emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/textmodes/conf-mode.el


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/conf-mode.el
Date: Sat, 29 Oct 2005 12:01:38 -0400

Index: emacs/lisp/textmodes/conf-mode.el
diff -c emacs/lisp/textmodes/conf-mode.el:1.12 
emacs/lisp/textmodes/conf-mode.el:1.13
*** emacs/lisp/textmodes/conf-mode.el:1.12      Tue Oct 18 15:26:08 2005
--- emacs/lisp/textmodes/conf-mode.el   Sat Oct 29 16:01:37 2005
***************
*** 201,211 ****
    "Keywords to hilight in Conf Colon mode.")
  
  (defvar conf-assignment-sign ?=
!   "What sign is used for assignments.")
  
  (defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)"
    "Regexp to recognize assignments.
! It is anchored after the first sexp on a line.  There must a
  grouping for the assignment sign, including leading and trailing
  whitespace.")
  
--- 201,211 ----
    "Keywords to hilight in Conf Colon mode.")
  
  (defvar conf-assignment-sign ?=
!   "Sign used for assignments (char or string).")
  
  (defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)"
    "Regexp to recognize assignments.
! It is anchored after the first sexp on a line.  There must be a
  grouping for the assignment sign, including leading and trailing
  whitespace.")
  
***************
*** 279,285 ****
  
  
  ;;;###autoload
! (defun conf-mode (&optional comment syntax-table name)
    "Mode for Unix and Windows Conf files and Java properties.
  Most conf files know only three kinds of constructs: parameter
  assignments optionally grouped into sections and comments.  Yet
--- 279,285 ----
  
  
  ;;;###autoload
! (defun conf-mode ()
    "Mode for Unix and Windows Conf files and Java properties.
  Most conf files know only three kinds of constructs: parameter
  assignments optionally grouped into sections and comments.  Yet
***************
*** 311,317 ****
  \\{conf-mode-map}"
  
    (interactive)
!   (if (not comment)
        (let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0))
        (save-excursion
          (goto-char (point-min))
--- 311,323 ----
  \\{conf-mode-map}"
  
    (interactive)
!   ;; `conf-mode' plays two roles: it's the parent of several sub-modes
!   ;; but it's also the function that chooses between those submodes.
!   ;; To tell the difference between those two cases where the function
!   ;; might be called, we check `delay-mode-hooks'.
!   ;; (adopted from tex-mode.el)
!   (if (not delay-mode-hooks)
!       ;; try to guess sub-mode of conf-mode based on buffer content
        (let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0))
        (save-excursion
          (goto-char (point-min))
***************
*** 338,354 ****
           ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt)))
            (conf-windows-mode))
           (t (conf-unix-mode))))
      (kill-all-local-variables)
      (use-local-map conf-mode-map)
