Annotation of 43BSDReno/contrib/emacs-18.55/lisp/nroff-mode.el, revision 1.1

1.1     ! root        1: ;; GNU Emacs major mode for editing nroff source
        !             2: ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
        !             3: 
        !             4: ;; This file is part of GNU Emacs.
        !             5: 
        !             6: ;; GNU Emacs is distributed in the hope that it will be useful,
        !             7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
        !             8: ;; accepts responsibility to anyone for the consequences of using it
        !             9: ;; or for whether it serves any particular purpose or works at all,
        !            10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
        !            11: ;; License for full details.
        !            12: 
        !            13: ;; Everyone is granted permission to copy, modify and redistribute
        !            14: ;; GNU Emacs, but only under the conditions described in the
        !            15: ;; GNU Emacs General Public License.   A copy of this license is
        !            16: ;; supposed to have been given to you along with GNU Emacs so you
        !            17: ;; can know your rights and responsibilities.  It should be in a
        !            18: ;; file named COPYING.  Among other things, the copyright notice
        !            19: ;; and this notice must be preserved on all copies.
        !            20: 
        !            21: 
        !            22: 
        !            23: (defvar nroff-mode-abbrev-table nil
        !            24:   "Abbrev table used while in nroff mode.")
        !            25: 
        !            26: (defvar nroff-mode-map nil
        !            27:      "Major mode keymap for nroff-mode buffers")
        !            28: (if (not nroff-mode-map)
        !            29:     (progn
        !            30:       (setq nroff-mode-map (make-sparse-keymap))
        !            31:       (define-key nroff-mode-map "\t"  'tab-to-tab-stop)
        !            32:       (define-key nroff-mode-map "\es" 'center-line)
        !            33:       (define-key nroff-mode-map "\e?" 'count-text-lines)
        !            34:       (define-key nroff-mode-map "\n"  'electric-nroff-newline)
        !            35:       (define-key nroff-mode-map "\en" 'forward-text-line)
        !            36:       (define-key nroff-mode-map "\ep" 'backward-text-line)))
        !            37: 
        !            38: (defun nroff-mode ()
        !            39:   "Major mode for editing text intended for nroff to format.
        !            40: \\{nroff-mode-map}
        !            41: Turning on Nroff mode runs text-mode-hook, then nroff-mode-hook.
        !            42: Also, try nroff-electric-mode, for automatically inserting
        !            43: closing requests for requests that are used in matched pairs."
        !            44:   (interactive)
        !            45:   (kill-all-local-variables)
        !            46:   (use-local-map nroff-mode-map)
        !            47:   (setq mode-name "Nroff")
        !            48:   (setq major-mode 'nroff-mode)
        !            49:   (set-syntax-table text-mode-syntax-table)
        !            50:   (setq local-abbrev-table nroff-mode-abbrev-table)
        !            51:   (make-local-variable 'nroff-electric-mode)
        !            52:   ;; now define a bunch of variables for use by commands in this mode
        !            53:   (make-local-variable 'page-delimiter)
        !            54:   (setq page-delimiter "^\\.\\(bp\\|SK\\|OP\\)")
        !            55:   (make-local-variable 'paragraph-start)
        !            56:   (setq paragraph-start (concat "^[.']\\|" paragraph-start))
        !            57:   (make-local-variable 'paragraph-separate)
        !            58:   (setq paragraph-separate (concat "^[.']\\|" paragraph-separate))
        !            59:   ;; comment syntax added by mit-erl!gildea 18 Apr 86
        !            60:   (make-local-variable 'comment-start)
        !            61:   (setq comment-start "\\\" ")
        !            62:   (make-local-variable 'comment-start-skip)
        !            63:   (setq comment-start-skip "\\\\\"[ \t]*")
        !            64:   (make-local-variable 'comment-column)
        !            65:   (setq comment-column 24)
        !            66:   (make-local-variable 'comment-indent-hook)
        !            67:   (setq comment-indent-hook 'nroff-comment-indent)
        !            68:   (run-hooks 'text-mode-hook 'nroff-mode-hook))
        !            69: 
        !            70: ;;; Compute how much to indent a comment in nroff/troff source.
        !            71: ;;; By mit-erl!gildea April 86
        !            72: (defun nroff-comment-indent ()
        !            73:   "Compute indent for an nroff/troff comment.
        !            74: Puts a full-stop before comments on a line by themselves."
        !            75:   (let ((pt (point)))
        !            76:     (unwind-protect
        !            77:        (progn
        !            78:          (skip-chars-backward " \t")
        !            79:          (if (bolp)
        !            80:              (progn
        !            81:                (setq pt (1+ pt))
        !            82:                (insert ?.)
        !            83:                1)
        !            84:            (if (save-excursion
        !            85:                  (backward-char 1)
        !            86:                  (looking-at "^[.']"))
        !            87:                1
        !            88:              (max comment-column
        !            89:                   (* 8 (/ (+ (current-column)
        !            90:                              9) 8)))))) ; add 9 to ensure at least two blanks
        !            91:       (goto-char pt))))
        !            92: 
        !            93: (defun count-text-lines (start end &optional print)
        !            94:   "Count lines in region, except for nroff request lines.
        !            95: All lines not starting with a period are counted up.
        !            96: Interactively, print result in echo area.
        !            97: Noninteractively, return number of non-request lines from START to END."
        !            98:   (interactive "r\np")
        !            99:   (if print
        !           100:       (message "Region has %d text lines" (count-text-lines start end))
        !           101:     (save-excursion
        !           102:       (save-restriction
        !           103:        (narrow-to-region start end)
        !           104:        (goto-char (point-min))
        !           105:        (- (buffer-size) (forward-text-line (buffer-size)))))))
        !           106: 
        !           107: (defun forward-text-line (&optional cnt)
        !           108:   "Go forward one nroff text line, skipping lines of nroff requests.
        !           109: An argument is a repeat count; if negative, move backward."
        !           110:   (interactive "p")
        !           111:   (if (not cnt) (setq cnt 1))
        !           112:   (while (and (> cnt 0) (not (eobp)))
        !           113:     (forward-line 1)
        !           114:     (while (and (not (eobp)) (looking-at "[.']."))
        !           115:       (forward-line 1))
        !           116:     (setq cnt (- cnt 1)))
        !           117:   (while (and (< cnt 0) (not (bobp)))
        !           118:     (forward-line -1)
        !           119:     (while (and (not (bobp))
        !           120:                (looking-at "[.']."))
        !           121:       (forward-line -1))
        !           122:     (setq cnt (+ cnt 1)))
        !           123:   cnt)
        !           124: 
        !           125: (defun backward-text-line (&optional cnt)
        !           126:   "Go backward one nroff text line, skipping lines of nroff requests.
        !           127: An argument is a repeat count; negative means move forward."
        !           128:   (interactive "p")
        !           129:   (forward-text-line (- cnt)))
        !           130: 
        !           131: (defconst nroff-brace-table
        !           132:   '((".(b" . ".)b")
        !           133:     (".(l" . ".)l")
        !           134:     (".(q" . ".)q")
        !           135:     (".(c" . ".)c")
        !           136:     (".(x" . ".)x")
        !           137:     (".(z" . ".)z")
        !           138:     (".(d" . ".)d")
        !           139:     (".(f" . ".)f")
        !           140:     (".LG" . ".NL")
        !           141:     (".SM" . ".NL")
        !           142:     (".LD" . ".DE")
        !           143:     (".CD" . ".DE")
        !           144:     (".BD" . ".DE")
        !           145:     (".DS" . ".DE")
        !           146:     (".DF" . ".DE")
        !           147:     (".FS" . ".FE")
        !           148:     (".KS" . ".KE")
        !           149:     (".KF" . ".KE")
        !           150:     (".LB" . ".LE")
        !           151:     (".AL" . ".LE")
        !           152:     (".BL" . ".LE")
        !           153:     (".DL" . ".LE")
        !           154:     (".ML" . ".LE")
        !           155:     (".RL" . ".LE")
        !           156:     (".VL" . ".LE")
        !           157:     (".RS" . ".RE")
        !           158:     (".TS" . ".TE")
        !           159:     (".EQ" . ".EN")
        !           160:     (".PS" . ".PE")
        !           161:     (".BS" . ".BE")
        !           162:     (".G1" . ".G2")                    ; grap
        !           163:     (".na" . ".ad b")
        !           164:     (".nf" . ".fi")
        !           165:     (".de" . "..")))
        !           166: 
        !           167: (defun electric-nroff-newline (arg)
        !           168:   "Insert newline for nroff mode; special if electric-nroff mode.
        !           169: In electric-nroff-mode, if ending a line containing an nroff opening request,
        !           170: automatically inserts the matching closing request after point."
        !           171:   (interactive "P")
        !           172:   (let ((completion (save-excursion
        !           173:                      (beginning-of-line)
        !           174:                      (and (null arg)
        !           175:                           nroff-electric-mode
        !           176:                           (<= (point) (- (point-max) 3))
        !           177:                           (cdr (assoc (buffer-substring (point)
        !           178:                                                         (+ 3 (point)))
        !           179:                                       nroff-brace-table)))))
        !           180:        (needs-nl (not (looking-at "[ \t]*$"))))
        !           181:     (if (null completion)
        !           182:        (newline (prefix-numeric-value arg))
        !           183:       (save-excursion
        !           184:        (insert "\n\n" completion)
        !           185:        (if needs-nl (insert "\n")))
        !           186:       (forward-char 1))))
        !           187: 
        !           188: (defun electric-nroff-mode (&optional arg)
        !           189:   "Toggle nroff-electric-newline minor mode
        !           190: Nroff-electric-newline forces emacs to check for an nroff
        !           191: request at the beginning of the line, and insert the
        !           192: matching closing request if necessary.  
        !           193: This command toggles that mode (off->on, on->off), 
        !           194: with an argument, turns it on iff arg is positive, otherwise off."
        !           195:   (interactive "P")
        !           196:   (or (eq major-mode 'nroff-mode) (error "Must be in nroff mode"))
        !           197:   (or (assq 'nroff-electric-mode minor-mode-alist)
        !           198:       (setq minor-mode-alist (append minor-mode-alist
        !           199:                                     (list '(nroff-electric-mode
        !           200:                                             " Electric")))))
        !           201:   (setq nroff-electric-mode
        !           202:        (cond ((null arg) (null nroff-electric-mode))
        !           203:              (t (> (prefix-numeric-value arg) 0)))))
        !           204: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.