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.
parent 07d7852b
......@@ -1291,10 +1291,9 @@ You can thus get the full benefit of adaptive filling
Turning on Text mode runs the normal hook `text-mode-hook'."
@end group
@group
(set (make-local-variable 'text-mode-variant) t)
(set (make-local-variable 'require-final-newline)
mode-require-final-newline)
(set (make-local-variable 'indent-line-function) 'indent-relative))
(setq-local text-mode-variant t)
(setq-local require-final-newline mode-require-final-newline)
(setq-local indent-line-function #'indent-relative))
@end group
@end smallexample
......
;;; text-mode.el --- text mode, and its idiosyncratic commands
;;; text-mode.el --- text mode, and its idiosyncratic commands -*- lexical-binding: t -*-
;; Copyright (C) 1985, 1992, 1994, 2001-2019 Free Software Foundation,
;; Inc.
......@@ -104,10 +104,9 @@ You can thus get the full benefit of adaptive filling
(see the variable `adaptive-fill-mode').
\\{text-mode-map}
Turning on Text mode runs the normal hook `text-mode-hook'."
(set (make-local-variable 'text-mode-variant) t)
(set (make-local-variable 'require-final-newline)
mode-require-final-newline)
(set (make-local-variable 'indent-line-function) 'indent-relative))
(setq-local text-mode-variant t)
(setq-local require-final-newline mode-require-final-newline)
(setq-local indent-line-function #'indent-relative))
(define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
"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
:initial-value nil
;; Change the definition of a paragraph start.
(let ((ps-re "[ \t\n\f]\\|"))
(if (eq t (compare-strings ps-re nil nil
paragraph-start nil (length ps-re)))
(if (string-prefix-p ps-re paragraph-start)
(if (not paragraph-indent-minor-mode)
(set (make-local-variable 'paragraph-start)
(substring paragraph-start (length ps-re))))
(setq-local paragraph-start
(substring paragraph-start (length ps-re))))
(if paragraph-indent-minor-mode
(set (make-local-variable 'paragraph-start)
(concat ps-re paragraph-start)))))
(setq-local paragraph-start (concat ps-re paragraph-start)))))
;; Change the indentation function.
(if paragraph-indent-minor-mode
(add-function :override (local 'indent-line-function)
......@@ -154,7 +151,7 @@ Turning on Paragraph-Indent minor mode runs the normal hook
(defun text-mode-hook-identify ()
"Mark that this mode has run `text-mode-hook'.
This is how `toggle-text-mode-auto-fill' knows which buffers to operate on."
(set (make-local-variable 'text-mode-variant) t))
(setq-local text-mode-variant t))
(defun toggle-text-mode-auto-fill ()
"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."
(interactive)
(let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))))
(if enable-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(remove-hook 'text-mode-hook 'turn-on-auto-fill))
(add-hook 'text-mode-hook #'turn-on-auto-fill)
(remove-hook 'text-mode-hook #'turn-on-auto-fill))
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(if (or (derived-mode-p 'text-mode) text-mode-variant)
......@@ -214,15 +211,14 @@ The argument NLINES says how many lines to center."
(while (not (eq nlines 0))
(save-excursion
(let ((lm (current-left-margin))
line-length)
space)
(beginning-of-line)
(delete-horizontal-space)
(end-of-line)
(delete-horizontal-space)
(setq line-length (current-column))
(if (> (- fill-column lm line-length) 0)
(indent-line-to
(+ lm (/ (- fill-column lm line-length) 2))))))
(setq space (- fill-column lm (current-column)))
(if (> space 0)
(indent-line-to (+ lm (/ space 2))))))
(cond ((null nlines)
(setq nlines 0))
((> nlines 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment