From 450eef074b3a87c84e3937c01c63e6d2d63723cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Fri, 11 Aug 2023 10:50:38 +0200 Subject: [PATCH] Replace package-prefixes with symbol-packages --- admin/cl-packages.org | 24 ++++++++++++------------ lisp/emacs-lisp/bytecomp.el | 4 ++-- lisp/files.el | 4 ++-- src/lread.c | 16 ++++++---------- src/pkg.c | 11 +++++------ test/src/pkg-tests.el | 4 ++-- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/admin/cl-packages.org b/admin/cl-packages.org index 47cd349adc3..f5e56c002ce 100644 --- a/admin/cl-packages.org +++ b/admin/cl-packages.org @@ -46,10 +46,10 @@ The variables may go at some point. Or not. "*package-registry* is a hash-table of registered packages. The variable may go at some point. Or not. -A file-local variable "package-prefixes" can be used to enable or +A file-local variable "symbol-packages" can be used to enable or disable reading or printing of symbols with package prefixes. If -package-prefixes is nil, a symbol "a:b" will be read as a symbol with -name "a:b" in the Emacs package. If package-prefixes is t, "a:b" will +symbol-packages is nil, a symbol "a:b" will be read as a symbol with +name "a:b" in the Emacs package. If symbol-packages is t, "a:b" will be read as symbol "b" in package "a". Default is nil. Note that there is a small incompatibility here: In "normal" Emacs, @@ -115,7 +115,7 @@ the following of obarray-make to create obarrays. *** Reader -The variable 'package-prefixes' determines if the reader will +The variable 'symbol-packages' determines if the reader will interpret colons in a symbol name as part of a package name or not. Default is nil. @@ -152,7 +152,7 @@ But see under Ideas and Todos. *** Fake package qualification Existing code contains symbols like GUI:xyz which look like GUI is a package qualification. That's the reason for the variable -package-prefixes which means to interpret the : as part of the symbol +symbol-packages which means to interpret the : as part of the symbol name. ** Ideas / Todo @@ -181,23 +181,23 @@ Just ideas: with regexs. Or something. - (import sym as another-sym) -*** Package-prefixes in functions +*** symbol-packages in functions I'm wondering if it would be an idea to record the value of -package-prefixes at the time and in the buffer where functions are +symbol-packages at the time and in the buffer where functions are compiled or eval'd. We could then -- Bind package-prefixes around the execution of the function to that +- Bind symbol-packages around the execution of the function to that value. - Return a name with leading colon from symbol-value if - package-prefixes is nil, which means the function was compiled or + symbol-packages is nil, which means the function was compiled or eval'd in a "traditional" setting. It would return the keyword name - without the leading colon if package-prefixes is t. + without the leading colon if symbol-packages is t. - Make intern treat colons differently depending on the value of - package-prefixes. There are some places like transient.el which + symbol-packages. There are some places like transient.el which intern names with a leading colon which are a pain in the neck. - Maybe calls to read could also behave differently. @@ -209,7 +209,7 @@ This should be doable from that perspective. One probably just has to try it out. *** Modeline -A mode-line indicator showing the current package and package-prefixes +A mode-line indicator showing the current package and symbol-packages would be helpful. Can be done with (:eval ...) in global-mode-string now. Or maybe in a header-line. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index ddc1c316bc7..baa3e6b57ce 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2224,8 +2224,8 @@ See also `emacs-lisp-byte-compile-and-load'." ;; Don't inherit lexical-binding from caller (bug#12938). (unless (local-variable-p 'lexical-binding) (setq-local lexical-binding nil)) - (unless (local-variable-p 'package-prefixes) - (setq-local package-prefixes nil)) + (unless (local-variable-p 'symbol-packages) + (setq-local symbol-packages nil)) ;; Set the default directory, in case an eval-when-compile uses it. (setq default-directory (file-name-directory filename))) ;; Check if the file's local variables explicitly specify not to diff --git a/lisp/files.el b/lisp/files.el index 02db9996b33..7248a439ad5 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3687,7 +3687,7 @@ asking you for confirmation." (inhibit-compacting-font-caches . booleanp) ;; C source code (no-update-autoloads . booleanp) (lexical-binding . booleanp) ;; C source code - (package-prefixes . booleanp) ;; C source code + (symbol-packages . booleanp) ;; C source code (tab-width . integerp) ;; C source code (truncate-lines . booleanp) ;; C source code (word-wrap . booleanp) ;; C source code @@ -3726,7 +3726,7 @@ This hook is called only if there is at least one file-local variable to set.") (defvar permanently-enabled-local-variables - '(lexical-binding package-prefixes) + '(lexical-binding symbol-packages) "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") diff --git a/src/lread.c b/src/lread.c index a3fd76234e0..d65f05be1eb 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1166,8 +1166,7 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun, bool *prefixes) i--; val[i] = '\0'; - /* PKG-FIXME Do this more elegantly? */ - if (strcmp (var, "package-prefixes") == 0) + if (strcmp (var, "symbol-packages") == 0) *prefixes = strcmp (val, "nil") == 0 ? false : true; else if (strcmp (var, "lexical-binding") == 0) rv = (strcmp (val, "nil") != 0); @@ -1787,7 +1786,7 @@ Return t if the file exists and loads successfully. */) if (lisp_file_lexically_bound_p (Qget_file_char, &prefixes)) Fset (Qlexical_binding, Qt); if (prefixes) - Fset (Qpackage_prefixes, Qt); + Fset (Qsymbol_packages, Qt); if (! version || version >= 22) readevalloop (Qget_file_char, &input, hist_file_name, @@ -2666,7 +2665,7 @@ This function preserves the position of point. */) BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); bool prefixes; specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf, &prefixes) ? Qt : Qnil); - specbind (Qpackage_prefixes, prefixes ? Qt : Qnil); + specbind (Qsymbol_packages, prefixes ? Qt : Qnil); BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); readevalloop (buf, 0, filename, !NILP (printflag), unibyte, Qnil, Qnil, Qnil); @@ -4428,9 +4427,6 @@ read0 (Lisp_Object readcharfun, bool locate_syms) char *end = read_buffer + read_buffer_size; EMACS_INT start_position = readchar_offset - 1; - /* PKG-FIXME: This is too complicated. */ - /* PKG-FIXME: Check package-prefixes binding working. */ - /* Remember where package prefixes end in COLON, which will be set to the first colon we find. NCOLONS is the number of colons found so far. */ @@ -4450,7 +4446,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms) should't, or it is escaped by a preceding '\\' or inside a multi-escape. Note that we don't land here for #:. */ - if (c == ':' && !last_was_backslash && !NILP (Vpackage_prefixes)) + if (c == ':' && !last_was_backslash && !NILP (Vsymbol_packages)) { /* Remember where the first : is. */ if (colon == NULL) @@ -4549,7 +4545,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms) If we don't want to recognize ':' as a package indicator, nevertheless handle keywords. */ - if (NILP (Vpackage_prefixes)) + if (NILP (Vsymbol_packages)) { if (*symbol_start == ':') { @@ -4614,7 +4610,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms) result = Fmake_symbol (symbol_name); else if (NILP (package)) result = pkg_unqualified_symbol (symbol_name); - else if (NILP (Vpackage_prefixes)) + else if (NILP (Vsymbol_packages)) { /* package should be nil unless we found a keyword. */ eassert (EQ (package, Vkeyword_package)); diff --git a/src/pkg.c b/src/pkg.c index 026950078d8..622a5391f6d 100644 --- a/src/pkg.c +++ b/src/pkg.c @@ -933,11 +933,10 @@ init_pkg_once (void) DEFSYM (Qkeyword, "keyword"); DEFSYM (Qkeyword_package, "keyword-package"); DEFSYM (Qpackage, "package"); - DEFSYM (Qpackage_prefixes, "package-prefixes"); + DEFSYM (Qsymbol_packages, "symbol-packages"); DEFSYM (Qpackage_registry, "package-registry"); DEFSYM (Qpackagep, "packagep"); DEFSYM (Qsymbol_packages, "symbol-packages"); - DEFSYM (Qsymbol_packages, "symbol-packages"); DEFSYM (Qwatch_earmuffs_package, "watch-*package*"); staticpro (&Vpackage_registry); @@ -967,8 +966,8 @@ init_pkg_once (void) Vearmuffs_package = Vemacs_package; XSYMBOL (Qearmuffs_package)->u.s.declared_special = true; - staticpro (&Vpackage_prefixes); - Vpackage_prefixes = Qnil; + staticpro (&Vsymbol_packages); + Vsymbol_packages = Qnil; pkg_define_builtin_symbols (); } @@ -1010,9 +1009,9 @@ syms_of_pkg (void) doc: /* The current package. */); Fmake_variable_buffer_local (Qearmuffs_package); Fadd_variable_watcher (Qearmuffs_package, Fsymbol_function (Qwatch_earmuffs_package)); - DEFVAR_LISP_NOPRO ("package-prefixes", Vpackage_prefixes, + DEFVAR_LISP_NOPRO ("symbol-packages", Vsymbol_packages, doc: /* */); - Fmake_variable_buffer_local (Qpackage_prefixes); + Fmake_variable_buffer_local (Qsymbol_packages); Fprovide (Qsymbol_packages, Qnil); } diff --git a/test/src/pkg-tests.el b/test/src/pkg-tests.el index 9ddef8ebc78..bfb99f928db 100644 --- a/test/src/pkg-tests.el +++ b/test/src/pkg-tests.el @@ -95,7 +95,7 @@ (ert-deftest pkg-tests-read () (with-packages ((x :register t)) - (let* ((package-prefixes nil) + (let* ((symbol-packages nil) (sym (read "x::y"))) (should (symbolp sym)) (should (equal (symbol-name sym) "x::y")) @@ -108,7 +108,7 @@ (should (eq (symbol-package sym) *keyword-package*)))) (with-packages ((x :register t)) - (let* ((package-prefixes t) + (let* ((symbol-packages t) (sym (read "x::y"))) (should (symbolp sym)) (should (equal (symbol-name sym) "y")) -- 2.39.2