201 |
"Keywords to hilight in Conf Colon mode.") |
"Keywords to hilight in Conf Colon mode.") |
202 |
|
|
203 |
(defvar conf-assignment-sign ?= |
(defvar conf-assignment-sign ?= |
204 |
"What sign is used for assignments.") |
"Sign used for assignments (char or string).") |
205 |
|
|
206 |
(defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)" |
(defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)" |
207 |
"Regexp to recognize assignments. |
"Regexp to recognize assignments. |
208 |
It is anchored after the first sexp on a line. There must a |
It is anchored after the first sexp on a line. There must be a |
209 |
grouping for the assignment sign, including leading and trailing |
grouping for the assignment sign, including leading and trailing |
210 |
whitespace.") |
whitespace.") |
211 |
|
|
279 |
|
|
280 |
|
|
281 |
;;;###autoload |
;;;###autoload |
282 |
(defun conf-mode (&optional comment syntax-table name) |
(defun conf-mode () |
283 |
"Mode for Unix and Windows Conf files and Java properties. |
"Mode for Unix and Windows Conf files and Java properties. |
284 |
Most conf files know only three kinds of constructs: parameter |
Most conf files know only three kinds of constructs: parameter |
285 |
assignments optionally grouped into sections and comments. Yet |
assignments optionally grouped into sections and comments. Yet |
311 |
\\{conf-mode-map}" |
\\{conf-mode-map}" |
312 |
|
|
313 |
(interactive) |
(interactive) |
314 |
(if (not comment) |
;; `conf-mode' plays two roles: it's the parent of several sub-modes |
315 |
|
;; but it's also the function that chooses between those submodes. |
316 |
|
;; To tell the difference between those two cases where the function |
317 |
|
;; might be called, we check `delay-mode-hooks'. |
318 |
|
;; (adopted from tex-mode.el) |
319 |
|
(if (not delay-mode-hooks) |
320 |
|
;; try to guess sub-mode of conf-mode based on buffer content |
321 |
(let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0)) |
(let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0)) |
322 |
(save-excursion |
(save-excursion |
323 |
(goto-char (point-min)) |
(goto-char (point-min)) |
344 |
((or (> win unix) (and (= win unix) (eq system-type 'windows-nt))) |
((or (> win unix) (and (= win unix) (eq system-type 'windows-nt))) |
345 |
(conf-windows-mode)) |
(conf-windows-mode)) |
346 |
(t (conf-unix-mode)))) |
(t (conf-unix-mode)))) |
347 |
|
|
348 |
(kill-all-local-variables) |
(kill-all-local-variables) |
349 |
(use-local-map conf-mode-map) |
(use-local-map conf-mode-map) |
|
|
|
350 |
(setq major-mode 'conf-mode |
(setq major-mode 'conf-mode |
351 |
mode-name name) |
mode-name "Conf[?]") |
352 |
(set (make-local-variable 'font-lock-defaults) |
(set (make-local-variable 'font-lock-defaults) |
353 |
'(conf-font-lock-keywords nil t nil nil)) |
'(conf-font-lock-keywords nil t nil nil)) |
354 |
(set (make-local-variable 'comment-start) comment) |
;; Let newcomment.el decide this for itself. |
|
(set (make-local-variable 'comment-start-skip) |
|
|
(concat (regexp-quote comment-start) "+\\s *")) |
|
|
;; Let newcomment.el decide this for himself. |
|
355 |
;; (set (make-local-variable 'comment-use-syntax) t) |
;; (set (make-local-variable 'comment-use-syntax) t) |
356 |
(set (make-local-variable 'parse-sexp-ignore-comments) t) |
(set (make-local-variable 'parse-sexp-ignore-comments) t) |
357 |
(set (make-local-variable 'outline-regexp) |
(set (make-local-variable 'outline-regexp) |
360 |
"[\n}]") |
"[\n}]") |
361 |
(set (make-local-variable 'outline-level) |
(set (make-local-variable 'outline-level) |
362 |
'conf-outline-level) |
'conf-outline-level) |
363 |
(set-syntax-table syntax-table) |
(set-syntax-table conf-mode-syntax-table) |
364 |
(setq imenu-generic-expression |
(setq imenu-generic-expression |
365 |
'(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1) |
'(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1) |
366 |
;; [section] |
;; [section] |
367 |
(nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1) |
(nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1) |
368 |
;; section { ... } |
;; section { ... } |
369 |
(nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1))) |
(nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1))) |
|
|
|
370 |
(run-mode-hooks 'conf-mode-hook))) |
(run-mode-hooks 'conf-mode-hook))) |
371 |
|
|
372 |
|
(defun conf-mode-initialize (comment &optional font-lock) |
373 |
|
"Intitializations for sub-modes of conf-mode. |
374 |
|
COMMENT initializes `comment-start' and `comment-start-skip'. |
375 |
|
The optional arg FONT-LOCK is the value for FONT-LOCK-KEYWORDS." |
376 |
|
(set (make-local-variable 'comment-start) comment) |
377 |
|
(set (make-local-variable 'comment-start-skip) |
378 |
|
(concat (regexp-quote comment-start) "+\\s *")) |
379 |
|
(if font-lock |
380 |
|
(set (make-local-variable 'font-lock-defaults) |
381 |
|
`(,font-lock nil t nil nil)))) |
382 |
|
|
383 |
;;;###autoload |
;;;###autoload |
384 |
(defun conf-unix-mode () |
(define-derived-mode conf-unix-mode conf-mode "Conf[Unix]" |
385 |
"Conf Mode starter for Unix style Conf files. |
"Conf Mode starter for Unix style Conf files. |
386 |
Comments start with `#'. |
Comments start with `#'. |
387 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
393 |
Name=The GIMP |
Name=The GIMP |
394 |
Name[ca]=El GIMP |
Name[ca]=El GIMP |
395 |
Name[cs]=GIMP" |
Name[cs]=GIMP" |
396 |
(interactive) |
(conf-mode-initialize "#")) |
|
(conf-mode "#" conf-unix-mode-syntax-table "Conf[Unix]")) |
|
397 |
|
|
398 |
;;;###autoload |
;;;###autoload |
399 |
(defun conf-windows-mode () |
(define-derived-mode conf-windows-mode conf-mode "Conf[WinIni]" |
400 |
"Conf Mode starter for Windows style Conf files. |
"Conf Mode starter for Windows style Conf files. |
401 |
Comments start with `;'. |
Comments start with `;'. |
402 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
409 |
|
|
410 |
\[{5984FFE0-28D4-11CF-AE66-08002B2E1262}] |
\[{5984FFE0-28D4-11CF-AE66-08002B2E1262}] |
411 |
PersistMoniker=file://Folder.htt" |
PersistMoniker=file://Folder.htt" |
412 |
(interactive) |
(conf-mode-initialize ";")) |
|
(conf-mode ";" conf-mode-syntax-table "Conf[WinIni]")) |
|
413 |
|
|
414 |
;; Here are a few more or less widespread styles. There are others, so |
;; Here are a few more or less widespread styles. There are others, so |
415 |
;; obscure, they are not covered. E.g. RFC 2614 allows both Unix and Windows |
;; obscure, they are not covered. E.g. RFC 2614 allows both Unix and Windows |
417 |
;; if you need it. |
;; if you need it. |
418 |
|
|
419 |
;;;###autoload |
;;;###autoload |
420 |
(defun conf-javaprop-mode () |
(define-derived-mode conf-javaprop-mode conf-mode "Conf[JavaProp]" |
421 |
"Conf Mode starter for Java properties files. |
"Conf Mode starter for Java properties files. |
422 |
Comments start with `#' but are also recognized with `//' or |
Comments start with `#' but are also recognized with `//' or |
423 |
between `/*' and `*/'. |
between `/*' and `*/'. |
433 |
x.1 = |
x.1 = |
434 |
x.2.y.1.z.1 = |
x.2.y.1.z.1 = |
435 |
x.2.y.1.z.2.zz =" |
x.2.y.1.z.2.zz =" |
436 |
(interactive) |
(conf-mode-initialize "#" 'conf-javaprop-font-lock-keywords) |
|
(conf-mode "#" conf-javaprop-mode-syntax-table "Conf[JavaProp]") |
|
437 |
(set (make-local-variable 'conf-assignment-column) |
(set (make-local-variable 'conf-assignment-column) |
438 |
conf-javaprop-assignment-column) |
conf-javaprop-assignment-column) |
439 |
(set (make-local-variable 'conf-assignment-regexp) |
(set (make-local-variable 'conf-assignment-regexp) |
440 |
".+?\\([ \t]*[=: \t][ \t]*\\|$\\)") |
".+?\\([ \t]*[=: \t][ \t]*\\|$\\)") |
|
(set (make-local-variable 'conf-font-lock-keywords) |
|
|
conf-javaprop-font-lock-keywords) |
|
441 |
(setq comment-start-skip "\\(?:#+\\|/[/*]+\\)\\s *") |
(setq comment-start-skip "\\(?:#+\\|/[/*]+\\)\\s *") |
442 |
(setq imenu-generic-expression |
(setq imenu-generic-expression |
443 |
'(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1)))) |
'(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1)))) |
444 |
|
|
445 |
;;;###autoload |
;;;###autoload |
446 |
(defun conf-space-mode (&optional keywords) |
(define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]" |
447 |
"Conf Mode starter for space separated conf files. |
"Conf Mode starter for space separated conf files. |
448 |
\"Assignments\" are with ` '. Keywords before the parameters are |
\"Assignments\" are with ` '. Keywords before the parameters are |
449 |
recognized according to `conf-space-keywords'. Interactively |
recognized according to `conf-space-keywords'. Interactively |
450 |
with a prefix ARG of `0' no keywords will be recognized. With |
with a prefix ARG of `0' no keywords will be recognized. With |
451 |
any other prefix arg you will be prompted for a regexp to match |
any other prefix arg you will be prompted for a regexp to match |
452 |
the keywords. Programmatically you can pass such a regexp as |
the keywords. |
|
KEYWORDS, or any non-nil non-string for no keywords. |
|
453 |
|
|
454 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
455 |
|
|
464 |
# Standard multimedia devices |
# Standard multimedia devices |
465 |
add /dev/audio desktop |
add /dev/audio desktop |
466 |
add /dev/mixer desktop" |
add /dev/mixer desktop" |
467 |
(interactive |
(conf-mode-initialize "#" 'conf-space-font-lock-keywords) |
|
(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]") |
|
468 |
(set (make-local-variable 'conf-assignment-sign) |
(set (make-local-variable 'conf-assignment-sign) |
469 |
nil) |
nil) |
|
(set (make-local-variable 'conf-font-lock-keywords) |
|
|
conf-space-font-lock-keywords) |
|
470 |
;; This doesn't seem right, but the next two depend on conf-space-keywords |
;; This doesn't seem right, but the next two depend on conf-space-keywords |
471 |
;; being set, while after-change-major-mode-hook might set up imenu, needing |
;; being set, while after-change-major-mode-hook might set up imenu, needing |
472 |
;; the following result: |
;; the following result: |
473 |
(hack-local-variables-prop-line) |
(hack-local-variables-prop-line) |
474 |
(hack-local-variables) |
(hack-local-variables) |
475 |
(if keywords |
(cond (current-prefix-arg |
476 |
(set (make-local-variable 'conf-space-keywords) |
(set (make-local-variable 'conf-space-keywords) |
477 |
(if (stringp keywords) keywords)) |
(if (> (prefix-numeric-value current-prefix-arg) 0) |
478 |
(or conf-space-keywords |
(read-string "Regexp to match keywords: ")))) |
479 |
(not buffer-file-name) |
(conf-space-keywords) |
480 |
(set (make-local-variable 'conf-space-keywords) |
(buffer-file-name |
481 |
(assoc-default buffer-file-name conf-space-keywords-alist |
(set (make-local-variable 'conf-space-keywords) |
482 |
'string-match)))) |
(assoc-default buffer-file-name conf-space-keywords-alist |
483 |
|
'string-match)))) |
484 |
(set (make-local-variable 'conf-assignment-regexp) |
(set (make-local-variable 'conf-assignment-regexp) |
485 |
(if conf-space-keywords |
(if conf-space-keywords |
486 |
(concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") |
(concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") |
495 |
1)))) |
1)))) |
496 |
|
|
497 |
;;;###autoload |
;;;###autoload |
498 |
(defun conf-colon-mode (&optional comment syntax-table name) |
(define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]" |
499 |
"Conf Mode starter for Colon files. |
"Conf Mode starter for Colon files. |
500 |
\"Assignments\" are with `:'. |
\"Assignments\" are with `:'. |
501 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
504 |
|
|
505 |
<Multi_key> <exclam> <exclam> : \"\\241\" exclamdown |
<Multi_key> <exclam> <exclam> : \"\\241\" exclamdown |
506 |
<Multi_key> <c> <slash> : \"\\242\" cent" |
<Multi_key> <c> <slash> : \"\\242\" cent" |
507 |
(interactive) |
(conf-mode-initialize "#" 'conf-colon-font-lock-keywords) |
|
(if comment |
|
|
(conf-mode comment syntax-table name) |
|
|
(conf-unix-mode) |
|
|
(setq mode-name "Conf[Colon]")) |
|
508 |
(set (make-local-variable 'conf-assignment-space) |
(set (make-local-variable 'conf-assignment-space) |
509 |
conf-colon-assignment-space) |
conf-colon-assignment-space) |
510 |
(set (make-local-variable 'conf-assignment-column) |
(set (make-local-variable 'conf-assignment-column) |
513 |
?:) |
?:) |
514 |
(set (make-local-variable 'conf-assignment-regexp) |
(set (make-local-variable 'conf-assignment-regexp) |
515 |
".+?\\([ \t]*:[ \t]*\\)") |
".+?\\([ \t]*:[ \t]*\\)") |
|
(set (make-local-variable 'conf-font-lock-keywords) |
|
|
conf-colon-font-lock-keywords) |
|
516 |
(setq imenu-generic-expression |
(setq imenu-generic-expression |
517 |
`(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*:" 1) |
`(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*:" 1) |
518 |
,@(cdr imenu-generic-expression)))) |
,@(cdr imenu-generic-expression)))) |
519 |
|
|
520 |
;;;###autoload |
;;;###autoload |
521 |
(defun conf-ppd-mode () |
(define-derived-mode conf-ppd-mode conf-colon-mode "Conf[PPD]" |
522 |
"Conf Mode starter for Adobe/CUPS PPD files. |
"Conf Mode starter for Adobe/CUPS PPD files. |
523 |
Comments start with `*%' and \"assignments\" are with `:'. |
Comments start with `*%' and \"assignments\" are with `:'. |
524 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
527 |
|
|
528 |
*DefaultTransfer: Null |
*DefaultTransfer: Null |
529 |
*Transfer Null.Inverse: \"{ 1 exch sub }\"" |
*Transfer Null.Inverse: \"{ 1 exch sub }\"" |
530 |
(interactive) |
(conf-mode-initialize "*%") |
|
(conf-colon-mode "*%" conf-ppd-mode-syntax-table "Conf[PPD]") |
|
531 |
;; no sections, they match within PostScript code |
;; no sections, they match within PostScript code |
532 |
(setq imenu-generic-expression (list (car imenu-generic-expression)))) |
(setq imenu-generic-expression (list (car imenu-generic-expression)))) |
533 |
|
|
534 |
;;;###autoload |
;;;###autoload |
535 |
(defun conf-xdefaults-mode () |
(define-derived-mode conf-xdefaults-mode conf-colon-mode "Conf[Xdefaults]" |
536 |
"Conf Mode starter for Xdefaults files. |
"Conf Mode starter for Xdefaults files. |
537 |
Comments start with `!' and \"assignments\" are with `:'. |
Comments start with `!' and \"assignments\" are with `:'. |
538 |
For details see `conf-mode'. Example: |
For details see `conf-mode'. Example: |
541 |
|
|
542 |
*background: gray99 |
*background: gray99 |
543 |
*foreground: black" |
*foreground: black" |
544 |
(interactive) |
(conf-mode-initialize "!")) |
|
(conf-colon-mode "!" conf-xdefaults-mode-syntax-table "Conf[Xdefaults]")) |
|
545 |
|
|
546 |
(provide 'conf-mode) |
(provide 'conf-mode) |
547 |
|
|