Update copyright notices for 2013.
[bpt/emacs.git] / lisp / textmodes / conf-mode.el
index 9eae2f5..93ff179 100644 (file)
@@ -1,16 +1,16 @@
 ;;; conf-mode.el --- Simple major mode for editing conf/ini/properties files
 
-;; Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
 
 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
 ;; Keywords: conf ini windows java
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 ;;
@@ -69,9 +67,9 @@ not align (only setting space according to `conf-assignment-space')."
   :type 'boolean
   :group 'conf)
 
-
 (defvar conf-mode-map
-  (let ((map (make-sparse-keymap)))
+  (let ((map (make-sparse-keymap))
+       (menu-map (make-sparse-keymap)))
     (define-key map "\C-c\C-u" 'conf-unix-mode)
     (define-key map "\C-c\C-w" 'conf-windows-mode)
     (define-key map "\C-c\C-j" 'conf-javaprop-mode)
@@ -85,6 +83,49 @@ not align (only setting space according to `conf-assignment-space')."
     (define-key map "\C-c\"" 'conf-quote-normal)
     (define-key map "\C-c'" 'conf-quote-normal)
     (define-key map "\C-c\C-a" 'conf-align-assignments)
+    (define-key map [menu-bar sh-script] (cons "Conf" menu-map))
+    (define-key menu-map [conf-windows-mode]
+      '(menu-item "Windows mode"
+                 conf-windows-mode
+                 :help "Conf Mode starter for Windows style Conf files"
+                 :button (:radio . (eq major-mode 'conf-windows-mode))))
+    (define-key menu-map [conf-javaprop-mode]
+      '(menu-item "Java properties mode"
+                 conf-javaprop-mode
+                 :help "Conf Mode starter for Java properties files"
+                 :button (:radio . (eq major-mode 'conf-javaprop-mode))))
+    (define-key menu-map [conf-space-keywords]
+      '(menu-item "Space keywords mode..."
+                 conf-space-keywords
+                 :help "Enter Conf Space mode using regexp KEYWORDS to match the keywords"
+                 :button (:radio . (eq major-mode 'conf-space-keywords))))
+    (define-key menu-map [conf-ppd-mode]
+      '(menu-item "PPD mode"
+                 conf-ppd-mode
+                 :help "Conf Mode starter for Adobe/CUPS PPD files"
+                 :button (:radio . (eq major-mode 'conf-ppd-mode))))
+    (define-key menu-map [conf-colon-mode]
+      '(menu-item "Colon mode"
+                 conf-colon-mode
+                 :help "Conf Mode starter for Colon files"
+                 :button (:radio . (eq major-mode 'conf-colon-mode))))
+    (define-key menu-map [conf-unix-mode]
+      '(menu-item "Unix mode"
+                 conf-unix-mode
+                 :help "Conf Mode starter for Unix style Conf files"
+                 :button (:radio . (eq major-mode 'conf-unix-mode))))
+    (define-key menu-map [conf-xdefaults-mode]
+      '(menu-item "Xdefaults mode"
+                 conf-xdefaults-mode
+                 :help "Conf Mode starter for Xdefaults files"
+                 :button (:radio . (eq major-mode 'conf-xdefaults-mode))))
+    (define-key menu-map [c-s0] '("--"))
+    (define-key menu-map [conf-quote-normal]
+      '(menu-item "Set quote syntax normal" conf-quote-normal
+                 :help "Set the syntax of \' and \" to punctuation"))
+    (define-key menu-map [conf-align-assignments]
+      '(menu-item "Align assignments" conf-align-assignments
+                 :help "Align assignments"))
     map)
   "Local keymap for `conf-mode' buffers.")
 
@@ -114,7 +155,7 @@ not align (only setting space according to `conf-assignment-space')."
     (modify-syntax-entry ?/  ". 124" table)
     (modify-syntax-entry ?*  ". 23b" table)
     table)
-  "Syntax table in use in Java prperties buffers.")
+  "Syntax table in use in Java properties buffers.")
 
 (defvar conf-ppd-mode-syntax-table
   (let ((table (make-syntax-table conf-mode-syntax-table)))
@@ -136,7 +177,7 @@ not align (only setting space according to `conf-assignment-space')."
 
 
 (defvar conf-font-lock-keywords
-  `(;; [section] (do this first because it may look like a parameter)
+  '(;; [section] (do this first because it may look like a parameter)
     ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
     ;; var=val or var[index]=val
     ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*="
@@ -144,7 +185,7 @@ not align (only setting space according to `conf-assignment-space')."
      (2 'font-lock-constant-face nil t))
     ;; section { ... } (do this last because some assign ...{...)
     ("^[ \t]*\\([^=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
-  "Keywords to hilight in Conf mode.")
+  "Keywords to highlight in Conf mode.")
 
 (defvar conf-javaprop-font-lock-keywords
   '(;; var=val
@@ -156,7 +197,7 @@ not align (only setting space according to `conf-assignment-space')."
      (5 'font-lock-variable-name-face nil t)
      (6 'font-lock-constant-face nil t)
      (7 'font-lock-variable-name-face nil t)))
-  "Keywords to hilight in Conf Java Properties mode.")
+  "Keywords to highlight in Conf Java Properties mode.")
 
 (defvar conf-space-keywords-alist
   '(("\\`/etc/gpm/" . "key\\|name\\|foreground\\|background\\|border\\|head")
@@ -176,6 +217,7 @@ This allows constructs such as
 keyword var value
 This variable is best set in the file local variables, or through
 `conf-space-keywords-alist'.")
+(put 'conf-space-keywords 'safe-local-variable 'stringp)
 
 (defvar conf-space-font-lock-keywords
   `(;; [section] (do this first because it may look like a parameter)
@@ -198,7 +240,7 @@ This variable is best set in the file local variables, or through
      (1 'font-lock-variable-name-face))
     ;; section { ... } (do this last because some assign ...{...)
     ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
-  "Keywords to hilight in Conf Colon mode.")
+  "Keywords to highlight in Conf Colon mode.")
 
 (defvar conf-assignment-sign ?=
   "Sign used for assignments (char or string).")
@@ -214,37 +256,43 @@ whitespace.")
 ;; `align', I'd be glad to hear.
 (defun conf-align-assignments (&optional arg)
   (interactive "P")
+  "Align the assignments in the buffer or active region.
+In Transient Mark mode, if the mark is active, operate on the
+contents of the region.  Otherwise, operate on the whole buffer."
   (setq arg (if arg
                (prefix-numeric-value arg)
              conf-assignment-column))
   (save-excursion
-    (goto-char (point-min))
-    (while (not (eobp))
-      (let ((cs (comment-beginning)))  ; go before comment if within
-       (if cs (goto-char cs)))
-      (while (forward-comment 9))      ; max-int?
-      (when (and (not (eobp))
-                (looking-at conf-assignment-regexp))
-       (goto-char (match-beginning 1))
-       (delete-region (point) (match-end 1))
-       (if conf-assignment-sign
-           (if (>= arg 0)
-               (progn
-                 (indent-to-column arg)
+    (save-restriction
+      (when (use-region-p)
+       (narrow-to-region (region-beginning) (region-end)))
+      (goto-char (point-min))
+      (while (not (eobp))
+       (let ((cs (comment-beginning))) ; go before comment if within
+         (if cs (goto-char cs)))
+       (while (forward-comment 9))     ; max-int?
+       (when (and (not (eobp))
+                  (looking-at conf-assignment-regexp))
+         (goto-char (match-beginning 1))
+         (delete-region (point) (match-end 1))
+         (if conf-assignment-sign
+             (if (>= arg 0)
+                 (progn
+                   (indent-to-column arg)
+                   (or (not conf-assignment-space)
+                       (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))
+                   (insert conf-assignment-sign
+                           (if (and conf-assignment-space (not (eolp))) ?\s "")))
+               (insert (if conf-assignment-space ?\s "") conf-assignment-sign)
+               (unless (eolp)
+                 (indent-to-column (- arg))
                  (or (not conf-assignment-space)
-                      (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))
-                 (insert conf-assignment-sign
-                          (if (and conf-assignment-space (not (eolp))) ?\s "")))
-             (insert (if conf-assignment-space ?\s "") conf-assignment-sign)
-             (unless (eolp)
-               (indent-to-column (- arg))
-               (or (not conf-assignment-space)
-                    (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
-         (unless (eolp)
-           (if (>= (current-column) (abs arg))
-               (insert ?\s)
-             (indent-to-column (abs arg))))))
-      (forward-line))))
+                     (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
+           (unless (eolp)
+             (if (>= (current-column) (abs arg))
+                 (insert ?\s)
+               (indent-to-column (abs arg))))))
+       (forward-line)))))
 
 
 (defun conf-quote-normal (arg)
@@ -258,14 +306,13 @@ both, i.e. quotes delimit strings, except when they are
 unbalanced, but hey...)"
   (interactive "P")
   (let ((table (copy-syntax-table (syntax-table))))
-    (if (or (not arg) (= (prefix-numeric-value arg) 1))
-        (modify-syntax-entry ?\' "." table))
-    (if (or (not arg) (= (prefix-numeric-value arg) 2))
-        (modify-syntax-entry ?\" "." table))
+    (when (or (not arg) (= (prefix-numeric-value arg) 1))
+      (modify-syntax-entry ?\' "." table))
+    (when (or (not arg) (= (prefix-numeric-value arg) 2))
+      (modify-syntax-entry ?\" "." table))
     (set-syntax-table table)
-    (and (boundp 'font-lock-mode)
-        font-lock-mode
-        (font-lock-fontify-buffer))))
+    (when font-lock-mode
+      (font-lock-fontify-buffer))))
 
 
 (defun conf-outline-level ()
@@ -370,7 +417,7 @@ See also `conf-space-mode', `conf-colon-mode', `conf-javaprop-mode',
     (run-mode-hooks 'conf-mode-hook)))
 
 (defun conf-mode-initialize (comment &optional font-lock)
-  "Intitializations for sub-modes of conf-mode.
+  "Initializations for sub-modes of conf-mode.
 COMMENT initializes `comment-start' and `comment-start-skip'.
 The optional arg FONT-LOCK is the value for FONT-LOCK-KEYWORDS."
   (set (make-local-variable 'comment-start) comment)
@@ -573,5 +620,4 @@ For details see `conf-mode'.  Example:
 
 (provide 'conf-mode)
 
-;; arch-tag: 0a3805b2-0371-4d3a-8498-8897116b2356
 ;;; conf-mode.el ends here