Mercurial > hg > xemacs-beta
annotate lisp/text-mode.el @ 5560:58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
src/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* alloc.c:
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT_1):
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT):
* alloc.c (cons_print_preprocess):
* alloc.c (vector_print_preprocess):
* alloc.c (vector_nsubst_structures_descend):
* alloc.c (Fmake_symbol):
* alloc.c (UNMARK_symbol):
* alloc.c (sweep_symbols):
* alloc.c (reinit_alloc_objects_early):
* alloc.c (reinit_alloc_early):
* bytecode.c:
* bytecode.c (compiled_function_print_preprocess):
* bytecode.c (compiled_function_nsubst_structures_descend):
* bytecode.c (set_compiled_function_arglist):
* bytecode.c (set_compiled_function_interactive):
* bytecode.c (bytecode_objects_create):
* chartab.c:
* chartab.c (print_preprocess_mapper):
* chartab.c (nsubst_structures_mapper):
* chartab.c (char_table_nsubst_structures_descend):
* chartab.c (chartab_objects_create):
* elhash.c:
* elhash.c (nsubst_structures_map_hash_table):
* elhash.c (hash_table_nsubst_structures_descend):
* elhash.c (print_preprocess_mapper):
* elhash.c (hash_table_print_preprocess):
* elhash.c (inchash_eq):
* elhash.c (hash_table_objects_create):
* elhash.c (syms_of_elhash):
* elhash.h:
* emacs.c (main_1):
* fns.c:
* fns.c (check_eq_nokey):
* fns.c (Fnsubst):
* fns.c (syms_of_fns):
* lisp.h:
* lisp.h (struct Lisp_Symbol):
* lisp.h (IN_OBARRAY):
* lisp.h (struct):
* lisp.h (PRINT_PREPROCESS):
* lread.c (read1):
* lrecord.h:
* lrecord.h (struct lrecord_implementation):
* lrecord.h (DEFINE_DUMPABLE_MODULE_LISP_OBJECT):
* print.c:
* print.c (PRINT_CIRCLE_LIMIT):
* print.c (print_continuous_numbering_changed):
* print.c (print_prepare):
* print.c (print_finish):
* print.c (Fprin1_to_string):
* print.c (print_cons):
* print.c (print_preprocess_inchash_eq):
* print.c (print_preprocess):
* print.c (print_sort_get_numbers):
* print.c (print_sort_compare_ordinals):
* print.c (print_gensym_or_circle):
* print.c (nsubst_structures_descend):
* print.c (nsubst_structures):
* print.c (print_internal):
* print.c (print_symbol):
* print.c (vars_of_print):
* rangetab.c:
* rangetab.c (range_table_print_preprocess):
* rangetab.c (range_table_nsubst_structures_descend):
* rangetab.c (rangetab_objects_create):
* rangetab.c (syms_of_rangetab):
* symbols.c:
* symbols.c (symbol_print_preprocess):
* symbols.c (Fintern):
* symbols.c (Funintern):
* symbols.c (reinit_symbol_objects_early):
* symbols.c (init_symbols_once_early):
* symsinit.h:
Implement print-circle, printing circular structures in a readable
fashion, and treating them appropriately on read. This is by means
of two new object methods, print_preprocess (detecting
circularities), and nsubst_structures_descend (replacing
placeholders with the read objects).
Expose the substitution to Lisp via #'nsubst and its new
:descend-structures keyword.
Store information as to whether symbols are interned in obarray or
not in their header, making checking for keywords and uninterned
symbols (and thus printing) cheaper.
Default print_gensym to t, as Common Lisp does, and as a
more-than-decade old comment suggests.
lisp/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-output-file-form):
* bytecomp.el (byte-compile-output-docform):
Bind print-circle, print-continuous-numbering in these functions,
now those variables are available.
* lisp.el (forward-sexp):
* lisp.el (backward-sexp):
Recognise leading #N= as being part of an expression.
tests/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-reader-tests.el:
* automated/lisp-tests.el (literal-with-uninterned):
* automated/symbol-tests.el (foo):
Test print-circle, for printing (mutually-)recursive and circular
structures.
Bind print-continuous-numbering where appropriate.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sun, 04 Sep 2011 19:51:35 +0100 |
| parents | 308d34e9f07d |
| children | 182d01410b8d |
| rev | line source |
|---|---|
| 428 | 1 ;;; text-mode.el --- text mode, and its idiosyncratic commands. |
| 2 | |
| 3 ;; Copyright (C) 1985, 1992, 1994, 1997 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Maintainer: FSF | |
| 6 ;; Keywords: wp, dumped | |
| 7 | |
| 8 ;; This file is part of XEmacs. | |
| 9 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
13 ;; option) any later version. |
| 428 | 14 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
18 ;; for more details. |
| 428 | 19 |
| 20 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 428 | 22 |
| 23 ;;; Synched up with: FSF 20.2. | |
| 24 | |
| 25 ;;; Commentary: | |
| 26 | |
| 27 ;; This file is dumped with XEmacs. | |
| 28 | |
| 29 ;; This package provides the fundamental text mode documented in the | |
| 30 ;; Emacs user's manual. | |
| 31 | |
| 32 ;;; Code: | |
| 33 | |
| 34 (defvar text-mode-hook nil | |
| 35 "Normal hook run when entering Text mode and many related modes.") | |
| 36 | |
| 37 (defvar text-mode-variant nil | |
| 38 "Non-nil if this buffer's major mode is a variant of Text mode.") | |
| 39 | |
| 40 (defvar text-mode-syntax-table nil | |
| 41 "Syntax table used while in text mode.") | |
| 42 | |
| 43 (defvar text-mode-abbrev-table nil | |
| 44 "Abbrev table used while in text mode.") | |
| 45 (define-abbrev-table 'text-mode-abbrev-table ()) | |
| 46 | |
| 47 (if text-mode-syntax-table | |
| 48 () | |
| 49 (setq text-mode-syntax-table (make-syntax-table)) | |
| 50 (modify-syntax-entry ?\" ". " text-mode-syntax-table) | |
| 51 (modify-syntax-entry ?\\ ". " text-mode-syntax-table) | |
| 52 (modify-syntax-entry ?' "w " text-mode-syntax-table)) | |
| 53 | |
| 54 (defvar text-mode-map nil | |
| 55 "Keymap for Text mode. | |
| 56 Many other modes, such as Mail mode, Outline mode and Indented Text mode, | |
| 57 inherit all the commands defined in this map.") | |
| 58 | |
| 59 (if text-mode-map | |
| 60 () | |
| 61 (setq text-mode-map (make-sparse-keymap)) | |
| 62 ;; XEmacs change | |
| 63 (set-keymap-name text-mode-map 'text-mode-map) | |
| 64 (define-key text-mode-map "\e\t" 'ispell-complete-word) | |
| 65 (define-key text-mode-map "\t" 'indent-relative) | |
| 66 (define-key text-mode-map "\es" 'center-line) | |
| 67 (define-key text-mode-map "\eS" 'center-paragraph)) | |
| 68 | |
| 69 | |
| 70 (defun text-mode () | |
| 71 "Major mode for editing text written for humans to read. | |
| 72 In this mode, paragraphs are delimited only by blank or white lines. | |
| 73 You can thus get the full benefit of adaptive filling | |
| 74 (see the variable `adaptive-fill-mode'). | |
| 75 \\{text-mode-map} | |
| 76 Turning on Text mode runs the normal hook `text-mode-hook'." | |
| 77 (interactive) | |
| 78 (kill-all-local-variables) | |
| 79 (use-local-map text-mode-map) | |
| 80 (setq local-abbrev-table text-mode-abbrev-table) | |
| 81 (set-syntax-table text-mode-syntax-table) | |
| 82 (make-local-variable 'paragraph-start) | |
| 83 (setq paragraph-start (concat page-delimiter "\\|[ \t]*$")) | |
| 84 (make-local-variable 'paragraph-separate) | |
| 85 (setq paragraph-separate paragraph-start) | |
| 86 (setq mode-name "Text") | |
| 87 (setq major-mode 'text-mode) | |
| 88 (run-hooks 'text-mode-hook)) | |
| 89 | |
| 90 (defun paragraph-indent-text-mode () | |
| 91 "Major mode for editing text, with leading spaces starting a paragraph. | |
| 92 In this mode, you do not need blank lines between paragraphs | |
| 93 when the first line of the following paragraph starts with whitespace. | |
| 94 Special commands: | |
| 95 \\{text-mode-map} | |
| 96 Turning on Paragraph-Indent Text mode runs the normal hooks | |
| 97 `text-mode-hook' and `paragraph-indent-text-mode-hook'." | |
| 98 (interactive) | |
| 99 (kill-all-local-variables) | |
| 100 (use-local-map text-mode-map) | |
| 101 (setq mode-name "Parindent") | |
| 102 (setq major-mode 'paragraph-indent-text-mode) | |
| 103 (setq local-abbrev-table text-mode-abbrev-table) | |
| 104 (set-syntax-table text-mode-syntax-table) | |
| 105 (run-hooks 'text-mode-hook 'paragraph-indent-text-mode-hook)) | |
| 106 | |
| 107 (defalias 'indented-text-mode 'text-mode) | |
| 108 | |
| 109 (defun text-mode-hook-identify () | |
| 110 "Mark that this mode has run `text-mode-hook'. | |
| 111 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on." | |
| 112 (make-local-variable 'text-mode-variant) | |
| 113 (setq text-mode-variant t)) | |
| 114 | |
| 115 (add-hook 'text-mode-hook 'text-mode-hook-identify) | |
| 116 | |
| 117 (defun toggle-text-mode-auto-fill () | |
| 118 "Toggle whether to use Auto Fill in Text mode and related modes. | |
| 119 This command affects all buffers that use modes related to Text mode, | |
| 120 both existing buffers and buffers that you subsequently create." | |
| 121 (interactive) | |
| 122 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))) | |
| 123 (buffers (buffer-list))) | |
| 124 (if enable-mode | |
| 125 (add-hook 'text-mode-hook 'turn-on-auto-fill) | |
| 126 (remove-hook 'text-mode-hook 'turn-on-auto-fill)) | |
| 127 (while buffers | |
| 128 (with-current-buffer (car buffers) | |
| 129 (if text-mode-variant | |
| 130 (auto-fill-mode (if enable-mode 1 0)))) | |
| 131 (setq buffers (cdr buffers))) | |
| 132 (message "Auto Fill %s in Text modes" | |
| 133 (if enable-mode "enabled" "disabled")))) | |
| 134 | |
| 135 (defun center-paragraph () | |
| 136 "Center each nonblank line in the paragraph at or after point. | |
| 137 See `center-line' for more info." | |
| 138 (interactive) | |
| 139 (save-excursion | |
| 140 (forward-paragraph) | |
| 141 (or (bolp) (newline 1)) | |
| 142 (let ((end (point))) | |
| 143 (backward-paragraph) | |
| 144 (center-region (point) end)))) | |
| 145 | |
| 146 (defun center-region (from to) | |
| 147 "Center each nonblank line starting in the region. | |
| 148 See `center-line' for more info." | |
| 149 (interactive "r") | |
| 150 (if (> from to) | |
| 151 (let ((tem to)) | |
| 152 (setq to from from tem))) | |
| 153 (save-excursion | |
| 154 (save-restriction | |
| 155 (narrow-to-region from to) | |
| 156 (goto-char from) | |
| 157 (while (not (eobp)) | |
| 158 (or (save-excursion (skip-chars-forward " \t") (eolp)) | |
| 159 (center-line)) | |
| 160 (forward-line 1))))) | |
| 161 | |
| 162 (defun center-line (&optional nlines) | |
| 163 "Center the line point is on, within the width specified by `fill-column'. | |
| 164 This means adjusting the indentation so that it equals | |
| 165 the distance between the end of the text and `fill-column'. | |
| 166 The argument NLINES says how many lines to center." | |
| 167 (interactive "P") | |
| 168 (if nlines (setq nlines (prefix-numeric-value nlines))) | |
| 169 (while (not (eq nlines 0)) | |
| 170 (save-excursion | |
| 171 (let ((lm (current-left-margin)) | |
| 172 line-length) | |
| 173 (beginning-of-line) | |
| 174 (delete-horizontal-space) | |
| 175 (end-of-line) | |
| 176 (delete-horizontal-space) | |
| 177 (setq line-length (current-column)) | |
| 178 (if (> (- fill-column lm line-length) 0) | |
| 179 (indent-line-to | |
| 180 (+ lm (/ (- fill-column lm line-length) 2)))))) | |
| 181 (cond ((null nlines) | |
| 182 (setq nlines 0)) | |
| 183 ((> nlines 0) | |
| 184 (setq nlines (1- nlines)) | |
| 185 (forward-line 1)) | |
| 186 ((< nlines 0) | |
| 187 (setq nlines (1+ nlines)) | |
| 188 (forward-line -1))))) | |
| 189 | |
| 190 ;;; text-mode.el ends here |
