|
|
1.1 ! root 1: ;; Text mode, and its ideosyncratic commands. ! 2: ;; Copyright (C) 1985 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: (defvar text-mode-syntax-table nil ! 23: "Syntax table used while in text mode.") ! 24: ! 25: (defvar text-mode-abbrev-table nil ! 26: "Abbrev table used while in text mode.") ! 27: (define-abbrev-table 'text-mode-abbrev-table ()) ! 28: ! 29: (if text-mode-syntax-table ! 30: () ! 31: (setq text-mode-syntax-table (make-syntax-table)) ! 32: (modify-syntax-entry ?\" ". " text-mode-syntax-table) ! 33: (modify-syntax-entry ?\\ ". " text-mode-syntax-table) ! 34: (modify-syntax-entry ?' "w " text-mode-syntax-table)) ! 35: ! 36: (defvar text-mode-map nil "") ! 37: (if text-mode-map ! 38: () ! 39: (setq text-mode-map (make-sparse-keymap)) ! 40: (define-key text-mode-map "\t" 'tab-to-tab-stop) ! 41: (define-key text-mode-map "\es" 'center-line) ! 42: (define-key text-mode-map "\eS" 'center-paragraph)) ! 43: ! 44: ! 45: ;(defun non-saved-text-mode () ! 46: ; "Like text-mode, but delete auto save file when file is saved for real." ! 47: ; (text-mode) ! 48: ; (make-local-variable 'delete-auto-save-files) ! 49: ; (setq delete-auto-save-files t)) ! 50: ! 51: (defun text-mode () ! 52: "Major mode for editing text intended for humans to read. Special commands:\\{text-mode-map} ! 53: Turning on text-mode calls the value of the variable text-mode-hook, ! 54: if that value is non-nil." ! 55: (interactive) ! 56: (kill-all-local-variables) ! 57: (use-local-map text-mode-map) ! 58: (setq mode-name "Text") ! 59: (setq major-mode 'text-mode) ! 60: (setq local-abbrev-table text-mode-abbrev-table) ! 61: (set-syntax-table text-mode-syntax-table) ! 62: (run-hooks 'text-mode-hook)) ! 63: ! 64: (defvar indented-text-mode-map ()) ! 65: (if indented-text-mode-map ! 66: () ! 67: (setq indented-text-mode-map (make-sparse-keymap)) ! 68: (define-key indented-text-mode-map "\t" 'indent-relative) ! 69: (define-key indented-text-mode-map "\es" 'center-line) ! 70: (define-key indented-text-mode-map "\eS" 'center-paragraph)) ! 71: ! 72: (defun indented-text-mode () ! 73: "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map} ! 74: Turning on indented-text-mode calls the value of the variable text-mode-hook, ! 75: if that value is non-nil." ! 76: (interactive) ! 77: (kill-all-local-variables) ! 78: (use-local-map text-mode-map) ! 79: (define-abbrev-table 'text-mode-abbrev-table ()) ! 80: (setq local-abbrev-table text-mode-abbrev-table) ! 81: (set-syntax-table text-mode-syntax-table) ! 82: (make-local-variable 'indent-line-function) ! 83: (setq indent-line-function 'indent-relative-maybe) ! 84: (use-local-map indented-text-mode-map) ! 85: (setq mode-name "Indented Text") ! 86: (setq major-mode 'indented-text-mode) ! 87: (run-hooks 'text-mode-hook)) ! 88: ! 89: (defun center-paragraph () ! 90: "Center each line in the paragraph at or after point. ! 91: See center-line for more info." ! 92: (interactive) ! 93: (save-excursion ! 94: (forward-paragraph) ! 95: (or (bolp) (newline 1)) ! 96: (let ((end (point))) ! 97: (backward-paragraph) ! 98: (center-region (point) end)))) ! 99: ! 100: (defun center-region (from to) ! 101: "Center each line starting in the region. ! 102: See center-line for more info." ! 103: (interactive "r") ! 104: (if (> from to) ! 105: (let ((tem to)) ! 106: (setq to from from tem))) ! 107: (save-excursion ! 108: (save-restriction ! 109: (narrow-to-region from to) ! 110: (goto-char from) ! 111: (while (not (eobp)) ! 112: (center-line) ! 113: (forward-line 1))))) ! 114: ! 115: (defun center-line () ! 116: "Center the line point is on, within the width specified by `fill-column'. ! 117: This means adjusting the indentation to match ! 118: the distance between the end of the text and `fill-column'." ! 119: (interactive) ! 120: (save-excursion ! 121: (let (line-length) ! 122: (beginning-of-line) ! 123: (delete-horizontal-space) ! 124: (end-of-line) ! 125: (delete-horizontal-space) ! 126: (setq line-length (current-column)) ! 127: (beginning-of-line) ! 128: (indent-to ! 129: (+ left-margin ! 130: (/ (- fill-column left-margin line-length) 2))))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.