emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comments on setopt


From: Po Lu
Subject: Re: Comments on setopt
Date: Wed, 16 Feb 2022 15:13:04 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux)

Richard Stallman <rms@gnu.org> writes:

> Setting a command line option is not especially common.
> I don't think it calls for a name of only 6 characters -- if I were
> choosing one afresh, I think I would choose `set-command-option'.
>
> The only reason to use `setopt' is to for parallelism with `getopt'.

This macro sets a customizable variable in Emacs, it's not related to
`getopt'.  Here is its definition:

  (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))))

Thanks.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]