annotate lisp/modes/nroff-mode.el @ 44:8d2a9b52c682 r19-15prefinal

Import from CVS: tag r19-15prefinal
author cvs
date Mon, 13 Aug 2007 08:55:10 +0200
parents ac2d302a0011
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; nroff-mode.el --- GNU Emacs major mode for editing nroff source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3 ;; Copyright (C) 1985, 1986, 1994, 1995 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This package is a major mode for editing nroff source code. It knows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; about various nroff constructs, ms, mm, and me macros, and will fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; and indent paragraphs properly in their presence. It also includes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; a command to count text lines (excluding nroff constructs), a command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; to center a line, and movement commands that know how to skip macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
35 ;; Paragraph filling and line-counting currently don't respect comments,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
36 ;; as they should.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
37
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defvar nroff-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Abbrev table used while in nroff mode.")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
42 (define-abbrev-table 'nroff-mode-abbrev-table ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar nroff-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Major mode keymap for nroff mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (not nroff-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq nroff-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (define-key nroff-mode-map "\t" 'tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (define-key nroff-mode-map "\es" 'center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (define-key nroff-mode-map "\e?" 'count-text-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (define-key nroff-mode-map "\n" 'electric-nroff-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (define-key nroff-mode-map "\en" 'forward-text-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (define-key nroff-mode-map "\ep" 'backward-text-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 (defvar nroff-mode-syntax-table nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 "Syntax table used while in nroff mode.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 (defvar nroff-font-lock-keywords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 (list
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 ;; Directives are . or ' at start of line, followed by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 ;; optional whitespace, then command (which my be longer than
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 ;; 2 characters in groff). Perhaps the arguments should be
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 ;; fontified as well.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 "^[.']\\s-*\\sw+"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 ;; There are numerous groff escapes; the following get things
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 ;; like \-, \(em (standard troff) and \f[bar] (groff
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 ;; variants). This won't currently do groff's \A'foo' and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
69 ;; the like properly. One might expect it to highlight an escape's
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
70 ;; arguments in common cases, like \f.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
71 (concat "\\\\" ; backslash
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
72 "\\(" ; followed by various possibilities
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
73 (mapconcat 'identity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
74 '("[f*n]*\\[.+]" ; some groff extensions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75 "(.." ; two chars after (
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 "[^(\"]" ; single char escape
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 ) "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 "\\)")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 "Font-lock highlighting control in nroff-mode.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun nroff-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "Major mode for editing text intended for nroff to format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 \\{nroff-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Turning on Nroff mode runs `text-mode-hook', then `nroff-mode-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Also, try `nroff-electric-mode', for automatically inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 closing requests for requests that are used in matched pairs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (use-local-map nroff-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq mode-name "Nroff")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq major-mode 'nroff-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
94 (if nroff-mode-syntax-table
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
95 ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
96 (setq nroff-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
97 ;; " isn't given string quote syntax in text-mode but it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 ;; (arguably) should be for use round nroff arguments (with ` and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99 ;; ' used otherwise).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100 (modify-syntax-entry ?\" "\" 2" nroff-mode-syntax-table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
101 ;; Comments are delimited by \" and newline.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
102 (modify-syntax-entry ?\\ "\\ 1" nroff-mode-syntax-table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
103 (modify-syntax-entry ?\n "> 1" nroff-mode-syntax-table))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
104 (set-syntax-table nroff-mode-syntax-table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
105 (make-local-variable 'font-lock-defaults)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
106 (setq font-lock-defaults '(nroff-font-lock-keywords nil t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq local-abbrev-table nroff-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (make-local-variable 'nroff-electric-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq nroff-electric-mode nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
110 (make-local-variable 'outline-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
111 (setq outline-regexp "\\.H[ ]+[1-7]+ ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
112 (make-local-variable 'outline-level)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
113 (setq outline-level 'nroff-outline-level)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; now define a bunch of variables for use by commands in this mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (make-local-variable 'page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq page-delimiter "^\\.\\(bp\\|SK\\|OP\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (make-local-variable 'paragraph-start)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
118 (setq paragraph-start (concat "[.']\\|" paragraph-start))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (make-local-variable 'paragraph-separate)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
120 (setq paragraph-separate (concat "[.']\\|" paragraph-separate))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; comment syntax added by mit-erl!gildea 18 Apr 86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq comment-start "\\\" ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq comment-start-skip "\\\\\"[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq comment-column 24)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (make-local-variable 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (setq comment-indent-function 'nroff-comment-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (run-hooks 'text-mode-hook 'nroff-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
132 (defun nroff-outline-level ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
134 (looking-at outline-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
135 (skip-chars-forward ".H ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 (string-to-int (buffer-substring (point) (+ 1 (point))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; Compute how much to indent a comment in nroff/troff source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;; By mit-erl!gildea April 86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defun nroff-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "Compute indent for an nroff/troff comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 Puts a full-stop before comments on a line by themselves."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((pt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq pt (1+ pt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (insert ?.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (looking-at "^[.']"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (max comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (* 8 (/ (+ (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 9) 8)))))) ; add 9 to ensure at least two blanks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (goto-char pt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defun count-text-lines (start end &optional print)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Count lines in region, except for nroff request lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 All lines not starting with a period are counted up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Interactively, print result in echo area.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Noninteractively, return number of non-request lines from START to END."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (interactive "r\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (message "Region has %d text lines" (count-text-lines start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (- (buffer-size) (forward-text-line (buffer-size)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun forward-text-line (&optional cnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Go forward one nroff text line, skipping lines of nroff requests.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 An argument is a repeat count; if negative, move backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (not cnt) (setq cnt 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (while (and (> cnt 0) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (while (and (not (eobp)) (looking-at "[.']."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq cnt (- cnt 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (while (and (< cnt 0) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (looking-at "[.']."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq cnt (+ cnt 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 cnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun backward-text-line (&optional cnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Go backward one nroff text line, skipping lines of nroff requests.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 An argument is a repeat count; negative means move forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (forward-text-line (- cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defconst nroff-brace-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 '((".(b" . ".)b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (".(l" . ".)l")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (".(q" . ".)q")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (".(c" . ".)c")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (".(x" . ".)x")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (".(z" . ".)z")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (".(d" . ".)d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (".(f" . ".)f")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (".LG" . ".NL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (".SM" . ".NL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (".LD" . ".DE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (".CD" . ".DE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (".BD" . ".DE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (".DS" . ".DE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (".DF" . ".DE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (".FS" . ".FE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (".KS" . ".KE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (".KF" . ".KE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (".LB" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (".AL" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (".BL" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (".DL" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (".ML" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (".RL" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (".VL" . ".LE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (".RS" . ".RE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (".TS" . ".TE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (".EQ" . ".EN")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (".PS" . ".PE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (".BS" . ".BE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (".G1" . ".G2") ; grap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (".na" . ".ad b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (".nf" . ".fi")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (".de" . "..")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (defun electric-nroff-newline (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 "Insert newline for nroff mode; special if electric-nroff mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 In `electric-nroff-mode', if ending a line containing an nroff opening request,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 automatically inserts the matching closing request after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (let ((completion (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 nroff-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (<= (point) (- (point-max) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (cdr (assoc (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (+ 3 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 nroff-brace-table)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (needs-nl (not (looking-at "[ \t]*$"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (newline (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (insert "\n\n" completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if needs-nl (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun electric-nroff-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "Toggle `nroff-electric-newline' minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 `nroff-electric-newline' forces Emacs to check for an nroff request at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 beginning of the line, and insert the matching closing request if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 This command toggles that mode (off->on, on->off), with an argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 turns it on iff arg is positive, otherwise off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (or (eq major-mode 'nroff-mode) (error "Must be in nroff mode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; XEmacs: see below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ; (or (assq 'nroff-electric-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ; (setq minor-mode-alist (append minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ; (list '(nroff-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ; " Electric")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq nroff-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (cond ((null arg) (null nroff-electric-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (t (> (prefix-numeric-value arg) 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defvar nroff-electric-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "Non-nil if in electric-nroff minor mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; XEmacs: do it right. This must come after the defun of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; electric-nroff-mode so that add-minor-mode will recognize it as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; perverse variable name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (add-minor-mode 'nroff-electric-mode " Electric" nil nil 'electric-nroff-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;;; nroff-mode.el ends here