comparison lisp/textmodes/conf-mode.el @ 93535:a128a4284881

* emacs-lisp/debug.el (debugger-mode-map): * textmodes/conf-mode.el (conf-mode-map): Add a menu. (conf-align-assignments): Only work on the region if it is active. (conf-quote-normal): Use when instead of if. Remove redundant test.
author Dan Nicolaescu <dann@ics.uci.edu>
date Wed, 02 Apr 2008 06:35:21 +0000
parents dc100f64b2b7
children f4a69fedbd46
comparison
equal deleted inserted replaced
93534:8bdec2731742 93535:a128a4284881
67 (defcustom conf-colon-assignment-space nil 67 (defcustom conf-colon-assignment-space nil
68 "Value for `conf-assignment-space' in colon style Conf mode buffers." 68 "Value for `conf-assignment-space' in colon style Conf mode buffers."
69 :type 'boolean 69 :type 'boolean
70 :group 'conf) 70 :group 'conf)
71 71
72
73 (defvar conf-mode-map 72 (defvar conf-mode-map
74 (let ((map (make-sparse-keymap))) 73 (let ((map (make-sparse-keymap))
74 (menu-map (make-sparse-keymap)))
75 (define-key map "\C-c\C-u" 'conf-unix-mode) 75 (define-key map "\C-c\C-u" 'conf-unix-mode)
76 (define-key map "\C-c\C-w" 'conf-windows-mode) 76 (define-key map "\C-c\C-w" 'conf-windows-mode)
77 (define-key map "\C-c\C-j" 'conf-javaprop-mode) 77 (define-key map "\C-c\C-j" 'conf-javaprop-mode)
78 (define-key map "\C-c\C-s" 'conf-space-keywords) 78 (define-key map "\C-c\C-s" 'conf-space-keywords)
79 (define-key map "\C-c " 'conf-space-keywords) 79 (define-key map "\C-c " 'conf-space-keywords)
83 (define-key map "\C-c\C-p" 'conf-ppd-mode) 83 (define-key map "\C-c\C-p" 'conf-ppd-mode)
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 (define-key map [menu-bar sh-script] (cons "Conf" menu-map))
89 (define-key menu-map [conf-windows-mode]
90 '(menu-item "Windows mode"
91 conf-windows-mode
92 :help "Conf Mode starter for Windows style Conf files"
93 :button (:radio . (eq major-mode 'conf-windows-mode))))
94 (define-key menu-map [conf-javaprop-mode]
95 '(menu-item "Java properties mode"
96 conf-javaprop-mode
97 :help "Conf Mode starter for Java properties files"
98 :button (:radio . (eq major-mode 'conf-javaprop-mode))))
99 (define-key menu-map [conf-space-keywords]
100 '(menu-item "Space keywords mode..."
101 conf-space-keywords
102 :help "Enter Conf Space mode using regexp KEYWORDS to match the keywords"
103 :button (:radio . (eq major-mode 'conf-space-keywords))))
104 (define-key menu-map [conf-ppd-mode]
105 '(menu-item "PPD mode"
106 conf-ppd-mode
107 :help "Conf Mode starter for Adobe/CUPS PPD files"
108 :button (:radio . (eq major-mode 'conf-ppd-mode))))
109 (define-key menu-map [conf-colon-mode]
110 '(menu-item "Colon mode"
111 conf-colon-mode
112 :help "Conf Mode starter for Colon files"
113 :button (:radio . (eq major-mode 'conf-colon-mode))))
114 (define-key menu-map [conf-unix-mode]
115 '(menu-item "Unix mode"
116 conf-unix-mode
117 :help "Conf Mode starter for Unix style Conf files"
118 :button (:radio . (eq major-mode 'conf-unix-mode))))
119 (define-key menu-map [conf-xdefaults-mode]
120 '(menu-item "Xdefaults mode"
121 conf-xdefaults-mode
122 :help "Conf Mode starter for Xdefaults files"
123 :button (:radio . (eq major-mode 'conf-xdefaults-mode))))
124 (define-key menu-map [c-s0] '("--"))
125 (define-key menu-map [conf-quote-normal]
126 '(menu-item "Set quote syntax normal" conf-quote-normal
127 :help "Set the syntax of \' and \" to punctuation"))
128 (define-key menu-map [conf-align-assignments]
129 '(menu-item "Align assignments" conf-align-assignments
130 :help "Align assignments"))
88 map) 131 map)
89 "Local keymap for `conf-mode' buffers.") 132 "Local keymap for `conf-mode' buffers.")
90 133
91 (defvar conf-mode-syntax-table 134 (defvar conf-mode-syntax-table
92 (let ((table (make-syntax-table))) 135 (let ((table (make-syntax-table)))
213 256
214 ;; If anybody can figure out how to get the same effect by configuring 257 ;; If anybody can figure out how to get the same effect by configuring
215 ;; `align', I'd be glad to hear. 258 ;; `align', I'd be glad to hear.
216 (defun conf-align-assignments (&optional arg) 259 (defun conf-align-assignments (&optional arg)
217 (interactive "P") 260 (interactive "P")
261 "Align the assignments in the buffer or active region.
262 In Transient Mark mode, if the mark is active, operate on the
263 contents of the region. Otherwise, operate on the whole buffer."
218 (setq arg (if arg 264 (setq arg (if arg
219 (prefix-numeric-value arg) 265 (prefix-numeric-value arg)
220 conf-assignment-column)) 266 conf-assignment-column))
221 (save-excursion 267 (save-excursion
222 (goto-char (point-min)) 268 (save-restriction
223 (while (not (eobp)) 269 (when (use-region-p)
224 (let ((cs (comment-beginning))) ; go before comment if within 270 (narrow-to-region (region-beginning) (region-end)))
225 (if cs (goto-char cs))) 271 (goto-char (point-min))
226 (while (forward-comment 9)) ; max-int? 272 (while (not (eobp))
227 (when (and (not (eobp)) 273 (let ((cs (comment-beginning))) ; go before comment if within
228 (looking-at conf-assignment-regexp)) 274 (if cs (goto-char cs)))
229 (goto-char (match-beginning 1)) 275 (while (forward-comment 9)) ; max-int?
230 (delete-region (point) (match-end 1)) 276 (when (and (not (eobp))
231 (if conf-assignment-sign 277 (looking-at conf-assignment-regexp))
232 (if (>= arg 0) 278 (goto-char (match-beginning 1))
233 (progn 279 (delete-region (point) (match-end 1))
234 (indent-to-column arg) 280 (if conf-assignment-sign
281 (if (>= arg 0)
282 (progn
283 (indent-to-column arg)
284 (or (not conf-assignment-space)
285 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))
286 (insert conf-assignment-sign
287 (if (and conf-assignment-space (not (eolp))) ?\s "")))
288 (insert (if conf-assignment-space ?\s "") conf-assignment-sign)
289 (unless (eolp)
290 (indent-to-column (- arg))
235 (or (not conf-assignment-space) 291 (or (not conf-assignment-space)
236 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s)) 292 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
237 (insert conf-assignment-sign 293 (unless (eolp)
238 (if (and conf-assignment-space (not (eolp))) ?\s ""))) 294 (if (>= (current-column) (abs arg))
239 (insert (if conf-assignment-space ?\s "") conf-assignment-sign) 295 (insert ?\s)
240 (unless (eolp) 296 (indent-to-column (abs arg))))))
241 (indent-to-column (- arg)) 297 (forward-line)))))
242 (or (not conf-assignment-space)
243 (memq (char-before (point)) '(?\s ?\t)) (insert ?\s))))
244 (unless (eolp)
245 (if (>= (current-column) (abs arg))
246 (insert ?\s)
247 (indent-to-column (abs arg))))))
248 (forward-line))))
249 298
250 299
251 (defun conf-quote-normal (arg) 300 (defun conf-quote-normal (arg)
252 "Set the syntax of ' and \" to punctuation. 301 "Set the syntax of ' and \" to punctuation.
253 With prefix arg, only do it for ' if 1, or only for \" if 2. 302 With prefix arg, only do it for ' if 1, or only for \" if 2.
257 and you can correct it with this command. (Some files even do 306 and you can correct it with this command. (Some files even do
258 both, i.e. quotes delimit strings, except when they are 307 both, i.e. quotes delimit strings, except when they are
259 unbalanced, but hey...)" 308 unbalanced, but hey...)"
260 (interactive "P") 309 (interactive "P")
261 (let ((table (copy-syntax-table (syntax-table)))) 310 (let ((table (copy-syntax-table (syntax-table))))
262 (if (or (not arg) (= (prefix-numeric-value arg) 1)) 311 (when (or (not arg) (= (prefix-numeric-value arg) 1))
263 (modify-syntax-entry ?\' "." table)) 312 (modify-syntax-entry ?\' "." table))
264 (if (or (not arg) (= (prefix-numeric-value arg) 2)) 313 (when (or (not arg) (= (prefix-numeric-value arg) 2))
265 (modify-syntax-entry ?\" "." table)) 314 (modify-syntax-entry ?\" "." table))
266 (set-syntax-table table) 315 (set-syntax-table table)
267 (and (boundp 'font-lock-mode) 316 (when font-lock-mode
268 font-lock-mode 317 (font-lock-fontify-buffer))))
269 (font-lock-fontify-buffer))))
270 318
271 319
272 (defun conf-outline-level () 320 (defun conf-outline-level ()
273 (let ((depth 0) 321 (let ((depth 0)
274 (pt (match-end 0))) 322 (pt (match-end 0)))