From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: Proposed changes to text-mode.el
Date: Sun, 31 Mar 2019 22:42:33 +0100 [thread overview]
Message-ID: <87bm1q90vq.fsf@tcd.ie> (raw)
In-Reply-To: <83ef6sl3tr.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 27 Mar 2019 17:44:32 +0200")
[-- 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: 4987 bytes --]
From 4c9950d015fdb520d29f04c6b1eb7418a442fc60 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: 2859 bytes --]
From 2e3deb09bd42d22a9b354937ce63b151fb493d8a Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Sun, 31 Mar 2019 19:39:54 +0100
Subject: [PATCH 2/3] Do not set indent-line-function in text-mode
For discussion, see thread starting at:
https://lists.gnu.org/archive/html/emacs-devel/2019-03/msg01012.html
* 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 | 9 +++++++++
lisp/textmodes/text-mode.el | 3 +--
3 files changed, 11 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 7486d6bcfe..89e07a2f4d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1371,6 +1371,15 @@ ending character were silently omitted.
For example, '(rx (any "@z-a" (?9 . ?0)))' would match '@' only.
Now, such rx expressions generate an error.
++++
+** '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
* Lisp Changes 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-Do-not-set-indent-line-function-in-text-mode.patch --]
[-- Type: text/x-diff, Size: 1574 bytes --]
From 63471c837dde50179f3c7bb6d316d61160e9e825 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] 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.
---
etc/NEWS | 5 +++++
lisp/textmodes/text-mode.el | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 89e07a2f4d..836dd2bb1a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1233,6 +1233,11 @@ 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-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: 494 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: "Basil L. Contovounesios" <contovob@tcd.ie>
>> Date: Wed, 27 Mar 2019 03:50:26 +0000
>> Cc: emacs-devel@gnu.org
>>
>> Thanks for the clarification and review.
>> I'll wait a few more days for others to comment before pushing.
>
> My only comment is that the NEWS item that describes an incompatible
> change should be in the section dedicated to incompatible changes.
I did so and pushed the three updated patches attached.
Thanks,
--
Basil
prev parent reply other threads:[~2019-03-31 21:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 1:34 Proposed changes to text-mode.el Basil L. Contovounesios
2019-03-26 13:00 ` 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 [this message]
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=87bm1q90vq.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).