aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-02-13 16:29:26 +0100
committerLars Ingebrigtsen2022-02-13 16:29:26 +0100
commit997dd86a9f6a253e4542d65b17dfec6af2f4e8fd (patch)
tree446bf645ed4c341bf4fd237fbdd3812897c20562
parent68b32732140606a1eddce82f50733c549a40900a (diff)
downloademacs-997dd86a9f6a253e4542d65b17dfec6af2f4e8fd.tar.gz
emacs-997dd86a9f6a253e4542d65b17dfec6af2f4e8fd.zip
Add a new macro `setopt'
* doc/emacs/custom.texi (Examining): Mention it. (Init Syntax): Ditto. * doc/emacs/windows.texi (Window Choice): Adjust example. * doc/lispref/windows.texi (Choosing Window Options): Adjust examples. * doc/lispref/variables.texi (Setting Variables): Document setopt. * doc/misc/eudc.texi (Emacs-only Configuration): Adjust examples. * lisp/cus-edit.el (setopt): New macro.
-rw-r--r--doc/emacs/custom.texi21
-rw-r--r--doc/emacs/windows.texi12
-rw-r--r--doc/lispref/variables.texi27
-rw-r--r--doc/lispref/windows.texi40
-rw-r--r--doc/misc/eudc.texi36
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/cus-edit.el23
7 files changed, 117 insertions, 47 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index b2dd5eb6980..c4f112d6683 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -844,6 +844,21 @@ otherwise stated, affects only the current Emacs session. The only
844way to alter the variable in future sessions is to put something in 844way to alter the variable in future sessions is to put something in
845your initialization file (@pxref{Init File}). 845your initialization file (@pxref{Init File}).
846 846
847 If you're setting a customizable variable in your initialization
848file, and you don't want to use the Customize interface, you can use
849the @code{setopt} macro. For instance:
850
851@findex setopt
852@example
853(setopt fill-column 75)
854@end example
855
856This works the same as @code{setq}, but if the variable has any
857special setter functions, they will be run automatically when using
858@code{setopt}. You can also use @code{setopt} on other,
859non-customizable variables, but this is less efficient than using
860@code{setq}.
861
847@node Hooks 862@node Hooks
848@subsection Hooks 863@subsection Hooks
849@cindex hook 864@cindex hook
@@ -2338,8 +2353,8 @@ mode when you set them with Customize, but ordinary @code{setq} won't
2338do that; to enable the mode in your init file, call the minor mode 2353do that; to enable the mode in your init file, call the minor mode
2339command. Finally, a few customizable user options are initialized in 2354command. Finally, a few customizable user options are initialized in
2340complex ways, and these have to be set either via the customize 2355complex ways, and these have to be set either via the customize
2341interface (@pxref{Customization}) or by using 2356interface (@pxref{Customization}), or by using
2342@code{customize-set-variable} (@pxref{Examining}). 2357@code{customize-set-variable}/@code{setopt} (@pxref{Examining}).
2343 2358
2344 The second argument to @code{setq} is an expression for the new 2359 The second argument to @code{setq} is an expression for the new
2345value of the variable. This can be a constant, a variable, or a 2360value of the variable. This can be a constant, a variable, or a
@@ -2492,7 +2507,7 @@ Change the coding system used when using the clipboard
2492(@pxref{Communication Coding}). 2507(@pxref{Communication Coding}).
2493 2508
2494@example 2509@example
2495(customize-set-variable 'selection-coding-system 'utf-8) 2510(setopt selection-coding-system 'utf-8)
2496@end example 2511@end example
2497 2512
2498@item 2513@item
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi
index 4a3862562c2..4537f8157e8 100644
--- a/doc/emacs/windows.texi
+++ b/doc/emacs/windows.texi
@@ -442,8 +442,8 @@ selected window write:
442 442
443@example 443@example
444@group 444@group
445(customize-set-variable 445(setopt
446 'display-buffer-alist 446 display-buffer-alist
447 '(("\\*scratch\\*" (display-buffer-same-window)))) 447 '(("\\*scratch\\*" (display-buffer-same-window))))
448@end group 448@end group
449@end example 449@end example
@@ -468,8 +468,8 @@ Lisp Reference Manual}) as follows:
468 468
469@example 469@example
470@group 470@group
471(customize-set-variable 471(setopt
472 'display-buffer-base-action 472 display-buffer-base-action
473 '((display-buffer-reuse-window display-buffer-pop-up-frame) 473 '((display-buffer-reuse-window display-buffer-pop-up-frame)
474 (reusable-frames . 0))) 474 (reusable-frames . 0)))
475@end group 475@end group
@@ -535,8 +535,8 @@ the following form in your initialization file (@pxref{Init File}):
535 535
536@example 536@example
537@group 537@group
538(customize-set-variable 538(setopt
539 'display-buffer-alist 539 display-buffer-alist
540 '(("\\*Completions\\*" display-buffer-below-selected))) 540 '(("\\*Completions\\*" display-buffer-below-selected)))
541@end group 541@end group
542@end example 542@end example
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index b9de92a29eb..8b5f50562e7 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -861,6 +861,33 @@ error is signaled.
861@end example 861@end example
862@end defun 862@end defun
863 863
864@defmac setopt [symbol form]@dots{}
865This is like @code{setq} (see above), but meant for user options.
866This macro uses the Customize machinery to set the variable(s). In
867particular, @code{setopt} will run the setter function associated with
868the variable. For instance, if you have:
869
870@example
871(defcustom my-var 1
872 "My var."
873 :type 'number
874 :set (lambda (var val)
875 (set-default var val)
876 (message "We set %s to %s" var val)))
877@end example
878
879Then the following, in addition to setting @code{my-var} to @samp{2},
880will also issue a message:
881
882@example
883(setop my-var 2)
884@end example
885
886@code{setopt} can be used on regular, non-user option variables, but
887is much less efficient than @code{setq}. The main use case for this
888macro is setting user options in the user's init file.
889@end defmac
890
864@node Watching Variables 891@node Watching Variables
865@section Running a function when a variable is changed. 892@section Running a function when a variable is changed.
866@cindex variable watchpoints 893@cindex variable watchpoints
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index bbf8988e5c4..43f222d57ff 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -3377,8 +3377,8 @@ functions it should try instead as, for example:
3377 3377
3378@example 3378@example
3379@group 3379@group
3380(customize-set-variable 3380(setopt
3381 'display-buffer-base-action 3381 display-buffer-base-action
3382 '((display-buffer-reuse-window display-buffer-same-window 3382 '((display-buffer-reuse-window display-buffer-same-window
3383 display-buffer-in-previous-window 3383 display-buffer-in-previous-window
3384 display-buffer-use-some-window))) 3384 display-buffer-use-some-window)))
@@ -3392,8 +3392,8 @@ Instead of customizing this variable to @code{t}, customize
3392 3392
3393@example 3393@example
3394@group 3394@group
3395(customize-set-variable 3395(setopt
3396 'display-buffer-base-action 3396 display-buffer-base-action
3397 '((display-buffer-reuse-window display-buffer-pop-up-frame) 3397 '((display-buffer-reuse-window display-buffer-pop-up-frame)
3398 (reusable-frames . 0))) 3398 (reusable-frames . 0)))
3399@end group 3399@end group
@@ -3409,8 +3409,8 @@ specifying the action function @code{display-buffer-same-window}.
3409 3409
3410@example 3410@example
3411@group 3411@group
3412(customize-set-variable 3412(setopt
3413 'display-buffer-alist 3413 display-buffer-alist
3414 (cons '("\\*foo\\*" (display-buffer-same-window)) 3414 (cons '("\\*foo\\*" (display-buffer-same-window))
3415 display-buffer-alist)) 3415 display-buffer-alist))
3416@end group 3416@end group
@@ -3483,8 +3483,8 @@ another frame. Such a user might provide the following customization:
3483 3483
3484@example 3484@example
3485@group 3485@group
3486(customize-set-variable 3486(setopt
3487 'display-buffer-base-action 3487 display-buffer-base-action
3488 '((display-buffer-reuse-window display-buffer-pop-up-frame) 3488 '((display-buffer-reuse-window display-buffer-pop-up-frame)
3489 (reusable-frames . 0))) 3489 (reusable-frames . 0)))
3490@end group 3490@end group
@@ -3529,8 +3529,8 @@ In fact, this:
3529 3529
3530@example 3530@example
3531@group 3531@group
3532(customize-set-variable 3532(setopt
3533 'display-buffer-base-action 3533 display-buffer-base-action
3534 '(display-buffer-pop-up-frame (reusable-frames . 0))) 3534 '(display-buffer-pop-up-frame (reusable-frames . 0)))
3535@end group 3535@end group
3536@end example 3536@end example
@@ -3586,8 +3586,8 @@ by customizing the option @code{display-buffer-alist} as follows:
3586 3586
3587@example 3587@example
3588@group 3588@group
3589(customize-set-variable 3589(setopt
3590 'display-buffer-alist 3590 display-buffer-alist
3591 '(("\\*foo\\*" 3591 '(("\\*foo\\*"
3592 (display-buffer-reuse-window display-buffer-pop-up-frame)))) 3592 (display-buffer-reuse-window display-buffer-pop-up-frame))))
3593@end group 3593@end group
@@ -3609,8 +3609,8 @@ we would have to specify that separately, however:
3609 3609
3610@example 3610@example
3611@group 3611@group
3612(customize-set-variable 3612(setopt
3613 'display-buffer-alist 3613 display-buffer-alist
3614 '(("\\*foo\\*" 3614 '(("\\*foo\\*"
3615 (display-buffer-reuse-window display-buffer-pop-up-frame) 3615 (display-buffer-reuse-window display-buffer-pop-up-frame)
3616 (reusable-frames . visible)))) 3616 (reusable-frames . visible))))
@@ -3716,8 +3716,8 @@ written that as
3716 3716
3717@example 3717@example
3718@group 3718@group
3719(customize-set-variable 3719(setopt
3720 'display-buffer-alist 3720 display-buffer-alist
3721 '(("\\*foo\\*" 3721 '(("\\*foo\\*"
3722 (display-buffer-reuse-window display-buffer-pop-up-frame) 3722 (display-buffer-reuse-window display-buffer-pop-up-frame)
3723 (inhibit-same-window . t) 3723 (inhibit-same-window . t)
@@ -3860,8 +3860,8 @@ follows:
3860 3860
3861@example 3861@example
3862@group 3862@group
3863(customize-set-variable 3863(setopt
3864 'display-buffer-alist 3864 display-buffer-alist
3865 '(("\\*foo\\*" 3865 '(("\\*foo\\*"
3866 (display-buffer-below-selected display-buffer-at-bottom) 3866 (display-buffer-below-selected display-buffer-at-bottom)
3867 (inhibit-same-window . t) 3867 (inhibit-same-window . t)
@@ -3874,8 +3874,8 @@ To add a customization for a second buffer one would then write:
3874 3874
3875@example 3875@example
3876@group 3876@group
3877(customize-set-variable 3877(setopt
3878 'display-buffer-alist 3878 display-buffer-alist
3879 '(("\\*foo\\*" 3879 '(("\\*foo\\*"
3880 (display-buffer-below-selected display-buffer-at-bottom) 3880 (display-buffer-below-selected display-buffer-at-bottom)
3881 (inhibit-same-window . t) 3881 (inhibit-same-window . t)
diff --git a/doc/misc/eudc.texi b/doc/misc/eudc.texi
index e9cf4cfade9..7c37ae55055 100644
--- a/doc/misc/eudc.texi
+++ b/doc/misc/eudc.texi
@@ -286,14 +286,14 @@ LDAP:
286@lisp 286@lisp
287(with-eval-after-load "message" 287(with-eval-after-load "message"
288 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline)) 288 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
289(customize-set-variable 'eudc-server-hotlist 289(setopt eudc-server-hotlist
290 '(("" . bbdb) 290 '(("" . bbdb)
291 ("ldaps://ldap.gnu.org" . ldap))) 291 ("ldaps://ldap.gnu.org" . ldap)))
292(customize-set-variable 'ldap-host-parameters-alist 292(setopt 'ldap-host-parameters-alist
293 '(("ldaps://ldap.gnu.org" 293 '(("ldaps://ldap.gnu.org"
294 base "ou=people,dc=gnu,dc=org" 294 base "ou=people,dc=gnu,dc=org"
295 binddn "gnu\\emacsuser" 295 binddn "gnu\\emacsuser"
296 passwd ldap-password-read))) 296 passwd ldap-password-read)))
297@end lisp 297@end lisp
298 298
299@findex ldap-password-read 299@findex ldap-password-read
@@ -342,12 +342,12 @@ configure EUDC for LDAP:
342@lisp 342@lisp
343(with-eval-after-load "message" 343(with-eval-after-load "message"
344 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline)) 344 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
345(customize-set-variable 'eudc-server-hotlist 345(setopt 'eudc-server-hotlist
346 '(("" . bbdb) 346 '(("" . bbdb)
347 ("ldaps://ldap.gnu.org" . ldap))) 347 ("ldaps://ldap.gnu.org" . ldap)))
348(customize-set-variable 'ldap-host-parameters-alist 348(setopt 'ldap-host-parameters-alist
349 '(("ldaps://ldap.gnu.org" 349 '(("ldaps://ldap.gnu.org"
350 auth-source t))) 350 auth-source t)))
351@end lisp 351@end lisp
352 352
353For this example where we only care about one server, the server name 353For this example where we only care about one server, the server name
@@ -371,10 +371,10 @@ and the @file{.emacs} expressions become:
371@lisp 371@lisp
372(with-eval-after-load "message" 372(with-eval-after-load "message"
373 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline)) 373 (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
374(customize-set-variable 'eudc-server-hotlist 374(setopt 'eudc-server-hotlist
375 '(("" . bbdb) ("" . ldap))) 375 '(("" . bbdb) ("" . ldap)))
376(customize-set-variable 'ldap-host-parameters-alist 376(setopt 'ldap-host-parameters-alist
377 '(("" auth-source t))) 377 '(("" auth-source t)))
378@end lisp 378@end lisp
379 379
380@node Troubleshooting 380@node Troubleshooting
diff --git a/etc/NEWS b/etc/NEWS
index 6f5edfafc5a..0f956f18a20 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1093,6 +1093,11 @@ functions.
1093* Lisp Changes in Emacs 29.1 1093* Lisp Changes in Emacs 29.1
1094 1094
1095+++ 1095+++
1096** New macro 'setopt'.
1097This is like 'setq', but uses 'customize-set-variable' to set the
1098variable(s).
1099
1100+++
1096** New utility predicate 'mode-line-window-selected-p'. 1101** New utility predicate 'mode-line-window-selected-p'.
1097This is meant to be used from ':eval' mode line constructs to create 1102This is meant to be used from ':eval' mode line constructs to create
1098different mode line looks for selected and unselected windows. 1103different mode line looks for selected and unselected windows.
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index ff70f6724a8..bb7ffc1eae5 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1045,6 +1045,29 @@ If given a prefix (or a COMMENT argument), also prompt for a comment."
1045 value) 1045 value)
1046 1046
1047;;;###autoload 1047;;;###autoload
1048(defmacro setopt (&rest pairs)
1049 "Set VARIABLE/VALUE pairs, and return the final VALUE.
1050This is like `setq', but is meant for user options instead of
1051plain variables. This means that `setopt' will execute any
1052Customize form associated with VARIABLE.
1053
1054If VARIABLE has a `custom-set' property, that is used for setting
1055VARIABLE, otherwise `set-default' is used.
1056
1057\(fn [VARIABLE VALUE]...)"
1058 (declare (debug setq))
1059 (unless (zerop (mod (length pairs) 2))
1060 (error "PAIRS must have an even number of variable/value members"))
1061 (let ((expr nil))
1062 (while pairs
1063 (unless (symbolp (car pairs))
1064 (error "Attempting to set a non-symbol: %s" (car pairs)))
1065 (push `(customize-set-variable ',(car pairs) ,(cadr pairs))
1066 expr)
1067 (setq pairs (cddr pairs)))
1068 (macroexp-progn (nreverse expr))))
1069
1070;;;###autoload
1048(defun customize-save-variable (variable value &optional comment) 1071(defun customize-save-variable (variable value &optional comment)
1049 "Set the default for VARIABLE to VALUE, and save it for future sessions. 1072 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1050Return VALUE. 1073Return VALUE.