* 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.
way to alter the variable in future sessions is to put something in
your initialization file (@pxref{Init File}).
+ If you're setting a customizable variable in your initialization
+file, and you don't want to use the Customize interface, you can use
+the @code{setopt} macro. For instance:
+
+@findex setopt
+@example
+(setopt fill-column 75)
+@end example
+
+This works the same as @code{setq}, but if the variable has any
+special setter functions, they will be run automatically when using
+@code{setopt}. You can also use @code{setopt} on other,
+non-customizable variables, but this is less efficient than using
+@code{setq}.
+
@node Hooks
@subsection Hooks
@cindex hook
do that; to enable the mode in your init file, call the minor mode
command. Finally, a few customizable user options are initialized in
complex ways, and these have to be set either via the customize
-interface (@pxref{Customization}) or by using
-@code{customize-set-variable} (@pxref{Examining}).
+interface (@pxref{Customization}), or by using
+@code{customize-set-variable}/@code{setopt} (@pxref{Examining}).
The second argument to @code{setq} is an expression for the new
value of the variable. This can be a constant, a variable, or a
(@pxref{Communication Coding}).
@example
-(customize-set-variable 'selection-coding-system 'utf-8)
+(setopt selection-coding-system 'utf-8)
@end example
@item
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*scratch\\*" (display-buffer-same-window))))
@end group
@end example
@example
@group
-(customize-set-variable
- 'display-buffer-base-action
+(setopt
+ display-buffer-base-action
'((display-buffer-reuse-window display-buffer-pop-up-frame)
(reusable-frames . 0)))
@end group
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*Completions\\*" display-buffer-below-selected)))
@end group
@end example
@end example
@end defun
+@defmac setopt [symbol form]@dots{}
+This is like @code{setq} (see above), but meant for user options.
+This macro uses the Customize machinery to set the variable(s). In
+particular, @code{setopt} will run the setter function associated with
+the variable. For instance, if you have:
+
+@example
+(defcustom my-var 1
+ "My var."
+ :type 'number
+ :set (lambda (var val)
+ (set-default var val)
+ (message "We set %s to %s" var val)))
+@end example
+
+Then the following, in addition to setting @code{my-var} to @samp{2},
+will also issue a message:
+
+@example
+(setop my-var 2)
+@end example
+
+@code{setopt} can be used on regular, non-user option variables, but
+is much less efficient than @code{setq}. The main use case for this
+macro is setting user options in the user's init file.
+@end defmac
+
@node Watching Variables
@section Running a function when a variable is changed.
@cindex variable watchpoints
@example
@group
-(customize-set-variable
- 'display-buffer-base-action
+(setopt
+ display-buffer-base-action
'((display-buffer-reuse-window display-buffer-same-window
display-buffer-in-previous-window
display-buffer-use-some-window)))
@example
@group
-(customize-set-variable
- 'display-buffer-base-action
+(setopt
+ display-buffer-base-action
'((display-buffer-reuse-window display-buffer-pop-up-frame)
(reusable-frames . 0)))
@end group
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
(cons '("\\*foo\\*" (display-buffer-same-window))
display-buffer-alist))
@end group
@example
@group
-(customize-set-variable
- 'display-buffer-base-action
+(setopt
+ display-buffer-base-action
'((display-buffer-reuse-window display-buffer-pop-up-frame)
(reusable-frames . 0)))
@end group
@example
@group
-(customize-set-variable
- 'display-buffer-base-action
+(setopt
+ display-buffer-base-action
'(display-buffer-pop-up-frame (reusable-frames . 0)))
@end group
@end example
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*foo\\*"
(display-buffer-reuse-window display-buffer-pop-up-frame))))
@end group
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*foo\\*"
(display-buffer-reuse-window display-buffer-pop-up-frame)
(reusable-frames . visible))))
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*foo\\*"
(display-buffer-reuse-window display-buffer-pop-up-frame)
(inhibit-same-window . t)
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*foo\\*"
(display-buffer-below-selected display-buffer-at-bottom)
(inhibit-same-window . t)
@example
@group
-(customize-set-variable
- 'display-buffer-alist
+(setopt
+ display-buffer-alist
'(("\\*foo\\*"
(display-buffer-below-selected display-buffer-at-bottom)
(inhibit-same-window . t)
@lisp
(with-eval-after-load "message"
(define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
-(customize-set-variable 'eudc-server-hotlist
- '(("" . bbdb)
- ("ldaps://ldap.gnu.org" . ldap)))
-(customize-set-variable 'ldap-host-parameters-alist
- '(("ldaps://ldap.gnu.org"
- base "ou=people,dc=gnu,dc=org"
- binddn "gnu\\emacsuser"
- passwd ldap-password-read)))
+(setopt eudc-server-hotlist
+ '(("" . bbdb)
+ ("ldaps://ldap.gnu.org" . ldap)))
+(setopt 'ldap-host-parameters-alist
+ '(("ldaps://ldap.gnu.org"
+ base "ou=people,dc=gnu,dc=org"
+ binddn "gnu\\emacsuser"
+ passwd ldap-password-read)))
@end lisp
@findex ldap-password-read
@lisp
(with-eval-after-load "message"
(define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
-(customize-set-variable 'eudc-server-hotlist
- '(("" . bbdb)
- ("ldaps://ldap.gnu.org" . ldap)))
-(customize-set-variable 'ldap-host-parameters-alist
- '(("ldaps://ldap.gnu.org"
- auth-source t)))
+(setopt 'eudc-server-hotlist
+ '(("" . bbdb)
+ ("ldaps://ldap.gnu.org" . ldap)))
+(setopt 'ldap-host-parameters-alist
+ '(("ldaps://ldap.gnu.org"
+ auth-source t)))
@end lisp
For this example where we only care about one server, the server name
@lisp
(with-eval-after-load "message"
(define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
-(customize-set-variable 'eudc-server-hotlist
- '(("" . bbdb) ("" . ldap)))
-(customize-set-variable 'ldap-host-parameters-alist
- '(("" auth-source t)))
+(setopt 'eudc-server-hotlist
+ '(("" . bbdb) ("" . ldap)))
+(setopt 'ldap-host-parameters-alist
+ '(("" auth-source t)))
@end lisp
@node Troubleshooting
\f
* Lisp Changes in Emacs 29.1
++++
+** New macro 'setopt'.
+This is like 'setq', but uses 'customize-set-variable' to set the
+variable(s).
+
+++
** New utility predicate 'mode-line-window-selected-p'.
This is meant to be used from ':eval' mode line constructs to create
(put variable 'customized-variable-comment comment)))
value)
+;;;###autoload
+(defmacro setopt (&rest pairs)
+ "Set VARIABLE/VALUE pairs, and return the final VALUE.
+This is like `setq', but is meant for user options instead of
+plain variables. This means that `setopt' will execute any
+Customize form associated with VARIABLE.
+
+If VARIABLE has a `custom-set' property, that is used for setting
+VARIABLE, otherwise `set-default' is used.
+
+\(fn [VARIABLE VALUE]...)"
+ (declare (debug setq))
+ (unless (zerop (mod (length pairs) 2))
+ (error "PAIRS must have an even number of variable/value members"))
+ (let ((expr nil))
+ (while pairs
+ (unless (symbolp (car pairs))
+ (error "Attempting to set a non-symbol: %s" (car pairs)))
+ (push `(customize-set-variable ',(car pairs) ,(cadr pairs))
+ expr)
+ (setq pairs (cddr pairs)))
+ (macroexp-progn (nreverse expr))))
+
;;;###autoload
(defun customize-save-variable (variable value &optional comment)
"Set the default for VARIABLE to VALUE, and save it for future sessions.