|
|
1.1 ! root 1: ;; Copyright (C) 1985 N. Ziring and Richard M. Stallman. ! 2: ! 3: ;; This file is part of GNU Emacs. ! 4: ! 5: ;; GNU Emacs is distributed in the hope that it will be useful, ! 6: ;; but WITHOUT ANY WARRANTY. No author or distributor ! 7: ;; accepts responsibility to anyone for the consequences of using it ! 8: ;; or for whether it serves any particular purpose or works at all, ! 9: ;; unless he says so in writing. Refer to the GNU Emacs General Public ! 10: ;; License for full details. ! 11: ! 12: ;; Everyone is granted permission to copy, modify and redistribute ! 13: ;; GNU Emacs, but only under the conditions described in the ! 14: ;; GNU Emacs General Public License. A copy of this license is ! 15: ;; supposed to have been given to you along with GNU Emacs so you ! 16: ;; can know your rights and responsibilities. It should be in a ! 17: ;; file named COPYING. Among other things, the copyright notice ! 18: ;; and this notice must be preserved on all copies. ! 19: ! 20: ! 21: ;; GNU Emacs major mode for editing nroff source ! 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") ! 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: (run-hooks 'text-mode-hook 'nroff-mode-hook)) ! 60: ! 61: (defun count-text-lines (start end &optional print) ! 62: "Count lines in region, except for nroff request lines. ! 63: All lines not starting with a period are counted up. ! 64: Interactively, print result in echo area. ! 65: Noninteractively, return number of non-request lines from START to END." ! 66: (interactive "r\np") ! 67: (if print ! 68: (message "Region has %d text lines" (count-text-lines start end)) ! 69: (save-excursion ! 70: (save-restriction ! 71: (narrow-to-region start end) ! 72: (goto-char (point-min)) ! 73: (- (buffer-size) (forward-text-line (buffer-size))))))) ! 74: ! 75: (defun forward-text-line (&optional cnt) ! 76: "Go forward one nroff text line, skipping lines of nroff requests. ! 77: An argument is a repeat count; if negative, move backward." ! 78: (interactive "p") ! 79: (if (not cnt) (setq cnt 1)) ! 80: (while (and (> cnt 0) (not (eobp))) ! 81: (forward-line 1) ! 82: (while (and (not (eobp)) (looking-at "\\..")) ! 83: (forward-line 1)) ! 84: (setq cnt (- cnt 1))) ! 85: (while (and (< cnt 0) (not (bobp))) ! 86: (forward-line -1) ! 87: (while (and (not (bobp)) ! 88: (looking-at "\\..")) ! 89: (forward-line -1)) ! 90: (setq cnt (+ cnt 1))) ! 91: cnt) ! 92: ! 93: (defun backward-text-line (&optional cnt) ! 94: "Go backward one nroff text line, skipping lines of nroff requests. ! 95: An argument is a repeat count; negative means move forward." ! 96: (interactive "p") ! 97: (forward-text-line (- cnt))) ! 98: ! 99: (defconst nroff-brace-table ! 100: '((".(b" . ".)b") ! 101: (".(l" . ".)l") ! 102: (".(q" . ".)q") ! 103: (".(c" . ".)c") ! 104: (".(x" . ".)x") ! 105: (".(z" . ".)z") ! 106: (".(d" . ".)d") ! 107: (".(f" . ".)f") ! 108: (".DS" . ".DE") ! 109: (".KS" . ".KE") ! 110: (".de" . ".."))) ! 111: ! 112: (defun electric-nroff-newline (arg) ! 113: "Insert newline for nroff mode; special if electric-nroff mode. ! 114: In electric-nroff-mode, if ending a line containing an nroff opening request, ! 115: automatically inserts the matching closing request after point." ! 116: (interactive "P") ! 117: (let ((completion (save-excursion ! 118: (beginning-of-line) ! 119: (and (null arg) ! 120: nroff-electric-mode ! 121: (<= (point) (- (point-max) 3)) ! 122: (cdr (assoc (buffer-substring (point) ! 123: (+ 3 (point))) ! 124: nroff-brace-table)))))) ! 125: (if (null completion) ! 126: (newline (prefix-numeric-value arg)) ! 127: (insert "\n" completion "\n")))) ! 128: ! 129: (defun electric-nroff-mode (arg) ! 130: "Toggle nroff-electric-newline minor mode ! 131: Nroff-electric-newline forces emacs to check for an nroff ! 132: request at the beginning of the line, and insert the ! 133: matching closing request if necessary. ! 134: This command toggles that mode (off->on, on->off), ! 135: with an argument, turns it on iff arg is positive, otherwise off." ! 136: (interactive "P") ! 137: (setq nroff-electric-mode ! 138: (cond ! 139: ((null arg) (null nroff-electric-mode)) ! 140: (t (> (prefix-numeric-value arg) 0)))) ! 141: (set-minor-mode 'electric-nroff-mode "electric" nroff-electric-mode)) ! 142:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.