- 
      (setq major-mode 'conf-mode
!         mode-name name)
      (set (make-local-variable 'font-lock-defaults)
           '(conf-font-lock-keywords nil t nil nil))
!     (set (make-local-variable 'comment-start) comment)
!     (set (make-local-variable 'comment-start-skip)
!        (concat (regexp-quote comment-start) "+\\s *"))
!     ;; Let newcomment.el decide this for himself.
      ;; (set (make-local-variable 'comment-use-syntax) t)
      (set (make-local-variable 'parse-sexp-ignore-comments) t)
      (set (make-local-variable 'outline-regexp)
--- 344,357 ----
           ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt)))
            (conf-windows-mode))
           (t (conf-unix-mode))))
+ 
      (kill-all-local-variables)
      (use-local-map conf-mode-map)
      (setq major-mode 'conf-mode
!         mode-name "Conf[?]")
      (set (make-local-variable 'font-lock-defaults)
           '(conf-font-lock-keywords nil t nil nil))
!     ;; Let newcomment.el decide this for itself.
      ;; (set (make-local-variable 'comment-use-syntax) t)
      (set (make-local-variable 'parse-sexp-ignore-comments) t)
      (set (make-local-variable 'outline-regexp)
***************
*** 357,374 ****
         "[\n}]")
      (set (make-local-variable 'outline-level)
         'conf-outline-level)
!     (set-syntax-table syntax-table)
      (setq imenu-generic-expression
          '(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1)
            ;; [section]
            (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1)
            ;; section { ... }
            (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1)))
- 
      (run-mode-hooks 'conf-mode-hook)))
  
  ;;;###autoload
! (defun conf-unix-mode ()
    "Conf Mode starter for Unix style Conf files.
  Comments start with `#'.
  For details see `conf-mode'.  Example:
--- 360,387 ----
         "[\n}]")
      (set (make-local-variable 'outline-level)
         'conf-outline-level)
!     (set-syntax-table conf-mode-syntax-table)
      (setq imenu-generic-expression
          '(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1)
            ;; [section]
            (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1)
            ;; section { ... }
            (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1)))
      (run-mode-hooks 'conf-mode-hook)))
  
+ (defun conf-mode-initialize (comment &optional font-lock)
+   "Intitializations 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)
+   (set (make-local-variable 'comment-start-skip)
+        (concat (regexp-quote comment-start) "+\\s *"))
+   (if font-lock
+       (set (make-local-variable 'font-lock-defaults)
+            `(,font-lock nil t nil nil))))
+ 
  ;;;###autoload
! (define-derived-mode conf-unix-mode conf-mode "Conf[Unix]"
    "Conf Mode starter for Unix style Conf files.
  Comments start with `#'.
  For details see `conf-mode'.  Example:
***************
*** 380,390 ****
         Name=The GIMP
         Name[ca]=El GIMP
         Name[cs]=GIMP"
!   (interactive)
!   (conf-mode "#" conf-unix-mode-syntax-table "Conf[Unix]"))
  
  ;;;###autoload
! (defun conf-windows-mode ()
    "Conf Mode starter for Windows style Conf files.
  Comments start with `;'.
  For details see `conf-mode'.  Example:
--- 393,402 ----
         Name=The GIMP
         Name[ca]=El GIMP
         Name[cs]=GIMP"
!   (conf-mode-initialize "#"))
  
  ;;;###autoload
! (define-derived-mode conf-windows-mode conf-mode "Conf[WinIni]"
    "Conf Mode starter for Windows style Conf files.
  Comments start with `;'.
  For details see `conf-mode'.  Example:
***************
*** 397,404 ****
  
  \[{5984FFE0-28D4-11CF-AE66-08002B2E1262}]
  PersistMoniker=file://Folder.htt"
!   (interactive)
!   (conf-mode ";" conf-mode-syntax-table "Conf[WinIni]"))
  
  ;; Here are a few more or less widespread styles.  There are others, so
  ;; obscure, they are not covered.  E.g. RFC 2614 allows both Unix and Windows
--- 409,415 ----
  
  \[{5984FFE0-28D4-11CF-AE66-08002B2E1262}]
  PersistMoniker=file://Folder.htt"
!   (conf-mode-initialize ";"))
  
  ;; Here are a few more or less widespread styles.  There are others, so
  ;; obscure, they are not covered.  E.g. RFC 2614 allows both Unix and Windows
***************
*** 406,412 ****
  ;; if you need it.
  
  ;;;###autoload
! (defun conf-javaprop-mode ()
    "Conf Mode starter for Java properties files.
  Comments start with `#' but are also recognized with `//' or
  between `/*' and `*/'.
--- 417,423 ----
  ;; if you need it.
  
  ;;;###autoload
! (define-derived-mode conf-javaprop-mode conf-mode "Conf[JavaProp]"
    "Conf Mode starter for Java properties files.
  Comments start with `#' but are also recognized with `//' or
  between `/*' and `*/'.
***************
*** 422,448 ****
  x.1 =
  x.2.y.1.z.1 =
  x.2.y.1.z.2.zz ="
!   (interactive)
!   (conf-mode "#" conf-javaprop-mode-syntax-table "Conf[JavaProp]")
    (set (make-local-variable 'conf-assignment-column)
         conf-javaprop-assignment-column)
    (set (make-local-variable 'conf-assignment-regexp)
         ".+?\\([ \t]*[=: \t][ \t]*\\|$\\)")
-   (set (make-local-variable 'conf-font-lock-keywords)
-        conf-javaprop-font-lock-keywords)
    (setq comment-start-skip "\\(?:#+\\|/[/*]+\\)\\s *")
    (setq imenu-generic-expression
        '(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1))))
  
  ;;;###autoload
! (defun conf-space-mode (&optional keywords)
    "Conf Mode starter for space separated conf files.
  \"Assignments\" are with ` '.  Keywords before the parameters are
  recognized according to `conf-space-keywords'.  Interactively
  with a prefix ARG of `0' no keywords will be recognized.  With
  any other prefix arg you will be prompted for a regexp to match
! the keywords.  Programmatically you can pass such a regexp as
! KEYWORDS, or any non-nil non-string for no keywords.
  
  For details see `conf-mode'.  Example:
  
--- 433,455 ----
  x.1 =
  x.2.y.1.z.1 =
  x.2.y.1.z.2.zz ="
!   (conf-mode-initialize "#" 'conf-javaprop-font-lock-keywords)
    (set (make-local-variable 'conf-assignment-column)
         conf-javaprop-assignment-column)
    (set (make-local-variable 'conf-assignment-regexp)
         ".+?\\([ \t]*[=: \t][ \t]*\\|$\\)")
    (setq comment-start-skip "\\(?:#+\\|/[/*]+\\)\\s *")
    (setq imenu-generic-expression
        '(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1))))
  
  ;;;###autoload
! (define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]"
    "Conf Mode starter for space separated conf files.
  \"Assignments\" are with ` '.  Keywords before the parameters are
  recognized according to `conf-space-keywords'.  Interactively
  with a prefix ARG of `0' no keywords will be recognized.  With
  any other prefix arg you will be prompted for a regexp to match
! the keywords.
  
  For details see `conf-mode'.  Example:
  
***************
*** 457,486 ****
  # Standard multimedia devices
  add /dev/audio                desktop
  add /dev/mixer                desktop"
!   (interactive
!    (list (if current-prefix-arg
!            (if (> (prefix-numeric-value current-prefix-arg) 0)
!                (read-string "Regexp to match keywords: ")
!              t))))
!   (conf-unix-mode)
!   (setq mode-name "Conf[Space]")
    (set (make-local-variable 'conf-assignment-sign)
         nil)
-   (set (make-local-variable 'conf-font-lock-keywords)
-        conf-space-font-lock-keywords)
    ;; This doesn't seem right, but the next two depend on conf-space-keywords
    ;; being set, while after-change-major-mode-hook might set up imenu, needing
    ;; the following result:
    (hack-local-variables-prop-line)
    (hack-local-variables)
!   (if keywords
!       (set (make-local-variable 'conf-space-keywords)
!          (if (stringp keywords) keywords))
!     (or conf-space-keywords
!       (not buffer-file-name)
!       (set (make-local-variable 'conf-space-keywords)
!            (assoc-default buffer-file-name conf-space-keywords-alist
!                           'string-match))))
    (set (make-local-variable 'conf-assignment-regexp)
         (if conf-space-keywords
           (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)")
--- 464,486 ----
  # Standard multimedia devices
  add /dev/audio                desktop
  add /dev/mixer                desktop"
!   (conf-mode-initialize "#" 'conf-space-font-lock-keywords)
    (set (make-local-variable 'conf-assignment-sign)
         nil)
    ;; This doesn't seem right, but the next two depend on conf-space-keywords
    ;; being set, while after-change-major-mode-hook might set up imenu, needing
    ;; the following result:
    (hack-local-variables-prop-line)
    (hack-local-variables)
!   (cond (current-prefix-arg
!          (set (make-local-variable 'conf-space-keywords)
!               (if (> (prefix-numeric-value current-prefix-arg) 0)
!                   (read-string "Regexp to match keywords: "))))
!         (conf-space-keywords)
!         (buffer-file-name
!          (set (make-local-variable 'conf-space-keywords)
!               (assoc-default buffer-file-name conf-space-keywords-alist
!                              'string-match))))
    (set (make-local-variable 'conf-assignment-regexp)
         (if conf-space-keywords
           (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)")
***************
*** 495,501 ****
           1))))
  
  ;;;###autoload
! (defun conf-colon-mode (&optional comment syntax-table name)
    "Conf Mode starter for Colon files.
  \"Assignments\" are with `:'.
  For details see `conf-mode'.  Example:
--- 495,501 ----
           1))))
  
  ;;;###autoload
! (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]"
    "Conf Mode starter for Colon files.
  \"Assignments\" are with `:'.
  For details see `conf-mode'.  Example:
***************
*** 504,514 ****
  
  <Multi_key> <exclam> <exclam>         : \"\\241\"     exclamdown
  <Multi_key> <c> <slash>                       : \"\\242\"     cent"
!   (interactive)
!   (if comment
!       (conf-mode comment syntax-table name)
!     (conf-unix-mode)
!     (setq mode-name "Conf[Colon]"))
    (set (make-local-variable 'conf-assignment-space)
         conf-colon-assignment-space)
    (set (make-local-variable 'conf-assignment-column)
--- 504,510 ----
  
  <Multi_key> <exclam> <exclam>         : \"\\241\"     exclamdown
  <Multi_key> <c> <slash>                       : \"\\242\"     cent"
!   (conf-mode-initialize "#" 'conf-colon-font-lock-keywords)
    (set (make-local-variable 'conf-assignment-space)
         conf-colon-assignment-space)
    (set (make-local-variable 'conf-assignment-column)
***************
*** 517,530 ****
         ?:)
    (set (make-local-variable 'conf-assignment-regexp)
         ".+?\\([ \t]*:[ \t]*\\)")
-   (set (make-local-variable 'conf-font-lock-keywords)
-        conf-colon-font-lock-keywords)
    (setq imenu-generic-expression
        `(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*:" 1)
          ,@(cdr imenu-generic-expression))))
  
  ;;;###autoload
! (defun conf-ppd-mode ()
    "Conf Mode starter for Adobe/CUPS PPD files.
  Comments start with `*%' and \"assignments\" are with `:'.
  For details see `conf-mode'.  Example:
--- 513,524 ----
         ?:)
    (set (make-local-variable 'conf-assignment-regexp)
         ".+?\\([ \t]*:[ \t]*\\)")
    (setq imenu-generic-expression
        `(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*:" 1)
          ,@(cdr imenu-generic-expression))))
  
  ;;;###autoload
! (define-derived-mode conf-ppd-mode conf-colon-mode "Conf[PPD]"
    "Conf Mode starter for Adobe/CUPS PPD files.
  Comments start with `*%' and \"assignments\" are with `:'.
  For details see `conf-mode'.  Example:
***************
*** 533,545 ****
  
  *DefaultTransfer: Null
  *Transfer Null.Inverse: \"{ 1 exch sub }\""
!   (interactive)
!   (conf-colon-mode "*%" conf-ppd-mode-syntax-table "Conf[PPD]")
    ;; no sections, they match within PostScript code
    (setq imenu-generic-expression (list (car imenu-generic-expression))))
  
  ;;;###autoload
! (defun conf-xdefaults-mode ()
    "Conf Mode starter for Xdefaults files.
  Comments start with `!' and \"assignments\" are with `:'.
  For details see `conf-mode'.  Example:
--- 527,538 ----
  
  *DefaultTransfer: Null
  *Transfer Null.Inverse: \"{ 1 exch sub }\""
!   (conf-mode-initialize "*%")
    ;; no sections, they match within PostScript code
    (setq imenu-generic-expression (list (car imenu-generic-expression))))
  
  ;;;###autoload
! (define-derived-mode conf-xdefaults-mode conf-colon-mode "Conf[Xdefaults]"
    "Conf Mode starter for Xdefaults files.
  Comments start with `!' and \"assignments\" are with `:'.
  For details see `conf-mode'.  Example:
***************
*** 548,555 ****
  
  *background:                  gray99
  *foreground:                  black"
!   (interactive)
!   (conf-colon-mode "!" conf-xdefaults-mode-syntax-table "Conf[Xdefaults]"))
  
  (provide 'conf-mode)
  
--- 541,547 ----
  
  *background:                  gray99
  *foreground:                  black"
!   (conf-mode-initialize "!"))
  
  (provide 'conf-mode)
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]