summaryrefslogtreecommitdiff
path: root/lisp/textmodes/text-mode.el
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2019-03-18 23:45:55 +0000
committerBasil L. Contovounesios <contovob@tcd.ie>2019-03-31 22:27:21 +0100
commit4c9950d015fdb520d29f04c6b1eb7418a442fc60 (patch)
tree209c3f339546ea11ad206abf91622e2938ba1d5d /lisp/textmodes/text-mode.el
parent07d7852b00dc0c91f2450856ac27c17eea7a3e1a (diff)
downloademacs-4c9950d015fdb520d29f04c6b1eb7418a442fc60.tar.gz
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.
Diffstat (limited to 'lisp/textmodes/text-mode.el')
-rw-r--r--lisp/textmodes/text-mode.el34
1 files changed, 15 insertions, 19 deletions
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 @@
-;;; 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)