From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: <emacs-devel@gnu.org>
Subject: Proposed changes to text-mode.el
Date: Tue, 26 Mar 2019 01:34:22 +0000 [thread overview]
Message-ID: <87o95yxvtt.fsf@tcd.ie> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-Use-lexical-binding-in-text-mode.el.patch --]
[-- Type: text/x-diff, Size: 4988 bytes --]
From 36a7cded27791a26cc4979a1a27a6fa59d9a46f5 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Mon, 18 Mar 2019 23:45:55 +0000
Subject: [PATCH 1/3] 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.
---
doc/lispref/modes.texi | 7 +++----
lisp/textmodes/text-mode.el | 34 +++++++++++++++-------------------
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 1afbc5a5ce..7b64a56b19 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1291,10 +1291,9 @@ Example Major Modes
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
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 931faadb5b..90bb3eb3b5 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 @@ text-mode
(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 @@ paragraph-indent-minor-mode
: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 @@ 'indented-text-mode
(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 @@ toggle-text-mode-auto-fill
(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 @@ center-line
(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)
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Do-not-set-indent-line-function-in-text-mode.patch --]
[-- Type: text/x-diff, Size: 2779 bytes --]
From fa3f26d44c746fdf52520d18bded7e8b7987852a Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 26 Feb 2019 16:13:23 +0000
Subject: [PATCH 2/3] Do not set indent-line-function in text-mode
* lisp/textmodes/text-mode.el (text-mode): Do not reset
indent-line-function to its global default value of indent-relative.
* doc/lispref/modes.texi (Example Major Modes):
* etc/NEWS: Document change accordingly.
---
doc/lispref/modes.texi | 7 +------
etc/NEWS | 11 +++++++++++
lisp/textmodes/text-mode.el | 3 +--
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 7b64a56b19..4315b70ed7 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1292,15 +1292,10 @@ Example Major Modes
@end group
@group
(setq-local text-mode-variant t)
- (setq-local require-final-newline mode-require-final-newline)
- (setq-local indent-line-function #'indent-relative))
+ (setq-local require-final-newline mode-require-final-newline))
@end group
@end smallexample
-@noindent
-(The last line is redundant nowadays, since @code{indent-relative} is
-the default value, and we'll delete it in a future version.)
-
@cindex @file{lisp-mode.el}
The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp Interaction
mode) have more features than Text mode and the code is correspondingly
diff --git a/etc/NEWS b/etc/NEWS
index afee1e1dca..69af0447b2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1233,6 +1233,17 @@ near the current column in Tabulated Lists (see variables
'tabulated-list-tty-sort-indicator-asc', and
'tabulated-list-tty-sort-indicator-desc').
+** Text mode
+
++++
+*** 'text-mode' no longer sets the value of 'indent-line-function'.
+The global value of 'indent-line-function', which defaults to
+'indent-relative', will no longer be reset locally when turning on
+'text-mode'.
+
+To get back the old behavior, add a function to 'text-mode-hook' which
+performs (setq-local indent-line-function #'indent-relative).
+
\f
* New Modes and Packages in Emacs 27.1
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 90bb3eb3b5..6114490208 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -105,8 +105,7 @@ text-mode
\\{text-mode-map}
Turning on Text mode runs the normal hook `text-mode-hook'."
(setq-local text-mode-variant t)
- (setq-local require-final-newline mode-require-final-newline)
- (setq-local indent-line-function #'indent-relative))
+ (setq-local require-final-newline mode-require-final-newline))
(define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
"Major mode for editing text, with leading spaces starting a paragraph.
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0003-Make-text-mode-variant-obsolete.patch --]
[-- Type: text/x-diff, Size: 1529 bytes --]
From 1bc70af0bca2d1cb9e6d8799748bf5c262b9a5eb Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Mon, 25 Mar 2019 23:10:59 +0000
Subject: [PATCH 3/3] Make text-mode-variant obsolete
* lisp/textmodes/text-mode.el (text-mode-variant): Make obsolete,
suggesting derived-mode-p as a better alternative.
* etc/NEWS: Announce obsolescence.
---
etc/NEWS | 3 +++
lisp/textmodes/text-mode.el | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 69af0447b2..f3d09bc3dc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1244,6 +1244,9 @@ The global value of 'indent-line-function', which defaults to
To get back the old behavior, add a function to 'text-mode-hook' which
performs (setq-local indent-line-function #'indent-relative).
++++
+*** 'text-mode-variant' is now obsolete, use 'derived-mode-p' instead.
+
\f
* New Modes and Packages in Emacs 27.1
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 6114490208..e676a5dae2 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -38,8 +38,8 @@ text-mode-hook
:group 'text)
(defvar text-mode-variant nil
- "Non-nil if this buffer's major mode is a variant of Text mode.
-Use (derived-mode-p \\='text-mode) instead.")
+ "Non-nil if this buffer's major mode is a variant of Text mode.")
+(make-obsolete-variable 'text-mode-variant 'derived-mode-p "27.1")
(defvar text-mode-syntax-table
(let ((st (make-syntax-table)))
--
2.20.1
[-- Attachment #4: Type: text/plain, Size: 941 bytes --]
I attach three patches for lisp/textmodes/text-mode.el arising from the
discussion in bug#34671.
The first enables lexical-binding and makes some minor simplifications.
The second makes text-mode no longer reset indent-line-function to
indent-relative locally, a change (info "(elisp) Example Major Modes")
has been promising for many moons. AFAICT, text-mode works even when
indent-line-function is not set to indent-relative (as I'd hope). I've
had a quick look through all the modes derived from text-mode in
emacs.git and nothing strikes me as an obvious incompatibility with the
proposed change. Are there any significant reasons to keep the current
setting of indent-line-function in text-mode?
The third obsoletes the variable text-mode-variant, which is unused in
both emacs.git and elpa.git, and has been recommending derived-mode-p as
a better alternative in its docstring for almost two decades.
WDYT?
Thanks,
--
Basil
next reply other threads:[~2019-03-26 1:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 1:34 Basil L. Contovounesios [this message]
2019-03-26 13:00 ` Proposed changes to text-mode.el Stefan Monnier
2019-03-27 3:50 ` Basil L. Contovounesios
2019-03-27 15:44 ` Eli Zaretskii
2019-03-31 21:42 ` Basil L. Contovounesios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o95yxvtt.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).