comparison lisp/textmodes/nroff-mode.el @ 68660:a747e863fd26

Clean up name space. (nroff-mode-syntax-table): Remove spurious `1' in the syntax of \n. (nroff-mode): Obey the global setting of nroff-electric-mode. (nroff-electric-mode): Use define-minor-mode and derived-mode-p.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 06 Feb 2006 23:13:22 +0000
parents 8b39fc927b5e
children e3694f1cb928 c5406394f567
comparison
equal deleted inserted replaced
68659:acb7a1c16a3d 68660:a747e863fd26
40 "Nroff mode." 40 "Nroff mode."
41 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) 41 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
42 :group 'wp 42 :group 'wp
43 :prefix "nroff-") 43 :prefix "nroff-")
44 44
45
45 (defcustom nroff-electric-mode nil 46 (defcustom nroff-electric-mode nil
46 "*Non-nil means automatically closing requests when you insert an open." 47 "Non-nil means automatically closing requests when you insert an open."
47 :group 'nroff 48 :group 'nroff
48 :type 'boolean) 49 :type 'boolean)
49 50
50 (defvar nroff-mode-map 51 (defvar nroff-mode-map
51 (let ((map (make-sparse-keymap))) 52 (let ((map (make-sparse-keymap)))
52 (define-key map "\t" 'tab-to-tab-stop) 53 (define-key map "\t" 'tab-to-tab-stop)
53 (define-key map "\es" 'center-line) 54 (define-key map "\es" 'center-line)
54 (define-key map "\e?" 'count-text-lines) 55 (define-key map "\e?" 'nroff-count-text-lines)
55 (define-key map "\n" 'electric-nroff-newline) 56 (define-key map "\n" 'nroff-electric-newline)
56 (define-key map "\en" 'forward-text-line) 57 (define-key map "\en" 'nroff-forward-text-line)
57 (define-key map "\ep" 'backward-text-line) 58 (define-key map "\ep" 'nroff-backward-text-line)
58 map) 59 map)
59 "Major mode keymap for `nroff-mode'.") 60 "Major mode keymap for `nroff-mode'.")
60 61
61 (defvar nroff-mode-syntax-table 62 (defvar nroff-mode-syntax-table
62 (let ((st (copy-syntax-table text-mode-syntax-table))) 63 (let ((st (copy-syntax-table text-mode-syntax-table)))
64 ;; (arguably) should be for use round nroff arguments (with ` and 65 ;; (arguably) should be for use round nroff arguments (with ` and
65 ;; ' used otherwise). 66 ;; ' used otherwise).
66 (modify-syntax-entry ?\" "\" 2" st) 67 (modify-syntax-entry ?\" "\" 2" st)
67 ;; Comments are delimited by \" and newline. 68 ;; Comments are delimited by \" and newline.
68 (modify-syntax-entry ?\\ "\\ 1" st) 69 (modify-syntax-entry ?\\ "\\ 1" st)
69 (modify-syntax-entry ?\n "> 1" st) 70 (modify-syntax-entry ?\n ">" st)
70 st) 71 st)
71 "Syntax table used while in `nroff-mode'.") 72 "Syntax table used while in `nroff-mode'.")
72 73
73 (defvar nroff-imenu-expression 74 (defvar nroff-imenu-expression
74 ;; man headers: 75 ;; man headers:
114 (set (make-local-variable 'font-lock-defaults) 115 (set (make-local-variable 'font-lock-defaults)
115 ;; SYNTAX-BEGIN is set to backward-paragraph to avoid slow-down 116 ;; SYNTAX-BEGIN is set to backward-paragraph to avoid slow-down
116 ;; near the end of large buffers due to searching to buffer's 117 ;; near the end of large buffers due to searching to buffer's
117 ;; beginning. 118 ;; beginning.
118 '(nroff-font-lock-keywords nil t nil backward-paragraph)) 119 '(nroff-font-lock-keywords nil t nil backward-paragraph))
119 (set (make-local-variable 'nroff-electric-mode) nil)
120 (set (make-local-variable 'outline-regexp) "\\.H[ ]+[1-7]+ ") 120 (set (make-local-variable 'outline-regexp) "\\.H[ ]+[1-7]+ ")
121 (set (make-local-variable 'outline-level) 'nroff-outline-level) 121 (set (make-local-variable 'outline-level) 'nroff-outline-level)
122 ;; now define a bunch of variables for use by commands in this mode 122 ;; now define a bunch of variables for use by commands in this mode
123 (set (make-local-variable 'page-delimiter) "^\\.\\(bp\\|SK\\|OP\\)") 123 (set (make-local-variable 'page-delimiter) "^\\.\\(bp\\|SK\\|OP\\)")
124 (set (make-local-variable 'paragraph-start) 124 (set (make-local-variable 'paragraph-start)
136 (save-excursion 136 (save-excursion
137 (looking-at outline-regexp) 137 (looking-at outline-regexp)
138 (skip-chars-forward ".H ") 138 (skip-chars-forward ".H ")
139 (string-to-number (buffer-substring (point) (+ 1 (point)))))) 139 (string-to-number (buffer-substring (point) (+ 1 (point))))))
140 140
141 ;;; Compute how much to indent a comment in nroff/troff source. 141 ;; Compute how much to indent a comment in nroff/troff source.
142 ;;; By mit-erl!gildea April 86 142 ;; By mit-erl!gildea April 86
143 (defun nroff-comment-indent () 143 (defun nroff-comment-indent ()
144 "Compute indent for an nroff/troff comment. 144 "Compute indent for an nroff/troff comment.
145 Puts a full-stop before comments on a line by themselves." 145 Puts a full-stop before comments on a line by themselves."
146 (let ((pt (point))) 146 (let ((pt (point)))
147 (unwind-protect 147 (unwind-protect
159 (max comment-column 159 (max comment-column
160 (* 8 (/ (+ (current-column) 160 (* 8 (/ (+ (current-column)
161 9) 8)))))) ; add 9 to ensure at least two blanks 161 9) 8)))))) ; add 9 to ensure at least two blanks
162 (goto-char pt)))) 162 (goto-char pt))))
163 163
164 (defun count-text-lines (start end &optional print) 164 (defun nroff-count-text-lines (start end &optional print)
165 "Count lines in region, except for nroff request lines. 165 "Count lines in region, except for nroff request lines.
166 All lines not starting with a period are counted up. 166 All lines not starting with a period are counted up.
167 Interactively, print result in echo area. 167 Interactively, print result in echo area.
168 Noninteractively, return number of non-request lines from START to END." 168 Noninteractively, return number of non-request lines from START to END."
169 (interactive "r\np") 169 (interactive "r\np")
170 (if print 170 (if print
171 (message "Region has %d text lines" (count-text-lines start end)) 171 (message "Region has %d text lines" (nroff-count-text-lines start end))
172 (save-excursion 172 (save-excursion
173 (save-restriction 173 (save-restriction
174 (narrow-to-region start end) 174 (narrow-to-region start end)
175 (goto-char (point-min)) 175 (goto-char (point-min))
176 (- (buffer-size) (forward-text-line (buffer-size))))))) 176 (- (buffer-size) (forward-text-line (buffer-size)))))))
177 177
178 (defun forward-text-line (&optional cnt) 178 (defun nroff-forward-text-line (&optional cnt)
179 "Go forward one nroff text line, skipping lines of nroff requests. 179 "Go forward one nroff text line, skipping lines of nroff requests.
180 An argument is a repeat count; if negative, move backward." 180 An argument is a repeat count; if negative, move backward."
181 (interactive "p") 181 (interactive "p")
182 (if (not cnt) (setq cnt 1)) 182 (if (not cnt) (setq cnt 1))
183 (while (and (> cnt 0) (not (eobp))) 183 (while (and (> cnt 0) (not (eobp)))
191 (looking-at "[.'].")) 191 (looking-at "[.']."))
192 (forward-line -1)) 192 (forward-line -1))
193 (setq cnt (+ cnt 1))) 193 (setq cnt (+ cnt 1)))
194 cnt) 194 cnt)
195 195
196 (defun backward-text-line (&optional cnt) 196 (defun nroff-backward-text-line (&optional cnt)
197 "Go backward one nroff text line, skipping lines of nroff requests. 197 "Go backward one nroff text line, skipping lines of nroff requests.
198 An argument is a repeat count; negative means move forward." 198 An argument is a repeat count; negative means move forward."
199 (interactive "p") 199 (interactive "p")
200 (forward-text-line (- cnt))) 200 (nroff-forward-text-line (- cnt)))
201 201
202 (defconst nroff-brace-table 202 (defconst nroff-brace-table
203 '((".(b" . ".)b") 203 '((".(b" . ".)b")
204 (".(l" . ".)l") 204 (".(l" . ".)l")
205 (".(q" . ".)q") 205 (".(q" . ".)q")
233 (".G1" . ".G2") ; grap 233 (".G1" . ".G2") ; grap
234 (".na" . ".ad b") 234 (".na" . ".ad b")
235 (".nf" . ".fi") 235 (".nf" . ".fi")
236 (".de" . ".."))) 236 (".de" . "..")))
237 237
238 (defun electric-nroff-newline (arg) 238 (defun nroff-electric-newline (arg)
239 "Insert newline for nroff mode; special if electric-nroff mode. 239 "Insert newline for nroff mode; special if electric-nroff mode.
240 In `electric-nroff-mode', if ending a line containing an nroff opening request, 240 In `electric-nroff-mode', if ending a line containing an nroff opening request,
241 automatically inserts the matching closing request after point." 241 automatically inserts the matching closing request after point."
242 (interactive "P") 242 (interactive "P")
243 (let ((completion (save-excursion 243 (let ((completion (save-excursion
254 (save-excursion 254 (save-excursion
255 (insert "\n\n" completion) 255 (insert "\n\n" completion)
256 (if needs-nl (insert "\n"))) 256 (if needs-nl (insert "\n")))
257 (forward-char 1)))) 257 (forward-char 1))))
258 258
259 (defun electric-nroff-mode (&optional arg) 259 (define-minor-mode nroff-electric-mode
260 "Toggle `nroff-electric-newline' minor mode. 260 "Toggle `nroff-electric-newline' minor mode.
261 `nroff-electric-newline' forces Emacs to check for an nroff request at the 261 `nroff-electric-newline' forces Emacs to check for an nroff request at the
262 beginning of the line, and insert the matching closing request if necessary. 262 beginning of the line, and insert the matching closing request if necessary.
263 This command toggles that mode (off->on, on->off), with an argument, 263 This command toggles that mode (off->on, on->off), with an argument,
264 turns it on iff arg is positive, otherwise off." 264 turns it on iff arg is positive, otherwise off."
265 (interactive "P") 265 :lighter " Electric"
266 (or (eq major-mode 'nroff-mode) (error "Must be in nroff mode")) 266 (or (derived-mode-p 'nroff-mode) (error "Must be in nroff mode")))
267 (or (assq 'nroff-electric-mode minor-mode-alist) 267
268 (setq minor-mode-alist (append minor-mode-alist 268 ;; Old names that were not namespace clean.
269 (list '(nroff-electric-mode 269 (define-obsolete-function-alias 'count-text-lines 'nroff-count-text-lines "22.1")
270 " Electric"))))) 270 (define-obsolete-function-alias 'forward-text-line 'nroff-forward-text-line "22.1")
271 (setq nroff-electric-mode 271 (define-obsolete-function-alias 'backward-text-line 'nroff-backward-text-line "22.1")
272 (cond ((null arg) (null nroff-electric-mode)) 272 (define-obsolete-function-alias 'electric-nroff-newline 'nroff-electric-newline "22.1")
273 (t (> (prefix-numeric-value arg) 0))))) 273 (define-obsolete-function-alias 'electric-nroff-mode 'nroff-electric-mode "22.1")
274 274
275 (provide 'nroff-mode) 275 (provide 'nroff-mode)
276 276
277 ;;; arch-tag: 6e276340-6c65-4f65-b4e3-0ca431ddfb6c 277 ;; arch-tag: 6e276340-6c65-4f65-b4e3-0ca431ddfb6c
278 ;;; nroff-mode.el ends here 278 ;;; nroff-mode.el ends here