GNU bug report logs -
#67848
29.1; Fix usage of `setq-default' and add explanation
Previous Next
Reported by: Xiyue Deng <manphiz <at> gmail.com>
Date: Sat, 16 Dec 2023 11:19:01 UTC
Severity: normal
Tags: patch
Found in version 29.1
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[0001-Fix-usage-of-setq-default-and-add-explanation-bug-67.patch (text/x-diff, attachment)]
From 197467583063492dee7bc2fc40709ecb3a3d17e9 Mon Sep 17 00:00:00 2001
From: Xiyue Deng <manphiz <at> gmail.com>
Date: Sat, 16 Dec 2023 02:06:15 -0800
Subject: [PATCH] Fix usage of `setq-default' and add explanation (bug#67848)
cd61af0 changed from default-major-mode to major-mode in the first
code sample but didn't change the rest. Fix it here and add some
explanations of why use `setq-default' instead of `setq'.
* doc/lispintro/emacs-lisp-intro.texi (Text and Auto-fill): fix `setq'
to `setq-default' and add some explanations.
---
doc/lispintro/emacs-lisp-intro.texi | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index eb8ff413b79..2468571eb96 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -16943,14 +16943,19 @@ Here is the line again; how does it work?
@cindex Text Mode turned on
@smallexample
-(setq major-mode 'text-mode)
+(setq-default major-mode 'text-mode)
@end smallexample
@noindent
This line is a short, but complete Emacs Lisp expression.
-We are already familiar with @code{setq}. It sets the following variable,
-@code{major-mode}, to the subsequent value, which is @code{text-mode}.
+We are already familiar with @code{setq}. We use a similar macro
+@code{setq-default} to set the following variable,
+@code{major-mode}@footnote{We use @code{setq-default} because
+@code{text-mode} is buffer local. If we use @code{setq} it will only
+apply to the current buffer, and using @code{setq-default} will also
+apply this to newly created buffers.}, to the subsequent value, which is
+@code{text-mode}.
The single-quote before @code{text-mode} tells Emacs to deal directly
with the @code{text-mode} symbol, not with whatever it might stand for.
@xref{set & setq, , Setting the Value of a Variable},
--
2.39.2
This bug report was last modified 1 year and 149 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.