Mercurial > hg > xemacs-beta
comparison lisp/modes/nroff-mode.el @ 2:ac2d302a0011 r19-15b2
Import from CVS: tag r19-15b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:35 +0200 |
parents | 376386a54a3c |
children |
comparison
equal
deleted
inserted
replaced
1:c0c6a60d29db | 2:ac2d302a0011 |
---|---|
1 ;;; nroff-mode.el --- GNU Emacs major mode for editing nroff source | 1 ;;; nroff-mode.el --- GNU Emacs major mode for editing nroff source |
2 | 2 |
3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1994, 1995 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF | 5 ;; Maintainer: FSF |
6 ;; Keywords: wp | 6 ;; Keywords: wp |
7 | 7 |
8 ;; This file is part of XEmacs. | 8 ;; This file is part of XEmacs. |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 ;; General Public License for more details. | 18 ;; General Public License for more details. |
19 | 19 |
20 ;; You should have received a copy of the GNU General Public License | 20 ;; You should have received a copy of the GNU General Public License |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
23 ;; 02111-1307, USA. | |
24 | |
25 ;;; Synched up with: FSF 19.34. | |
23 | 26 |
24 ;;; Commentary: | 27 ;;; Commentary: |
25 | 28 |
26 ;; This package is a major mode for editing nroff source code. It knows | 29 ;; This package is a major mode for editing nroff source code. It knows |
27 ;; about various nroff constructs, ms, mm, and me macros, and will fill | 30 ;; about various nroff constructs, ms, mm, and me macros, and will fill |
28 ;; and indent paragraphs properly in their presence. It also includes | 31 ;; and indent paragraphs properly in their presence. It also includes |
29 ;; a command to count text lines (excluding nroff constructs), a command | 32 ;; a command to count text lines (excluding nroff constructs), a command |
30 ;; to center a line, and movement commands that know how to skip macros. | 33 ;; to center a line, and movement commands that know how to skip macros. |
31 | 34 |
35 ;; Paragraph filling and line-counting currently don't respect comments, | |
36 ;; as they should. | |
37 | |
32 ;;; Code: | 38 ;;; Code: |
33 | 39 |
34 (defvar nroff-mode-abbrev-table nil | 40 (defvar nroff-mode-abbrev-table nil |
35 "Abbrev table used while in nroff mode.") | 41 "Abbrev table used while in nroff mode.") |
42 (define-abbrev-table 'nroff-mode-abbrev-table ()) | |
36 | 43 |
37 (defvar nroff-mode-map nil | 44 (defvar nroff-mode-map nil |
38 "Major mode keymap for nroff mode.") | 45 "Major mode keymap for nroff mode.") |
39 (if (not nroff-mode-map) | 46 (if (not nroff-mode-map) |
40 (progn | 47 (progn |
44 (define-key nroff-mode-map "\e?" 'count-text-lines) | 51 (define-key nroff-mode-map "\e?" 'count-text-lines) |
45 (define-key nroff-mode-map "\n" 'electric-nroff-newline) | 52 (define-key nroff-mode-map "\n" 'electric-nroff-newline) |
46 (define-key nroff-mode-map "\en" 'forward-text-line) | 53 (define-key nroff-mode-map "\en" 'forward-text-line) |
47 (define-key nroff-mode-map "\ep" 'backward-text-line))) | 54 (define-key nroff-mode-map "\ep" 'backward-text-line))) |
48 | 55 |
56 (defvar nroff-mode-syntax-table nil | |
57 "Syntax table used while in nroff mode.") | |
58 | |
59 (defvar nroff-font-lock-keywords | |
60 (list | |
61 ;; Directives are . or ' at start of line, followed by | |
62 ;; optional whitespace, then command (which my be longer than | |
63 ;; 2 characters in groff). Perhaps the arguments should be | |
64 ;; fontified as well. | |
65 "^[.']\\s-*\\sw+" | |
66 ;; There are numerous groff escapes; the following get things | |
67 ;; like \-, \(em (standard troff) and \f[bar] (groff | |
68 ;; variants). This won't currently do groff's \A'foo' and | |
69 ;; the like properly. One might expect it to highlight an escape's | |
70 ;; arguments in common cases, like \f. | |
71 (concat "\\\\" ; backslash | |
72 "\\(" ; followed by various possibilities | |
73 (mapconcat 'identity | |
74 '("[f*n]*\\[.+]" ; some groff extensions | |
75 "(.." ; two chars after ( | |
76 "[^(\"]" ; single char escape | |
77 ) "\\|") | |
78 "\\)") | |
79 ) | |
80 "Font-lock highlighting control in nroff-mode.") | |
81 | |
49 ;;;###autoload | 82 ;;;###autoload |
50 (defun nroff-mode () | 83 (defun nroff-mode () |
51 "Major mode for editing text intended for nroff to format. | 84 "Major mode for editing text intended for nroff to format. |
52 \\{nroff-mode-map} | 85 \\{nroff-mode-map} |
53 Turning on Nroff mode runs `text-mode-hook', then `nroff-mode-hook'. | 86 Turning on Nroff mode runs `text-mode-hook', then `nroff-mode-hook'. |
56 (interactive) | 89 (interactive) |
57 (kill-all-local-variables) | 90 (kill-all-local-variables) |
58 (use-local-map nroff-mode-map) | 91 (use-local-map nroff-mode-map) |
59 (setq mode-name "Nroff") | 92 (setq mode-name "Nroff") |
60 (setq major-mode 'nroff-mode) | 93 (setq major-mode 'nroff-mode) |
61 (set-syntax-table text-mode-syntax-table) | 94 (if nroff-mode-syntax-table |
95 () | |
96 (setq nroff-mode-syntax-table (copy-syntax-table text-mode-syntax-table)) | |
97 ;; " isn't given string quote syntax in text-mode but it | |
98 ;; (arguably) should be for use round nroff arguments (with ` and | |
99 ;; ' used otherwise). | |
100 (modify-syntax-entry ?\" "\" 2" nroff-mode-syntax-table) | |
101 ;; Comments are delimited by \" and newline. | |
102 (modify-syntax-entry ?\\ "\\ 1" nroff-mode-syntax-table) | |
103 (modify-syntax-entry ?\n "> 1" nroff-mode-syntax-table)) | |
104 (set-syntax-table nroff-mode-syntax-table) | |
105 (make-local-variable 'font-lock-defaults) | |
106 (setq font-lock-defaults '(nroff-font-lock-keywords nil t)) | |
62 (setq local-abbrev-table nroff-mode-abbrev-table) | 107 (setq local-abbrev-table nroff-mode-abbrev-table) |
63 (make-local-variable 'nroff-electric-mode) | 108 (make-local-variable 'nroff-electric-mode) |
64 (setq nroff-electric-mode nil) | 109 (setq nroff-electric-mode nil) |
110 (make-local-variable 'outline-regexp) | |
111 (setq outline-regexp "\\.H[ ]+[1-7]+ ") | |
112 (make-local-variable 'outline-level) | |
113 (setq outline-level 'nroff-outline-level) | |
65 ;; now define a bunch of variables for use by commands in this mode | 114 ;; now define a bunch of variables for use by commands in this mode |
66 (make-local-variable 'page-delimiter) | 115 (make-local-variable 'page-delimiter) |
67 (setq page-delimiter "^\\.\\(bp\\|SK\\|OP\\)") | 116 (setq page-delimiter "^\\.\\(bp\\|SK\\|OP\\)") |
68 (make-local-variable 'paragraph-start) | 117 (make-local-variable 'paragraph-start) |
69 (setq paragraph-start (concat "^[.']\\|" paragraph-start)) | 118 (setq paragraph-start (concat "[.']\\|" paragraph-start)) |
70 (make-local-variable 'paragraph-separate) | 119 (make-local-variable 'paragraph-separate) |
71 (setq paragraph-separate (concat "^[.']\\|" paragraph-separate)) | 120 (setq paragraph-separate (concat "[.']\\|" paragraph-separate)) |
72 ;; comment syntax added by mit-erl!gildea 18 Apr 86 | 121 ;; comment syntax added by mit-erl!gildea 18 Apr 86 |
73 (make-local-variable 'comment-start) | 122 (make-local-variable 'comment-start) |
74 (setq comment-start "\\\" ") | 123 (setq comment-start "\\\" ") |
75 (make-local-variable 'comment-start-skip) | 124 (make-local-variable 'comment-start-skip) |
76 (setq comment-start-skip "\\\\\"[ \t]*") | 125 (setq comment-start-skip "\\\\\"[ \t]*") |
77 (make-local-variable 'comment-column) | 126 (make-local-variable 'comment-column) |
78 (setq comment-column 24) | 127 (setq comment-column 24) |
79 (make-local-variable 'comment-indent-function) | 128 (make-local-variable 'comment-indent-function) |
80 (setq comment-indent-function 'nroff-comment-indent) | 129 (setq comment-indent-function 'nroff-comment-indent) |
81 (run-hooks 'text-mode-hook 'nroff-mode-hook)) | 130 (run-hooks 'text-mode-hook 'nroff-mode-hook)) |
131 | |
132 (defun nroff-outline-level () | |
133 (save-excursion | |
134 (looking-at outline-regexp) | |
135 (skip-chars-forward ".H ") | |
136 (string-to-int (buffer-substring (point) (+ 1 (point)))))) | |
82 | 137 |
83 ;;; Compute how much to indent a comment in nroff/troff source. | 138 ;;; Compute how much to indent a comment in nroff/troff source. |
84 ;;; By mit-erl!gildea April 86 | 139 ;;; By mit-erl!gildea April 86 |
85 (defun nroff-comment-indent () | 140 (defun nroff-comment-indent () |
86 "Compute indent for an nroff/troff comment. | 141 "Compute indent for an nroff/troff comment. |