Commit 197fbfc7 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/subr.el (setq-default): Define as a macro

* lisp/emacs-lisp/bytecomp.el (byte-compile-setq-default): Delete.
(byte-compile-set-default): Inline the part that it used.

* lisp/emacs-lisp/edebug.el (setq-default): Remove the debug spec.

* src/data.c (Fsetq_default): Delete.
(syms_of_data): Don't register.
parent 20ef15fb
Pipeline #1123 failed with stage
in 50 minutes
......@@ -940,8 +940,7 @@ If READABLE is nil, an expression is inserted. The expression is
a call to `define-abbrev-table' that when evaluated will define
the abbrev table NAME exactly as it is currently defined.
Abbrevs marked as \"system abbrevs\" are ignored."
(let ((table (symbol-value name))
(symbols (abbrev--table-symbols name readable)))
(let ((symbols (abbrev--table-symbols name readable)))
(setq symbols (sort symbols 'string-lessp))
(let ((standard-output (current-buffer)))
(if readable
......
......@@ -3910,7 +3910,6 @@ discarding."
(byte-defop-compiler-1 setq)
(byte-defop-compiler-1 setq-default)
(byte-defop-compiler-1 quote)
(defun byte-compile-setq (form)
......@@ -3935,34 +3934,20 @@ discarding."
(byte-compile-form nil byte-compile--for-effect)))
(setq byte-compile--for-effect nil)))
(defun byte-compile-setq-default (form)
(setq form (cdr form))
(if (null form) ; (setq-default), with no arguments
(byte-compile-form nil byte-compile--for-effect)
(if (> (length form) 2)
(let ((setters ()))
(while (consp form)
(push `(setq-default ,(pop form) ,(pop form)) setters))
(byte-compile-form (cons 'progn (nreverse setters))))
(let ((var (car form)))
(and (or (not (symbolp var))
(macroexp--const-symbol-p var t))
(byte-compile-warning-enabled-p 'constants)
(byte-compile-warn
"variable assignment to %s `%s'"
(if (symbolp var) "constant" "nonvariable")
(prin1-to-string var)))
(byte-compile-normal-call `(set-default ',var ,@(cdr form)))))))
(byte-defop-compiler-1 set-default)
(defun byte-compile-set-default (form)
(let ((varexp (car-safe (cdr-safe form))))
(if (eq (car-safe varexp) 'quote)
;; If the varexp is constant, compile it as a setq-default
;; so we get more warnings.
(byte-compile-setq-default `(setq-default ,(car-safe (cdr varexp))
,@(cddr form)))
(byte-compile-normal-call form))))
;; If the varexp is constant, check the var's name.
(let ((var (car-safe (cdr varexp))))
(and (or (not (symbolp var))
(macroexp--const-symbol-p var t))
(byte-compile-warning-enabled-p 'constants)
(byte-compile-warn
"variable assignment to %s `%s'"
(if (symbolp var) "constant" "nonvariable")
(prin1-to-string var)))))
(byte-compile-normal-call form)))
(defun byte-compile-quote (form)
(byte-compile-constant (car (cdr form))))
......
......@@ -2165,7 +2165,6 @@ into `edebug--cl-macrolet-defs' which is checked in `edebug-list-form-args'."
(def-edebug-spec let* let)
(def-edebug-spec setq (&rest symbolp form))
(def-edebug-spec setq-default setq)
(def-edebug-spec cond (&rest (&rest form)))
......
......@@ -118,6 +118,26 @@ BODY should be a list of Lisp expressions.
;; depend on backquote.el.
(list 'function (cons 'lambda cdr)))
(defmacro setq-default (&rest args)
"Set the default value of variable VAR to VALUE.
VAR, the variable name, is literal (not evaluated);
VALUE is an expression: it is evaluated and its value returned.
The default value of a variable is seen in buffers
that do not have their own values for the variable.
More generally, you can use multiple variables and values, as in
(setq-default VAR VALUE VAR VALUE...)
This sets each VAR's default value to the corresponding VALUE.
The VALUE for the Nth VAR can refer to the new default values
of previous VARs.
\(setq-default [VAR VALUE]...)"
(declare (debug setq))
(let ((exps nil))
(while args
(push `(set-default ',(pop args) ,(pop args)) exps))
`(progn . ,(nreverse exps))))
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
;; Can't use backquote here, it's too early in the bootstrap.
......
......@@ -1744,36 +1744,6 @@ for this variable. */)
set_default_internal (symbol, value, SET_INTERNAL_SET);
return value;
}
DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
doc: /* Set the default value of variable VAR to VALUE.
VAR, the variable name, is literal (not evaluated);
VALUE is an expression: it is evaluated and its value returned.
The default value of a variable is seen in buffers
that do not have their own values for the variable.
More generally, you can use multiple variables and values, as in
(setq-default VAR VALUE VAR VALUE...)
This sets each VAR's default value to the corresponding VALUE.
The VALUE for the Nth VAR can refer to the new default values
of previous VARs.
usage: (setq-default [VAR VALUE]...) */)
(Lisp_Object args)
{
Lisp_Object args_left, symbol, val;
args_left = val = args;
while (CONSP (args_left))
{
val = eval_sub (Fcar (XCDR (args_left)));
symbol = XCAR (args_left);
Fset_default (symbol, val);
args_left = Fcdr (XCDR (args_left));
}
return val;
}
/* Lisp functions for creating and removing buffer-local variables. */
......@@ -4047,7 +4017,6 @@ syms_of_data (void)
defsubr (&Sdefault_boundp);
defsubr (&Sdefault_value);
defsubr (&Sset_default);
defsubr (&Ssetq_default);
defsubr (&Smake_variable_buffer_local);
defsubr (&Smake_local_variable);
defsubr (&Skill_local_variable);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment