1 ;; GNU Emacs major mode for editing nroff source
2 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
4 ;; 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 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 (defvar nroff-mode-abbrev-table nil
23 "Abbrev table used while in nroff mode.")
25 (defvar nroff-mode-map nil
26 "Major mode keymap for nroff mode.")
27 (if (not nroff-mode-map
)
29 (setq nroff-mode-map
(make-sparse-keymap))
30 (define-key nroff-mode-map
"\t" 'tab-to-tab-stop
)
31 (define-key nroff-mode-map
"\es" 'center-line
)
32 (define-key nroff-mode-map
"\e?" 'count-text-lines
)
33 (define-key nroff-mode-map
"\n" 'electric-nroff-newline
)
34 (define-key nroff-mode-map
"\en" 'forward-text-line
)
35 (define-key nroff-mode-map
"\ep" 'backward-text-line
)))
38 "Major mode for editing text intended for nroff to format.
40 Turning on Nroff mode runs `text-mode-hook', then `nroff-mode-hook'.
41 Also, try `nroff-electric-mode', for automatically inserting
42 closing requests for requests that are used in matched pairs."
44 (kill-all-local-variables)
45 (use-local-map nroff-mode-map
)
46 (setq mode-name
"Nroff")
47 (setq major-mode
'nroff-mode
)
48 (set-syntax-table text-mode-syntax-table
)
49 (setq local-abbrev-table nroff-mode-abbrev-table
)
50 (make-local-variable 'nroff-electric-mode
)
51 ;; now define a bunch of variables for use by commands in this mode
52 (make-local-variable 'page-delimiter
)
53 (setq page-delimiter
"^\\.\\(bp\\|SK\\|OP\\)")
54 (make-local-variable 'paragraph-start
)
55 (setq paragraph-start
(concat "^[.']\\|" paragraph-start
))
56 (make-local-variable 'paragraph-separate
)
57 (setq paragraph-separate
(concat "^[.']\\|" paragraph-separate
))
58 ;; comment syntax added by mit-erl!gildea 18 Apr 86
59 (make-local-variable 'comment-start
)
60 (setq comment-start
"\\\" ")
61 (make-local-variable 'comment-start-skip
)
62 (setq comment-start-skip
"\\\\\"[ \t]*")
63 (make-local-variable 'comment-column
)
64 (setq comment-column
24)
65 (make-local-variable 'comment-indent-hook
)
66 (setq comment-indent-hook
'nroff-comment-indent
)
67 (run-hooks 'text-mode-hook
'nroff-mode-hook
))
69 ;;; Compute how much to indent a comment in nroff/troff source.
70 ;;; By mit-erl!gildea April 86
71 (defun nroff-comment-indent ()
72 "Compute indent for an nroff/troff comment.
73 Puts a full-stop before comments on a line by themselves."
77 (skip-chars-backward " \t")
88 (* 8 (/ (+ (current-column)
89 9) 8)))))) ; add 9 to ensure at least two blanks
92 (defun count-text-lines (start end
&optional print
)
93 "Count lines in region, except for nroff request lines.
94 All lines not starting with a period are counted up.
95 Interactively, print result in echo area.
96 Noninteractively, return number of non-request lines from START to END."
99 (message "Region has %d text lines" (count-text-lines start end
))
102 (narrow-to-region start end
)
103 (goto-char (point-min))
104 (- (buffer-size) (forward-text-line (buffer-size)))))))
106 (defun forward-text-line (&optional cnt
)
107 "Go forward one nroff text line, skipping lines of nroff requests.
108 An argument is a repeat count; if negative, move backward."
110 (if (not cnt
) (setq cnt
1))
111 (while (and (> cnt
0) (not (eobp)))
113 (while (and (not (eobp)) (looking-at "[.']."))
115 (setq cnt
(- cnt
1)))
116 (while (and (< cnt
0) (not (bobp)))
118 (while (and (not (bobp))
119 (looking-at "[.']."))
121 (setq cnt
(+ cnt
1)))
124 (defun backward-text-line (&optional cnt
)
125 "Go backward one nroff text line, skipping lines of nroff requests.
126 An argument is a repeat count; negative means move forward."
128 (forward-text-line (- cnt
)))
130 (defconst nroff-brace-table
161 (".G1" .
".G2") ; grap
166 (defun electric-nroff-newline (arg)
167 "Insert newline for nroff mode; special if electric-nroff mode.
168 In `electric-nroff-mode', if ending a line containing an nroff opening request,
169 automatically inserts the matching closing request after point."
171 (let ((completion (save-excursion
175 (<= (point) (- (point-max) 3))
176 (cdr (assoc (buffer-substring (point)
178 nroff-brace-table
)))))
179 (needs-nl (not (looking-at "[ \t]*$"))))
180 (if (null completion
)
181 (newline (prefix-numeric-value arg
))
183 (insert "\n\n" completion
)
184 (if needs-nl
(insert "\n")))
187 (defun electric-nroff-mode (&optional arg
)
188 "Toggle `nroff-electric-newline' minor mode.
189 `nroff-electric-newline' forces Emacs to check for an nroff request at the
190 beginning of the line, and insert the matching closing request if necessary.
191 This command toggles that mode (off->on, on->off), with an argument,
192 turns it on iff arg is positive, otherwise off."
194 (or (eq major-mode
'nroff-mode
) (error "Must be in nroff mode"))
195 (or (assq 'nroff-electric-mode minor-mode-alist
)
196 (setq minor-mode-alist
(append minor-mode-alist
197 (list '(nroff-electric-mode
199 (setq nroff-electric-mode
200 (cond ((null arg
) (null nroff-electric-mode
))
201 (t (> (prefix-numeric-value arg
) 0)))))