aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasil L. Contovounesios2019-03-18 23:45:55 +0000
committerBasil L. Contovounesios2019-03-31 22:27:21 +0100
commit4c9950d015fdb520d29f04c6b1eb7418a442fc60 (patch)
tree209c3f339546ea11ad206abf91622e2938ba1d5d
parent07d7852b00dc0c91f2450856ac27c17eea7a3e1a (diff)
downloademacs-4c9950d015fdb520d29f04c6b1eb7418a442fc60.tar.gz
emacs-4c9950d015fdb520d29f04c6b1eb7418a442fc60.zip
Use lexical-binding in text-mode.el
* lisp/textmodes/text-mode.el: Use lexical-binding. (text-mode, paragraph-indent-minor-mode, text-mode-hook-identify): Use setq-local. (toggle-text-mode-auto-fill): Quote function symbols as such. (center-line): Minor simplification. * doc/lispref/modes.texi (Example Major Modes): Update code example for these changes to text-mode.
-rw-r--r--doc/lispref/modes.texi7
-rw-r--r--lisp/textmodes/text-mode.el34
2 files changed, 18 insertions, 23 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 1afbc5a5cee..7b64a56b199 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1291,10 +1291,9 @@ You can thus get the full benefit of adaptive filling
1291Turning on Text mode runs the normal hook `text-mode-hook'." 1291Turning on Text mode runs the normal hook `text-mode-hook'."
1292@end group 1292@end group
1293@group 1293@group
1294 (set (make-local-variable 'text-mode-variant) t) 1294 (setq-local text-mode-variant t)
1295 (set (make-local-variable 'require-final-newline) 1295 (setq-local require-final-newline mode-require-final-newline)
1296 mode-require-final-newline) 1296 (setq-local indent-line-function #'indent-relative))
1297 (set (make-local-variable 'indent-line-function) 'indent-relative))
1298@end group 1297@end group
1299@end smallexample 1298@end smallexample
1300 1299
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 931faadb5bb..90bb3eb3b53 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -1,4 +1,4 @@
1;;; text-mode.el --- text mode, and its idiosyncratic commands 1;;; text-mode.el --- text mode, and its idiosyncratic commands -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1985, 1992, 1994, 2001-2019 Free Software Foundation, 3;; Copyright (C) 1985, 1992, 1994, 2001-2019 Free Software Foundation,
4;; Inc. 4;; Inc.
@@ -104,10 +104,9 @@ You can thus get the full benefit of adaptive filling
104 (see the variable `adaptive-fill-mode'). 104 (see the variable `adaptive-fill-mode').
105\\{text-mode-map} 105\\{text-mode-map}
106Turning on Text mode runs the normal hook `text-mode-hook'." 106Turning on Text mode runs the normal hook `text-mode-hook'."
107 (set (make-local-variable 'text-mode-variant) t) 107 (setq-local text-mode-variant t)
108 (set (make-local-variable 'require-final-newline) 108 (setq-local require-final-newline mode-require-final-newline)
109 mode-require-final-newline) 109 (setq-local indent-line-function #'indent-relative))
110 (set (make-local-variable 'indent-line-function) 'indent-relative))
111 110
112(define-derived-mode paragraph-indent-text-mode text-mode "Parindent" 111(define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
113 "Major mode for editing text, with leading spaces starting a paragraph. 112 "Major mode for editing text, with leading spaces starting a paragraph.
@@ -131,14 +130,12 @@ Turning on Paragraph-Indent minor mode runs the normal hook
131 :initial-value nil 130 :initial-value nil
132 ;; Change the definition of a paragraph start. 131 ;; Change the definition of a paragraph start.
133 (let ((ps-re "[ \t\n\f]\\|")) 132 (let ((ps-re "[ \t\n\f]\\|"))
134 (if (eq t (compare-strings ps-re nil nil 133 (if (string-prefix-p ps-re paragraph-start)
135 paragraph-start nil (length ps-re)))
136 (if (not paragraph-indent-minor-mode) 134 (if (not paragraph-indent-minor-mode)
137 (set (make-local-variable 'paragraph-start) 135 (setq-local paragraph-start
138 (substring paragraph-start (length ps-re)))) 136 (substring paragraph-start (length ps-re))))
139 (if paragraph-indent-minor-mode 137 (if paragraph-indent-minor-mode
140 (set (make-local-variable 'paragraph-start) 138 (setq-local paragraph-start (concat ps-re paragraph-start)))))
141 (concat ps-re paragraph-start)))))
142 ;; Change the indentation function. 139 ;; Change the indentation function.
143 (if paragraph-indent-minor-mode 140 (if paragraph-indent-minor-mode
144 (add-function :override (local 'indent-line-function) 141 (add-function :override (local 'indent-line-function)
@@ -154,7 +151,7 @@ Turning on Paragraph-Indent minor mode runs the normal hook
154(defun text-mode-hook-identify () 151(defun text-mode-hook-identify ()
155 "Mark that this mode has run `text-mode-hook'. 152 "Mark that this mode has run `text-mode-hook'.
156This is how `toggle-text-mode-auto-fill' knows which buffers to operate on." 153This is how `toggle-text-mode-auto-fill' knows which buffers to operate on."
157 (set (make-local-variable 'text-mode-variant) t)) 154 (setq-local text-mode-variant t))
158 155
159(defun toggle-text-mode-auto-fill () 156(defun toggle-text-mode-auto-fill ()
160 "Toggle whether to use Auto Fill in Text mode and related modes. 157 "Toggle whether to use Auto Fill in Text mode and related modes.
@@ -163,8 +160,8 @@ both existing buffers and buffers that you subsequently create."
163 (interactive) 160 (interactive)
164 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook)))) 161 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))))
165 (if enable-mode 162 (if enable-mode
166 (add-hook 'text-mode-hook 'turn-on-auto-fill) 163 (add-hook 'text-mode-hook #'turn-on-auto-fill)
167 (remove-hook 'text-mode-hook 'turn-on-auto-fill)) 164 (remove-hook 'text-mode-hook #'turn-on-auto-fill))
168 (dolist (buffer (buffer-list)) 165 (dolist (buffer (buffer-list))
169 (with-current-buffer buffer 166 (with-current-buffer buffer
170 (if (or (derived-mode-p 'text-mode) text-mode-variant) 167 (if (or (derived-mode-p 'text-mode) text-mode-variant)
@@ -214,15 +211,14 @@ The argument NLINES says how many lines to center."
214 (while (not (eq nlines 0)) 211 (while (not (eq nlines 0))
215 (save-excursion 212 (save-excursion
216 (let ((lm (current-left-margin)) 213 (let ((lm (current-left-margin))
217 line-length) 214 space)
218 (beginning-of-line) 215 (beginning-of-line)
219 (delete-horizontal-space) 216 (delete-horizontal-space)
220 (end-of-line) 217 (end-of-line)
221 (delete-horizontal-space) 218 (delete-horizontal-space)
222 (setq line-length (current-column)) 219 (setq space (- fill-column lm (current-column)))
223 (if (> (- fill-column lm line-length) 0) 220 (if (> space 0)
224 (indent-line-to 221 (indent-line-to (+ lm (/ space 2))))))
225 (+ lm (/ (- fill-column lm line-length) 2))))))
226 (cond ((null nlines) 222 (cond ((null nlines)
227 (setq nlines 0)) 223 (setq nlines 0))
228 ((> nlines 0) 224 ((> nlines 0)