comparison lisp/textmodes/conf-mode.el @ 66188:fe198c9ace5c

Don't use font-lock-defaults-alist. Various docstring and line-width fixups. (conf-mode): Use cond. Set font-lock-defaults. Don't set comment-use-syntax.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 18 Oct 2005 15:26:08 +0000
parents 5e6a52548deb
children 33e9ace34df4
comparison
equal deleted inserted replaced
66187:5955934355f2 66188:fe198c9ace5c
84 (define-key map "\C-c\C-q" 'conf-quote-normal) 84 (define-key map "\C-c\C-q" 'conf-quote-normal)
85 (define-key map "\C-c\"" 'conf-quote-normal) 85 (define-key map "\C-c\"" 'conf-quote-normal)
86 (define-key map "\C-c'" 'conf-quote-normal) 86 (define-key map "\C-c'" 'conf-quote-normal)
87 (define-key map "\C-c\C-a" 'conf-align-assignments) 87 (define-key map "\C-c\C-a" 'conf-align-assignments)
88 map) 88 map)
89 "Local keymap for conf-mode buffers.") 89 "Local keymap for `conf-mode' buffers.")
90 90
91 (defvar conf-mode-syntax-table 91 (defvar conf-mode-syntax-table
92 (let ((table (make-syntax-table))) 92 (let ((table (make-syntax-table)))
93 (modify-syntax-entry ?= "." table) 93 (modify-syntax-entry ?= "." table)
94 (modify-syntax-entry ?_ "_" table) 94 (modify-syntax-entry ?_ "_" table)
97 (modify-syntax-entry ?\' "\"" table) 97 (modify-syntax-entry ?\' "\"" table)
98 (modify-syntax-entry ?\; "<" table) 98 (modify-syntax-entry ?\; "<" table)
99 (modify-syntax-entry ?\n ">" table) 99 (modify-syntax-entry ?\n ">" table)
100 (modify-syntax-entry ?\r ">" table) 100 (modify-syntax-entry ?\r ">" table)
101 table) 101 table)
102 "Syntax table in use in Windows style conf-mode buffers.") 102 "Syntax table in use in Windows style `conf-mode' buffers.")
103 103
104 (defvar conf-unix-mode-syntax-table 104 (defvar conf-unix-mode-syntax-table
105 (let ((table (make-syntax-table conf-mode-syntax-table))) 105 (let ((table (make-syntax-table conf-mode-syntax-table)))
106 (modify-syntax-entry ?\# "<" table) 106 (modify-syntax-entry ?\# "<" table)
107 ;; override 107 ;; override
108 (modify-syntax-entry ?\; "." table) 108 (modify-syntax-entry ?\; "." table)
109 table) 109 table)
110 "Syntax table in use in Unix style conf-mode buffers.") 110 "Syntax table in use in Unix style `conf-mode' buffers.")
111 111
112 (defvar conf-javaprop-mode-syntax-table 112 (defvar conf-javaprop-mode-syntax-table
113 (let ((table (make-syntax-table conf-unix-mode-syntax-table))) 113 (let ((table (make-syntax-table conf-unix-mode-syntax-table)))
114 (modify-syntax-entry ?/ ". 124" table) 114 (modify-syntax-entry ?/ ". 124" table)
115 (modify-syntax-entry ?* ". 23b" table) 115 (modify-syntax-entry ?* ". 23b" table)
122 (modify-syntax-entry ?% ". 2" table) 122 (modify-syntax-entry ?% ". 2" table)
123 ;; override 123 ;; override
124 (modify-syntax-entry ?\' "." table) 124 (modify-syntax-entry ?\' "." table)
125 (modify-syntax-entry ?\; "." table) 125 (modify-syntax-entry ?\; "." table)
126 table) 126 table)
127 "Syntax table in use in PPD conf-mode buffers.") 127 "Syntax table in use in PPD `conf-mode' buffers.")
128 128
129 (defvar conf-xdefaults-mode-syntax-table 129 (defvar conf-xdefaults-mode-syntax-table
130 (let ((table (make-syntax-table conf-mode-syntax-table))) 130 (let ((table (make-syntax-table conf-mode-syntax-table)))
131 (modify-syntax-entry ?! "<" table) 131 (modify-syntax-entry ?! "<" table)
132 ;; override 132 ;; override
133 (modify-syntax-entry ?\; "." table) 133 (modify-syntax-entry ?\; "." table)
134 table) 134 table)
135 "Syntax table in use in Xdefaults style conf-mode buffers.") 135 "Syntax table in use in Xdefaults style `conf-mode' buffers.")
136 136
137 137
138 (defvar conf-font-lock-keywords 138 (defvar conf-font-lock-keywords
139 `(;; [section] (do this first because it may look like a parameter) 139 `(;; [section] (do this first because it may look like a parameter)
140 ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face) 140 ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
142 ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*=" 142 ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*="
143 (1 'font-lock-variable-name-face) 143 (1 'font-lock-variable-name-face)
144 (2 'font-lock-constant-face nil t)) 144 (2 'font-lock-constant-face nil t))
145 ;; section { ... } (do this last because some assign ...{...) 145 ;; section { ... } (do this last because some assign ...{...)
146 ("^[ \t]*\\([^=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend)) 146 ("^[ \t]*\\([^=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
147 "Keywords to hilight in Conf mode") 147 "Keywords to hilight in Conf mode.")
148 148
149 (defvar conf-javaprop-font-lock-keywords 149 (defvar conf-javaprop-font-lock-keywords
150 '(;; var=val 150 '(;; var=val
151 ("^[ \t]*\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(\\..+?\\)?\\)?\\)?\\)?\\)?\\)?\\([:= \t]\\|$\\)" 151 ("^[ \t]*\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(\\..+?\\)?\\)?\\)?\\)?\\)?\\)?\\([:= \t]\\|$\\)"
152 (1 'font-lock-variable-name-face) 152 (1 'font-lock-variable-name-face)
154 (3 'font-lock-variable-name-face nil t) 154 (3 'font-lock-variable-name-face nil t)
155 (4 'font-lock-constant-face nil t) 155 (4 'font-lock-constant-face nil t)
156 (5 'font-lock-variable-name-face nil t) 156 (5 'font-lock-variable-name-face nil t)
157 (6 'font-lock-constant-face nil t) 157 (6 'font-lock-constant-face nil t)
158 (7 'font-lock-variable-name-face nil t))) 158 (7 'font-lock-variable-name-face nil t)))
159 "Keywords to hilight in Conf Java Properties mode") 159 "Keywords to hilight in Conf Java Properties mode.")
160 160
161 (defvar conf-space-keywords-alist 161 (defvar conf-space-keywords-alist
162 '(("\\`/etc/gpm/" . "key\\|name\\|foreground\\|background\\|border\\|head") 162 '(("\\`/etc/gpm/" . "key\\|name\\|foreground\\|background\\|border\\|head")
163 ("\\`/etc/magic\\'" . "[^ \t]+[ \t]+\\(?:[bl]?e?\\(?:short\\|long\\)\\|byte\\|string\\)[^ \t]*") 163 ("\\`/etc/magic\\'" . "[^ \t]+[ \t]+\\(?:[bl]?e?\\(?:short\\|long\\)\\|byte\\|string\\)[^ \t]*")
164 ("/mod\\(?:ules\\|probe\\)\\.conf" . "alias\\|in\\(?:clude\\|stall\\)\\|options\\|remove") 164 ("/mod\\(?:ules\\|probe\\)\\.conf" . "alias\\|in\\(?:clude\\|stall\\)\\|options\\|remove")
186 (eval if conf-space-keywords 186 (eval if conf-space-keywords
187 (list (concat "^[ \t]*\\(" conf-space-keywords "\\)[ \t]+\\([^\000- ]+\\)") 187 (list (concat "^[ \t]*\\(" conf-space-keywords "\\)[ \t]+\\([^\000- ]+\\)")
188 '(1 'font-lock-keyword-face) 188 '(1 'font-lock-keyword-face)
189 '(2 'font-lock-variable-name-face)) 189 '(2 'font-lock-variable-name-face))
190 '("^[ \t]*\\([^\000- ]+\\)" 1 'font-lock-variable-name-face))) 190 '("^[ \t]*\\([^\000- ]+\\)" 1 'font-lock-variable-name-face)))
191 "Keywords to hilight in Conf Space mode") 191 "Keywords to hilight in Conf Space mode.")
192 192
193 (defvar conf-colon-font-lock-keywords 193 (defvar conf-colon-font-lock-keywords
194 `(;; [section] (do this first because it may look like a parameter) 194 `(;; [section] (do this first because it may look like a parameter)
195 ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face) 195 ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
196 ;; var: val 196 ;; var: val
197 ("^[ \t]*\\(.+?\\)[ \t]*:" 197 ("^[ \t]*\\(.+?\\)[ \t]*:"
198 (1 'font-lock-variable-name-face)) 198 (1 'font-lock-variable-name-face))
199 ;; section { ... } (do this last because some assign ...{...) 199 ;; section { ... } (do this last because some assign ...{...)
200 ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend)) 200 ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
201 "Keywords to hilight in Conf Colon mode") 201 "Keywords to hilight in Conf Colon mode.")
202 202
203 (defvar conf-assignment-sign ?= 203 (defvar conf-assignment-sign ?=
204 "What sign is used for assignments.") 204 "What sign is used for assignments.")
205 205
206 (defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)" 206 (defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)"
229 (delete-region (point) (match-end 1)) 229 (delete-region (point) (match-end 1))
230 (if conf-assignment-sign 230 (if conf-assignment-sign
231 (if (>= arg 0) 231 (if (>= arg 0)
232 (progn 232 (progn
233 (indent-to-column arg) 233 (indent-to-column arg)
234 (or (not conf-assignment-space) (memq (char-before (point)) '(?\s ?\t)) (insert ?\s)) 234 (or (not conf-assignment-space)
235 (insert conf-assignment-sign (if (and conf-assignment-space (not (eolp))) ?\s ""))) 235 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))
236 (insert conf-assignment-sign
237 (if (and conf-assignment-space (not (eolp))) ?\s "")))
236 (insert (if conf-assignment-space ?\s "") conf-assignment-sign) 238 (insert (if conf-assignment-space ?\s "") conf-assignment-sign)
237 (unless (eolp) 239 (unless (eolp)
238 (indent-to-column (- arg)) 240 (indent-to-column (- arg))
239 (or (not conf-assignment-space) (memq (char-before (point)) '(?\s ?\t)) (insert ?\s)))) 241 (or (not conf-assignment-space)
242 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
240 (unless (eolp) 243 (unless (eolp)
241 (if (>= (current-column) (abs arg)) 244 (if (>= (current-column) (abs arg))
242 (insert ?\s) 245 (insert ?\s)
243 (indent-to-column (abs arg)))))) 246 (indent-to-column (abs arg))))))
244 (forward-line)))) 247 (forward-line))))
253 and you can correct it with this command. (Some files even do 256 and you can correct it with this command. (Some files even do
254 both, i.e. quotes delimit strings, except when they are 257 both, i.e. quotes delimit strings, except when they are
255 unbalanced, but hey...)" 258 unbalanced, but hey...)"
256 (interactive "P") 259 (interactive "P")
257 (let ((table (copy-syntax-table (syntax-table)))) 260 (let ((table (copy-syntax-table (syntax-table))))
258 (if (or (not arg) (= (prefix-numeric-value arg) 1)) (modify-syntax-entry ?\' "." table)) 261 (if (or (not arg) (= (prefix-numeric-value arg) 1))
259 (if (or (not arg) (= (prefix-numeric-value arg) 2)) (modify-syntax-entry ?\" "." table)) 262 (modify-syntax-entry ?\' "." table))
263 (if (or (not arg) (= (prefix-numeric-value arg) 2))
264 (modify-syntax-entry ?\" "." table))
260 (set-syntax-table table) 265 (set-syntax-table table)
261 (and (boundp 'font-lock-mode) 266 (and (boundp 'font-lock-mode)
262 font-lock-mode 267 font-lock-mode
263 (font-lock-fontify-buffer)))) 268 (font-lock-fontify-buffer))))
264 269
324 (setq colon (1+ colon)))) 329 (setq colon (1+ colon))))
325 ((looking-at "/[/*]") (setq jp (1+ jp))) 330 ((looking-at "/[/*]") (setq jp (1+ jp)))
326 ((looking-at ".*{")) ; nop 331 ((looking-at ".*{")) ; nop
327 ((setq space (1+ space)))) 332 ((setq space (1+ space))))
328 (forward-line))) 333 (forward-line)))
329 (if (> jp (max unix win 3)) 334 (cond
330 (conf-javaprop-mode) 335 ((> jp (max unix win 3)) (conf-javaprop-mode))
331 (if (> colon (max equal space)) 336 ((> colon (max equal space)) (conf-colon-mode))
332 (conf-colon-mode) 337 ((> space (max equal colon)) (conf-space-mode))
333 (if (> space (max equal colon)) 338 ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt)))
334 (conf-space-mode) 339 (conf-windows-mode))
335 (if (or (> win unix) 340 (t (conf-unix-mode))))
336 (and (= win unix) (eq system-type 'windows-nt)))
337 (conf-windows-mode)
338 (conf-unix-mode))))))
339 (kill-all-local-variables) 341 (kill-all-local-variables)
340 (use-local-map conf-mode-map) 342 (use-local-map conf-mode-map)
341 343
342 (setq major-mode 'conf-mode 344 (setq major-mode 'conf-mode
343 mode-name name) 345 mode-name name)
346 (set (make-local-variable 'font-lock-defaults)
347 '(conf-font-lock-keywords nil t nil nil))
344 (set (make-local-variable 'comment-start) comment) 348 (set (make-local-variable 'comment-start) comment)
345 (set (make-local-variable 'comment-start-skip) 349 (set (make-local-variable 'comment-start-skip)
346 (concat (regexp-quote comment-start) "+\\s *")) 350 (concat (regexp-quote comment-start) "+\\s *"))
347 (set (make-local-variable 'comment-use-syntax) t) 351 ;; Let newcomment.el decide this for himself.
352 ;; (set (make-local-variable 'comment-use-syntax) t)
348 (set (make-local-variable 'parse-sexp-ignore-comments) t) 353 (set (make-local-variable 'parse-sexp-ignore-comments) t)
349 (set (make-local-variable 'outline-regexp) 354 (set (make-local-variable 'outline-regexp)
350 "[ \t]*\\(?:\\[\\|.+[ \t\n]*{\\)") 355 "[ \t]*\\(?:\\[\\|.+[ \t\n]*{\\)")
351 (set (make-local-variable 'outline-heading-end-regexp) 356 (set (make-local-variable 'outline-heading-end-regexp)
352 "[\n}]") 357 "[\n}]")
366 (defun conf-unix-mode () 371 (defun conf-unix-mode ()
367 "Conf Mode starter for Unix style Conf files. 372 "Conf Mode starter for Unix style Conf files.
368 Comments start with `#'. 373 Comments start with `#'.
369 For details see `conf-mode'. Example: 374 For details see `conf-mode'. Example:
370 375
371 # Conf mode font-locks this right on Unix and with C-c C-u 376 # Conf mode font-locks this right on Unix and with \\[conf-unix-mode]
372 377
373 \[Desktop Entry] 378 \[Desktop Entry]
374 Encoding=UTF-8 379 Encoding=UTF-8
375 Name=The GIMP 380 Name=The GIMP
376 Name[ca]=El GIMP 381 Name[ca]=El GIMP
382 (defun conf-windows-mode () 387 (defun conf-windows-mode ()
383 "Conf Mode starter for Windows style Conf files. 388 "Conf Mode starter for Windows style Conf files.
384 Comments start with `;'. 389 Comments start with `;'.
385 For details see `conf-mode'. Example: 390 For details see `conf-mode'. Example:
386 391
387 ; Conf mode font-locks this right on Windows and with C-c C-w 392 ; Conf mode font-locks this right on Windows and with \\[conf-windows-mode]
388 393
389 \[ExtShellFolderViews] 394 \[ExtShellFolderViews]
390 Default={5984FFE0-28D4-11CF-AE66-08002B2E1262} 395 Default={5984FFE0-28D4-11CF-AE66-08002B2E1262}
391 {5984FFE0-28D4-11CF-AE66-08002B2E1262}={5984FFE0-28D4-11CF-AE66-08002B2E1262} 396 {5984FFE0-28D4-11CF-AE66-08002B2E1262}={5984FFE0-28D4-11CF-AE66-08002B2E1262}
392 397
405 "Conf Mode starter for Java properties files. 410 "Conf Mode starter for Java properties files.
406 Comments start with `#' but are also recognized with `//' or 411 Comments start with `#' but are also recognized with `//' or
407 between `/*' and `*/'. 412 between `/*' and `*/'.
408 For details see `conf-mode'. Example: 413 For details see `conf-mode'. Example:
409 414
410 # Conf mode font-locks this right with C-c C-j (Java properties) 415 # Conf mode font-locks this right with \\[conf-javaprop-mode] (Java properties)
411 // another kind of comment 416 // another kind of comment
412 /* yet another */ 417 /* yet another */
413 418
414 name:value 419 name:value
415 name=value 420 name=value
439 the keywords. Programmatically you can pass such a regexp as 444 the keywords. Programmatically you can pass such a regexp as
440 KEYWORDS, or any non-nil non-string for no keywords. 445 KEYWORDS, or any non-nil non-string for no keywords.
441 446
442 For details see `conf-mode'. Example: 447 For details see `conf-mode'. Example:
443 448
444 # Conf mode font-locks this right with C-c C-s (space separated) 449 # Conf mode font-locks this right with \\[conf-space-mode] (space separated)
445 450
446 image/jpeg jpeg jpg jpe 451 image/jpeg jpeg jpg jpe
447 image/png png 452 image/png png
448 image/tiff tiff tif 453 image/tiff tiff tif
449 454
493 (defun conf-colon-mode (&optional comment syntax-table name) 498 (defun conf-colon-mode (&optional comment syntax-table name)
494 "Conf Mode starter for Colon files. 499 "Conf Mode starter for Colon files.
495 \"Assignments\" are with `:'. 500 \"Assignments\" are with `:'.
496 For details see `conf-mode'. Example: 501 For details see `conf-mode'. Example:
497 502
498 # Conf mode font-locks this right with C-c C-c (colon) 503 # Conf mode font-locks this right with \\[conf-colon-mode] (colon)
499 504
500 <Multi_key> <exclam> <exclam> : \"\\241\" exclamdown 505 <Multi_key> <exclam> <exclam> : \"\\241\" exclamdown
501 <Multi_key> <c> <slash> : \"\\242\" cent" 506 <Multi_key> <c> <slash> : \"\\242\" cent"
502 (interactive) 507 (interactive)
503 (if comment 508 (if comment
522 (defun conf-ppd-mode () 527 (defun conf-ppd-mode ()
523 "Conf Mode starter for Adobe/CUPS PPD files. 528 "Conf Mode starter for Adobe/CUPS PPD files.
524 Comments start with `*%' and \"assignments\" are with `:'. 529 Comments start with `*%' and \"assignments\" are with `:'.
525 For details see `conf-mode'. Example: 530 For details see `conf-mode'. Example:
526 531
527 *% Conf mode font-locks this right with C-c C-p (PPD) 532 *% Conf mode font-locks this right with \\[conf-ppd-mode] (PPD)
528 533
529 *DefaultTransfer: Null 534 *DefaultTransfer: Null
530 *Transfer Null.Inverse: \"{ 1 exch sub }\"" 535 *Transfer Null.Inverse: \"{ 1 exch sub }\""
531 (interactive) 536 (interactive)
532 (conf-colon-mode "*%" conf-ppd-mode-syntax-table "Conf[PPD]") 537 (conf-colon-mode "*%" conf-ppd-mode-syntax-table "Conf[PPD]")
537 (defun conf-xdefaults-mode () 542 (defun conf-xdefaults-mode ()
538 "Conf Mode starter for Xdefaults files. 543 "Conf Mode starter for Xdefaults files.
539 Comments start with `!' and \"assignments\" are with `:'. 544 Comments start with `!' and \"assignments\" are with `:'.
540 For details see `conf-mode'. Example: 545 For details see `conf-mode'. Example:
541 546
542 ! Conf mode font-locks this right with C-c C-x (.Xdefaults) 547 ! Conf mode font-locks this right with \\[conf-xdefaults-mode] (.Xdefaults)
543 548
544 *background: gray99 549 *background: gray99
545 *foreground: black" 550 *foreground: black"
546 (interactive) 551 (interactive)
547 (conf-colon-mode "!" conf-xdefaults-mode-syntax-table "Conf[Xdefaults]")) 552 (conf-colon-mode "!" conf-xdefaults-mode-syntax-table "Conf[Xdefaults]"))
548 553
549
550 ;; font lock support
551 (if (boundp 'font-lock-defaults-alist)
552 (add-to-list
553 'font-lock-defaults-alist
554 (cons 'conf-mode
555 (list 'conf-font-lock-keywords nil t nil nil))))
556
557
558 (provide 'conf-mode) 554 (provide 'conf-mode)
559 555
560 ;; arch-tag: 0a3805b2-0371-4d3a-8498-8897116b2356 556 ;; arch-tag: 0a3805b2-0371-4d3a-8498-8897116b2356
561 ;;; conf-mode.el ends here 557 ;;; conf-mode.el ends here