aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorStefan Monnier2022-01-28 13:19:11 -0500
committerStefan Monnier2022-01-28 13:19:11 -0500
commit7531bf096eb3f1b0b6612e94eb5211405e049fee (patch)
tree387cb37020e6256d7491f9407f8f844de90de6be /src/data.c
parent1f5fa1de7fc2f23ebd7e68db219da4faee916a6f (diff)
downloademacs-7531bf096eb3f1b0b6612e94eb5211405e049fee.tar.gz
emacs-7531bf096eb3f1b0b6612e94eb5211405e049fee.zip
Reduce code duplication in parts of (auto)load&defalias
* src/data.c (defalias): New function, extracted from `Fdefalias`. (Fdefalias): Use it. (Ffset): Don't handle `Vautoload_queue` here, handle it in `defalias` instead. * src/comp.c (comp--register-subr): Use `defalias` instead of duplicating its code. * src/eval.c (load_with_autoload_queue): New function, extracted from `Fautoload_do_load`. (Fautoload_do_load): Use it. (un_autoload): Mark it as static. * src/fns.c (Frequire): Use it as well. * src/lisp.h (defalias, load_with_autoload_queue): New declarations. (un_autoload): Remove declaration.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/data.c b/src/data.c
index 7422348e392..dd6ec4c41a8 100644
--- a/src/data.c
+++ b/src/data.c
@@ -846,9 +846,6 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
846 846
847 function = XSYMBOL (symbol)->u.s.function; 847 function = XSYMBOL (symbol)->u.s.function;
848 848
849 if (!NILP (Vautoload_queue) && !NILP (function))
850 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
851
852 if (AUTOLOADP (function)) 849 if (AUTOLOADP (function))
853 Fput (symbol, Qautoload, XCDR (function)); 850 Fput (symbol, Qautoload, XCDR (function));
854 851
@@ -866,35 +863,23 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
866 return definition; 863 return definition;
867} 864}
868 865
869DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0, 866void
870 doc: /* Set SYMBOL's function definition to DEFINITION. 867defalias (Lisp_Object symbol, Lisp_Object definition)
871Associates the function with the current load file, if any.
872The optional third argument DOCSTRING specifies the documentation string
873for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
874determined by DEFINITION.
875
876Internally, this normally uses `fset', but if SYMBOL has a
877`defalias-fset-function' property, the associated value is used instead.
878
879The return value is undefined. */)
880 (register Lisp_Object symbol, Lisp_Object definition, Lisp_Object docstring)
881{ 868{
882 CHECK_SYMBOL (symbol);
883 if (!NILP (Vpurify_flag)
884 /* If `definition' is a keymap, immutable (and copying) is wrong. */
885 && !KEYMAPP (definition))
886 definition = Fpurecopy (definition);
887
888 { 869 {
889 bool autoload = AUTOLOADP (definition); 870 bool autoload = AUTOLOADP (definition);
890 if (!will_dump_p () || !autoload) 871 if (!will_dump_p () || !autoload)
891 { /* Only add autoload entries after dumping, because the ones before are 872 { /* Only add autoload entries after dumping, because the ones before are
892 not useful and else we get loads of them from the loaddefs.el. */ 873 not useful and else we get loads of them from the loaddefs.el. */
874 Lisp_Object function = XSYMBOL (symbol)->u.s.function;
893 875
894 if (AUTOLOADP (XSYMBOL (symbol)->u.s.function)) 876 if (AUTOLOADP (function))
895 /* Remember that the function was already an autoload. */ 877 /* Remember that the function was already an autoload. */
896 LOADHIST_ATTACH (Fcons (Qt, symbol)); 878 LOADHIST_ATTACH (Fcons (Qt, symbol));
897 LOADHIST_ATTACH (Fcons (autoload ? Qautoload : Qdefun, symbol)); 879 LOADHIST_ATTACH (Fcons (autoload ? Qautoload : Qdefun, symbol));
880
881 if (!NILP (Vautoload_queue) && !NILP (function))
882 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
898 } 883 }
899 } 884 }
900 885
@@ -905,6 +890,28 @@ The return value is undefined. */)
905 else 890 else
906 Ffset (symbol, definition); 891 Ffset (symbol, definition);
907 } 892 }
893}
894
895DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0,
896 doc: /* Set SYMBOL's function definition to DEFINITION.
897Associates the function with the current load file, if any.
898The optional third argument DOCSTRING specifies the documentation string
899for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
900determined by DEFINITION.
901
902Internally, this normally uses `fset', but if SYMBOL has a
903`defalias-fset-function' property, the associated value is used instead.
904
905The return value is undefined. */)
906 (register Lisp_Object symbol, Lisp_Object definition, Lisp_Object docstring)
907{
908 CHECK_SYMBOL (symbol);
909 if (!NILP (Vpurify_flag)
910 /* If `definition' is a keymap, immutable (and copying) is wrong. */
911 && !KEYMAPP (definition))
912 definition = Fpurecopy (definition);
913
914 defalias (symbol, definition);
908 915
909 maybe_defer_native_compilation (symbol, definition); 916 maybe_defer_native_compilation (symbol, definition);
910 917