conf-mode.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. ;;; conf-mode.el --- Simple major mode for editing conf/ini/properties files
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
  4. ;; Keywords: conf ini windows java
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; This mode is designed to edit many similar varieties of Conf/Ini files and
  19. ;; Java properties. It started out from Aurélien Tisné's ini-mode.
  20. ;; `conf-space-keywords' were inspired by Robert Fitzgerald's any-ini-mode.
  21. ;;; Code:
  22. (require 'newcomment)
  23. (defvar outline-heading-end-regexp)
  24. ;; Variables:
  25. (defgroup conf nil
  26. "Configuration files."
  27. :group 'data
  28. :version "22.1")
  29. (defcustom conf-assignment-column 24
  30. "Align assignments to this column by default with \\[conf-align-assignments].
  31. If this number is negative, the `=' comes before the whitespace. Use 0 to
  32. not align (only setting space according to `conf-assignment-space')."
  33. :type 'integer
  34. :group 'conf)
  35. (defcustom conf-javaprop-assignment-column 32
  36. "Value for `conf-assignment-column' in Java properties buffers."
  37. :type 'integer
  38. :group 'conf)
  39. (defcustom conf-colon-assignment-column (- (abs conf-assignment-column))
  40. "Value for `conf-assignment-column' in Java properties buffers."
  41. :type 'integer
  42. :group 'conf)
  43. (defcustom conf-assignment-space t
  44. "Put at least one space around assignments when aligning."
  45. :type 'boolean
  46. :group 'conf)
  47. (defcustom conf-colon-assignment-space nil
  48. "Value for `conf-assignment-space' in colon style Conf mode buffers."
  49. :type 'boolean
  50. :group 'conf)
  51. (defvar conf-mode-map
  52. (let ((map (make-sparse-keymap))
  53. (menu-map (make-sparse-keymap)))
  54. (define-key map "\C-c\C-u" 'conf-unix-mode)
  55. (define-key map "\C-c\C-w" 'conf-windows-mode)
  56. (define-key map "\C-c\C-j" 'conf-javaprop-mode)
  57. (define-key map "\C-c\C-s" 'conf-space-keywords)
  58. (define-key map "\C-c " 'conf-space-keywords)
  59. (define-key map "\C-c\C-c" 'conf-colon-mode)
  60. (define-key map "\C-c:" 'conf-colon-mode)
  61. (define-key map "\C-c\C-x" 'conf-xdefaults-mode)
  62. (define-key map "\C-c\C-p" 'conf-ppd-mode)
  63. (define-key map "\C-c\C-q" 'conf-quote-normal)
  64. (define-key map "\C-c\"" 'conf-quote-normal)
  65. (define-key map "\C-c'" 'conf-quote-normal)
  66. (define-key map "\C-c\C-a" 'conf-align-assignments)
  67. (define-key map [menu-bar sh-script] (cons "Conf" menu-map))
  68. (define-key menu-map [conf-windows-mode]
  69. '(menu-item "Windows mode"
  70. conf-windows-mode
  71. :help "Conf Mode starter for Windows style Conf files"
  72. :button (:radio . (eq major-mode 'conf-windows-mode))))
  73. (define-key menu-map [conf-javaprop-mode]
  74. '(menu-item "Java properties mode"
  75. conf-javaprop-mode
  76. :help "Conf Mode starter for Java properties files"
  77. :button (:radio . (eq major-mode 'conf-javaprop-mode))))
  78. (define-key menu-map [conf-space-keywords]
  79. '(menu-item "Space keywords mode..."
  80. conf-space-keywords
  81. :help "Enter Conf Space mode using regexp KEYWORDS to match the keywords"
  82. :button (:radio . (eq major-mode 'conf-space-keywords))))
  83. (define-key menu-map [conf-ppd-mode]
  84. '(menu-item "PPD mode"
  85. conf-ppd-mode
  86. :help "Conf Mode starter for Adobe/CUPS PPD files"
  87. :button (:radio . (eq major-mode 'conf-ppd-mode))))
  88. (define-key menu-map [conf-colon-mode]
  89. '(menu-item "Colon mode"
  90. conf-colon-mode
  91. :help "Conf Mode starter for Colon files"
  92. :button (:radio . (eq major-mode 'conf-colon-mode))))
  93. (define-key menu-map [conf-unix-mode]
  94. '(menu-item "Unix mode"
  95. conf-unix-mode
  96. :help "Conf Mode starter for Unix style Conf files"
  97. :button (:radio . (eq major-mode 'conf-unix-mode))))
  98. (define-key menu-map [conf-xdefaults-mode]
  99. '(menu-item "Xdefaults mode"
  100. conf-xdefaults-mode
  101. :help "Conf Mode starter for Xdefaults files"
  102. :button (:radio . (eq major-mode 'conf-xdefaults-mode))))
  103. (define-key menu-map [c-s0] '("--"))
  104. (define-key menu-map [conf-quote-normal]
  105. '(menu-item "Set quote syntax normal" conf-quote-normal
  106. :help "Set the syntax of \' and \" to punctuation"))
  107. (define-key menu-map [conf-align-assignments]
  108. '(menu-item "Align assignments" conf-align-assignments
  109. :help "Align assignments"))
  110. map)
  111. "Local keymap for `conf-mode' buffers.")
  112. (defvar conf-mode-syntax-table
  113. (let ((table (make-syntax-table)))
  114. (modify-syntax-entry ?= "." table)
  115. (modify-syntax-entry ?_ "_" table)
  116. (modify-syntax-entry ?- "_" table)
  117. (modify-syntax-entry ?. "_" table)
  118. (modify-syntax-entry ?\' "\"" table)
  119. (modify-syntax-entry ?\; "<" table)
  120. (modify-syntax-entry ?\n ">" table)
  121. (modify-syntax-entry ?\r ">" table)
  122. table)
  123. "Syntax table in use in Windows style `conf-mode' buffers.")
  124. (defvar conf-unix-mode-syntax-table
  125. (let ((table (make-syntax-table conf-mode-syntax-table)))
  126. (modify-syntax-entry ?\# "<" table)
  127. ;; override
  128. (modify-syntax-entry ?\; "." table)
  129. table)
  130. "Syntax table in use in Unix style `conf-mode' buffers.")
  131. (defvar conf-javaprop-mode-syntax-table
  132. (let ((table (make-syntax-table conf-unix-mode-syntax-table)))
  133. (modify-syntax-entry ?/ ". 124" table)
  134. (modify-syntax-entry ?* ". 23b" table)
  135. table)
  136. "Syntax table in use in Java properties buffers.")
  137. (defvar conf-ppd-mode-syntax-table
  138. (let ((table (make-syntax-table conf-mode-syntax-table)))
  139. (modify-syntax-entry ?* ". 1" table)
  140. (modify-syntax-entry ?% ". 2" table)
  141. ;; override
  142. (modify-syntax-entry ?\' "." table)
  143. (modify-syntax-entry ?\; "." table)
  144. table)
  145. "Syntax table in use in PPD `conf-mode' buffers.")
  146. (defvar conf-xdefaults-mode-syntax-table
  147. (let ((table (make-syntax-table conf-mode-syntax-table)))
  148. (modify-syntax-entry ?! "<" table)
  149. ;; override
  150. (modify-syntax-entry ?\; "." table)
  151. table)
  152. "Syntax table in use in Xdefaults style `conf-mode' buffers.")
  153. (defvar conf-font-lock-keywords
  154. '(;; [section] (do this first because it may look like a parameter)
  155. ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
  156. ;; var=val or var[index]=val
  157. ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*="
  158. (1 'font-lock-variable-name-face)
  159. (2 'font-lock-constant-face nil t))
  160. ;; section { ... } (do this last because some assign ...{...)
  161. ("^[ \t]*\\([^=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
  162. "Keywords to highlight in Conf mode.")
  163. (defvar conf-javaprop-font-lock-keywords
  164. '(;; var=val
  165. ("^[ \t]*\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(?:\\.\\(.+?\\)\\(?:\\.\\([0-9]+\\)\\(\\..+?\\)?\\)?\\)?\\)?\\)?\\)?\\([:= \t]\\|$\\)"
  166. (1 'font-lock-variable-name-face)
  167. (2 'font-lock-constant-face nil t)
  168. (3 'font-lock-variable-name-face nil t)
  169. (4 'font-lock-constant-face nil t)
  170. (5 'font-lock-variable-name-face nil t)
  171. (6 'font-lock-constant-face nil t)
  172. (7 'font-lock-variable-name-face nil t)))
  173. "Keywords to highlight in Conf Java Properties mode.")
  174. (defvar conf-space-keywords-alist
  175. '(("\\`/etc/gpm/" . "key\\|name\\|foreground\\|background\\|border\\|head")
  176. ("\\`/etc/magic\\'" . "[^ \t]+[ \t]+\\(?:[bl]?e?\\(?:short\\|long\\)\\|byte\\|string\\)[^ \t]*")
  177. ("/mod\\(?:ules\\|probe\\)\\.conf" . "alias\\|in\\(?:clude\\|stall\\)\\|options\\|remove")
  178. ("/manpath\\.config" . "MAN\\(?:DATORY_MANPATH\\|PATH_MAP\\|DB_MAP\\)")
  179. ("/sensors\\.conf" . "chip\\|bus\\|label\\|compute\\|set\\|ignore")
  180. ("/sane\\(\\.d\\)?/" . "option\\|device\\|port\\|usb\\|sc\\(?:si\\|anner\\)")
  181. ("/resmgr\\.conf" . "class\\|add\\|allow\\|deny")
  182. ("/dictionary\\.lst\\'" . "DICT\\|HYPH\\|THES")
  183. ("/tuxracer/options" . "set"))
  184. "File-name-based settings for the variable `conf-space-keywords'.")
  185. (defvar conf-space-keywords nil
  186. "Regexps for functions that may come before a space assignment.
  187. This allows constructs such as
  188. keyword var value
  189. This variable is best set in the file local variables, or through
  190. `conf-space-keywords-alist'.")
  191. (put 'conf-space-keywords 'safe-local-variable 'stringp)
  192. (defvar conf-space-font-lock-keywords
  193. `(;; [section] (do this first because it may look like a parameter)
  194. ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
  195. ;; section { ... } (do this first because it looks like a parameter)
  196. ("^[ \t]*\\(.+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face)
  197. ;; var val
  198. (eval if conf-space-keywords
  199. (list (concat "^[ \t]*\\(" conf-space-keywords "\\)[ \t]+\\([^\000- ]+\\)")
  200. '(1 'font-lock-keyword-face)
  201. '(2 'font-lock-variable-name-face))
  202. '("^[ \t]*\\([^\000- ]+\\)" 1 'font-lock-variable-name-face)))
  203. "Keywords to highlight in Conf Space mode.")
  204. (defvar conf-colon-font-lock-keywords
  205. `(;; [section] (do this first because it may look like a parameter)
  206. ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
  207. ;; var: val
  208. ("^[ \t]*\\(.+?\\)[ \t]*:"
  209. (1 'font-lock-variable-name-face))
  210. ;; section { ... } (do this last because some assign ...{...)
  211. ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
  212. "Keywords to highlight in Conf Colon mode.")
  213. (defvar conf-assignment-sign ?=
  214. "Sign used for assignments (char or string).")
  215. (defvar conf-assignment-regexp ".+?\\([ \t]*=[ \t]*\\)"
  216. "Regexp to recognize assignments.
  217. It is anchored after the first sexp on a line. There must be a
  218. grouping for the assignment sign, including leading and trailing
  219. whitespace.")
  220. ;; If anybody can figure out how to get the same effect by configuring
  221. ;; `align', I'd be glad to hear.
  222. (defun conf-align-assignments (&optional arg)
  223. (interactive "P")
  224. "Align the assignments in the buffer or active region.
  225. In Transient Mark mode, if the mark is active, operate on the
  226. contents of the region. Otherwise, operate on the whole buffer."
  227. (setq arg (if arg
  228. (prefix-numeric-value arg)
  229. conf-assignment-column))
  230. (save-excursion
  231. (save-restriction
  232. (when (use-region-p)
  233. (narrow-to-region (region-beginning) (region-end)))
  234. (goto-char (point-min))
  235. (while (not (eobp))
  236. (let ((cs (comment-beginning))) ; go before comment if within
  237. (if cs (goto-char cs)))
  238. (while (forward-comment 9)) ; max-int?
  239. (when (and (not (eobp))
  240. (looking-at conf-assignment-regexp))
  241. (goto-char (match-beginning 1))
  242. (delete-region (point) (match-end 1))
  243. (if conf-assignment-sign
  244. (if (>= arg 0)
  245. (progn
  246. (indent-to-column arg)
  247. (or (not conf-assignment-space)
  248. (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))
  249. (insert conf-assignment-sign
  250. (if (and conf-assignment-space (not (eolp))) ?\s "")))
  251. (insert (if conf-assignment-space ?\s "") conf-assignment-sign)
  252. (unless (eolp)
  253. (indent-to-column (- arg))
  254. (or (not conf-assignment-space)
  255. (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
  256. (unless (eolp)
  257. (if (>= (current-column) (abs arg))
  258. (insert ?\s)
  259. (indent-to-column (abs arg))))))
  260. (forward-line)))))
  261. (defun conf-quote-normal (arg)
  262. "Set the syntax of ' and \" to punctuation.
  263. With prefix arg, only do it for ' if 1, or only for \" if 2.
  264. This only affects the current buffer. Some conf files use quotes
  265. to delimit strings, while others allow quotes as simple parts of
  266. the assigned value. In those files font locking will be wrong,
  267. and you can correct it with this command. (Some files even do
  268. both, i.e. quotes delimit strings, except when they are
  269. unbalanced, but hey...)"
  270. (interactive "P")
  271. (let ((table (copy-syntax-table (syntax-table))))
  272. (when (or (not arg) (= (prefix-numeric-value arg) 1))
  273. (modify-syntax-entry ?\' "." table))
  274. (when (or (not arg) (= (prefix-numeric-value arg) 2))
  275. (modify-syntax-entry ?\" "." table))
  276. (set-syntax-table table)
  277. (when font-lock-mode
  278. (font-lock-fontify-buffer))))
  279. (defun conf-outline-level ()
  280. (let ((depth 0)
  281. (pt (match-end 0)))
  282. (condition-case nil
  283. (while (setq pt (scan-lists pt -1 1)
  284. depth (1+ depth)))
  285. (scan-error depth))))
  286. ;;;###autoload
  287. (defun conf-mode ()
  288. "Mode for Unix and Windows Conf files and Java properties.
  289. Most conf files know only three kinds of constructs: parameter
  290. assignments optionally grouped into sections and comments. Yet
  291. there is a great range of variation in the exact syntax of conf
  292. files. See below for various wrapper commands that set up the
  293. details for some of the most widespread variants.
  294. This mode sets up font locking, outline, imenu and it provides
  295. alignment support through `conf-align-assignments'. If strings
  296. come out wrong, try `conf-quote-normal'.
  297. Some files allow continuation lines, either with a backslash at
  298. the end of line, or by indenting the next line (further). These
  299. constructs cannot currently be recognized.
  300. Because of this great variety of nuances, which are often not
  301. even clearly specified, please don't expect it to get every file
  302. quite right. Patches that clearly identify some special case,
  303. without breaking the general ones, are welcome.
  304. If instead you start this mode with the generic `conf-mode'
  305. command, it will parse the buffer. It will generally well
  306. identify the first four cases listed below. If the buffer
  307. doesn't have enough contents to decide, this is identical to
  308. `conf-windows-mode' on Windows, elsewhere to `conf-unix-mode'.
  309. See also `conf-space-mode', `conf-colon-mode', `conf-javaprop-mode',
  310. `conf-ppd-mode' and `conf-xdefaults-mode'.
  311. \\{conf-mode-map}"
  312. (interactive)
  313. ;; `conf-mode' plays two roles: it's the parent of several sub-modes
  314. ;; but it's also the function that chooses between those submodes.
  315. ;; To tell the difference between those two cases where the function
  316. ;; might be called, we check `delay-mode-hooks'.
  317. ;; (adopted from tex-mode.el)
  318. (if (not delay-mode-hooks)
  319. ;; try to guess sub-mode of conf-mode based on buffer content
  320. (let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0))
  321. (save-excursion
  322. (goto-char (point-min))
  323. (while (not (eobp))
  324. (skip-chars-forward " \t\f")
  325. (cond ((eq (char-after) ?\#) (setq unix (1+ unix)))
  326. ((eq (char-after) ?\;) (setq win (1+ win)))
  327. ((eq (char-after) ?\[)) ; nop
  328. ((eolp)) ; nop
  329. ((eq (char-after) ?})) ; nop
  330. ;; recognize at most double spaces within names
  331. ((looking-at "[^ \t\n=:]+\\(?: ?[^ \t\n=:]+\\)*[ \t]*[=:]")
  332. (if (eq (char-before (match-end 0)) ?=)
  333. (setq equal (1+ equal))
  334. (setq colon (1+ colon))))
  335. ((looking-at "/[/*]") (setq jp (1+ jp)))
  336. ((looking-at ".*{")) ; nop
  337. ((setq space (1+ space))))
  338. (forward-line)))
  339. (cond
  340. ((> jp (max unix win 3)) (conf-javaprop-mode))
  341. ((> colon (max equal space)) (conf-colon-mode))
  342. ((> space (max equal colon)) (conf-space-mode))
  343. ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt)))
  344. (conf-windows-mode))
  345. (t (conf-unix-mode))))
  346. (kill-all-local-variables)
  347. (use-local-map conf-mode-map)
  348. (setq major-mode 'conf-mode
  349. mode-name "Conf[?]")
  350. (set (make-local-variable 'font-lock-defaults)
  351. '(conf-font-lock-keywords nil t nil nil))
  352. ;; Let newcomment.el decide this for itself.
  353. ;; (set (make-local-variable 'comment-use-syntax) t)
  354. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  355. (set (make-local-variable 'outline-regexp)
  356. "[ \t]*\\(?:\\[\\|.+[ \t\n]*{\\)")
  357. (set (make-local-variable 'outline-heading-end-regexp)
  358. "[\n}]")
  359. (set (make-local-variable 'outline-level)
  360. 'conf-outline-level)
  361. (set-syntax-table conf-mode-syntax-table)
  362. (setq imenu-generic-expression
  363. '(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1)
  364. ;; [section]
  365. (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1)
  366. ;; section { ... }
  367. (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1)))
  368. (run-mode-hooks 'conf-mode-hook)))
  369. (defun conf-mode-initialize (comment &optional font-lock)
  370. "Initializations for sub-modes of conf-mode.
  371. COMMENT initializes `comment-start' and `comment-start-skip'.
  372. The optional arg FONT-LOCK is the value for FONT-LOCK-KEYWORDS."
  373. (set (make-local-variable 'comment-start) comment)
  374. (set (make-local-variable 'comment-start-skip)
  375. (concat (regexp-quote comment-start) "+\\s *"))
  376. (if font-lock
  377. (set (make-local-variable 'font-lock-defaults)
  378. `(,font-lock nil t nil nil))))
  379. ;;;###autoload
  380. (define-derived-mode conf-unix-mode conf-mode "Conf[Unix]"
  381. "Conf Mode starter for Unix style Conf files.
  382. Comments start with `#'.
  383. For details see `conf-mode'. Example:
  384. # Conf mode font-locks this right on Unix and with \\[conf-unix-mode]
  385. \[Desktop Entry]
  386. Encoding=UTF-8
  387. Name=The GIMP
  388. Name[ca]=El GIMP
  389. Name[cs]=GIMP"
  390. (conf-mode-initialize "#"))
  391. ;;;###autoload
  392. (define-derived-mode conf-windows-mode conf-mode "Conf[WinIni]"
  393. "Conf Mode starter for Windows style Conf files.
  394. Comments start with `;'.
  395. For details see `conf-mode'. Example:
  396. ; Conf mode font-locks this right on Windows and with \\[conf-windows-mode]
  397. \[ExtShellFolderViews]
  398. Default={5984FFE0-28D4-11CF-AE66-08002B2E1262}
  399. {5984FFE0-28D4-11CF-AE66-08002B2E1262}={5984FFE0-28D4-11CF-AE66-08002B2E1262}
  400. \[{5984FFE0-28D4-11CF-AE66-08002B2E1262}]
  401. PersistMoniker=file://Folder.htt"
  402. (conf-mode-initialize ";"))
  403. ;; Here are a few more or less widespread styles. There are others, so
  404. ;; obscure, they are not covered. E.g. RFC 2614 allows both Unix and Windows
  405. ;; comments. Or the donkey has (* Pascal comments *) -- roll your own starter
  406. ;; if you need it.
  407. ;;;###autoload
  408. (define-derived-mode conf-javaprop-mode conf-mode "Conf[JavaProp]"
  409. "Conf Mode starter for Java properties files.
  410. Comments start with `#' but are also recognized with `//' or
  411. between `/*' and `*/'.
  412. For details see `conf-mode'. Example:
  413. # Conf mode font-locks this right with \\[conf-javaprop-mode] (Java properties)
  414. // another kind of comment
  415. /* yet another */
  416. name:value
  417. name=value
  418. name value
  419. x.1 =
  420. x.2.y.1.z.1 =
  421. x.2.y.1.z.2.zz ="
  422. (conf-mode-initialize "#" 'conf-javaprop-font-lock-keywords)
  423. (set (make-local-variable 'conf-assignment-column)
  424. conf-javaprop-assignment-column)
  425. (set (make-local-variable 'conf-assignment-regexp)
  426. ".+?\\([ \t]*[=: \t][ \t]*\\|$\\)")
  427. (setq comment-start-skip "\\(?:#+\\|/[/*]+\\)\\s *")
  428. (setq imenu-generic-expression
  429. '(("Parameters" "^[ \t]*\\(.+?\\)[=: \t]" 1))))
  430. ;;;###autoload
  431. (define-derived-mode conf-space-mode conf-unix-mode "Conf[Space]"
  432. "Conf Mode starter for space separated conf files.
  433. \"Assignments\" are with ` '. Keywords before the parameters are
  434. recognized according to the variable `conf-space-keywords-alist'.
  435. Alternatively, you can specify a value for the file local variable
  436. `conf-space-keywords'.
  437. Use the function `conf-space-keywords' if you want to specify keywords
  438. in an interactive fashion instead.
  439. For details see `conf-mode'. Example:
  440. # Conf mode font-locks this right with \\[conf-space-mode] (space separated)
  441. image/jpeg jpeg jpg jpe
  442. image/png png
  443. image/tiff tiff tif
  444. # Or with keywords (from a recognized file name):
  445. class desktop
  446. # Standard multimedia devices
  447. add /dev/audio desktop
  448. add /dev/mixer desktop"
  449. (conf-mode-initialize "#" 'conf-space-font-lock-keywords)
  450. (make-local-variable 'conf-assignment-sign)
  451. (setq conf-assignment-sign nil)
  452. (make-local-variable 'conf-space-keywords)
  453. (cond (buffer-file-name
  454. ;; We set conf-space-keywords directly, but a value which is
  455. ;; in the local variables list or interactively specified
  456. ;; (see the function conf-space-keywords) takes precedence.
  457. (setq conf-space-keywords
  458. (assoc-default buffer-file-name conf-space-keywords-alist
  459. 'string-match))))
  460. (conf-space-mode-internal)
  461. ;; In case the local variables list specifies conf-space-keywords,
  462. ;; recompute other things from that afterward.
  463. (add-hook 'hack-local-variables-hook 'conf-space-mode-internal nil t))
  464. ;;;###autoload
  465. (defun conf-space-keywords (keywords)
  466. "Enter Conf Space mode using regexp KEYWORDS to match the keywords.
  467. See `conf-space-mode'."
  468. (interactive "sConf Space keyword regexp: ")
  469. (delay-mode-hooks
  470. (conf-space-mode))
  471. (if (string-equal keywords "")
  472. (setq keywords nil))
  473. (setq conf-space-keywords keywords)
  474. (conf-space-mode-internal)
  475. (run-mode-hooks))
  476. (defun conf-space-mode-internal ()
  477. (make-local-variable 'conf-assignment-regexp)
  478. (setq conf-assignment-regexp
  479. (if conf-space-keywords
  480. (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)")
  481. ".+?\\([ \t]+\\|$\\)"))
  482. ;; If Font Lock is already enabled, reenable it with new
  483. ;; conf-assignment-regexp.
  484. (when (and font-lock-mode
  485. (boundp 'font-lock-keywords)) ;see `normal-mode'
  486. (font-lock-add-keywords nil nil)
  487. (font-lock-mode 1))
  488. ;; Copy so that we don't destroy shared structure.
  489. (setq imenu-generic-expression (copy-sequence imenu-generic-expression))
  490. ;; Get rid of any existing Parameters element.
  491. (setq imenu-generic-expression
  492. (delq (assoc "Parameters" imenu-generic-expression)
  493. imenu-generic-expression))
  494. ;; Add a new one based on conf-space-keywords.
  495. (setq imenu-generic-expression
  496. (cons `("Parameters"
  497. ,(if conf-space-keywords
  498. (concat "^[ \t]*\\(?:" conf-space-keywords
  499. "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)")
  500. "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)")
  501. 1)
  502. imenu-generic-expression)))
  503. ;;;###autoload
  504. (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]"
  505. "Conf Mode starter for Colon files.
  506. \"Assignments\" are with `:'.
  507. For details see `conf-mode'. Example:
  508. # Conf mode font-locks this right with \\[conf-colon-mode] (colon)
  509. <Multi_key> <exclam> <exclam> : \"\\241\" exclamdown
  510. <Multi_key> <c> <slash> : \"\\242\" cent"
  511. (conf-mode-initialize "#" 'conf-colon-font-lock-keywords)
  512. (set (make-local-variable 'conf-assignment-space)
  513. conf-colon-assignment-space)
  514. (set (make-local-variable 'conf-assignment-column)
  515. conf-colon-assignment-column)
  516. (set (make-local-variable 'conf-assignment-sign)
  517. ?:)
  518. (set (make-local-variable 'conf-assignment-regexp)
  519. ".+?\\([ \t]*:[ \t]*\\)")
  520. (setq imenu-generic-expression
  521. `(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*:" 1)
  522. ,@(cdr imenu-generic-expression))))
  523. ;;;###autoload
  524. (define-derived-mode conf-ppd-mode conf-colon-mode "Conf[PPD]"
  525. "Conf Mode starter for Adobe/CUPS PPD files.
  526. Comments start with `*%' and \"assignments\" are with `:'.
  527. For details see `conf-mode'. Example:
  528. *% Conf mode font-locks this right with \\[conf-ppd-mode] (PPD)
  529. *DefaultTransfer: Null
  530. *Transfer Null.Inverse: \"{ 1 exch sub }\""
  531. (conf-mode-initialize "*%")
  532. ;; no sections, they match within PostScript code
  533. (setq imenu-generic-expression (list (car imenu-generic-expression))))
  534. ;;;###autoload
  535. (define-derived-mode conf-xdefaults-mode conf-colon-mode "Conf[Xdefaults]"
  536. "Conf Mode starter for Xdefaults files.
  537. Comments start with `!' and \"assignments\" are with `:'.
  538. For details see `conf-mode'. Example:
  539. ! Conf mode font-locks this right with \\[conf-xdefaults-mode] (.Xdefaults)
  540. *background: gray99
  541. *foreground: black"
  542. (conf-mode-initialize "!"))
  543. (provide 'conf-mode)
  544. ;;; conf-mode.el ends here