emacs-diffs
[Top][All Lists]
Advanced

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

emacs-28 cf1409d: Don't apply shorthands to punctuation-only symbols (bu


From: João Távora
Subject: emacs-28 cf1409d: Don't apply shorthands to punctuation-only symbols (bug#51089)
Date: Mon, 11 Oct 2021 17:30:27 -0400 (EDT)

branch: emacs-28
commit cf1409db71152926767da189bf044c3a63e77128
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Don't apply shorthands to punctuation-only symbols (bug#51089)
    
    This includes symbols used for arithmetic functions such as -, /=,
    etc.  Using "-" or "/=" is still possible but doing so won't shadow
    those functions.
    
    * doc/lispref/symbols.texi (Shorthand, Exceptions): New
    subsubsection.
    
    * src/lread.c (read1): Exempt punctionation-only symbols from
    oblookup_considering_shorthand.
    
    * test/lisp/progmodes/elisp-mode-tests.el
    (elisp-dont-shadow-punctuation-only-symbols): Tweak test.
---
 doc/lispref/symbols.texi                | 17 +++++++++++++++++
 src/lread.c                             |  7 ++++++-
 test/lisp/progmodes/elisp-mode-tests.el |  5 ++---
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 9c33e2c..ed7dce1 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -735,3 +735,20 @@ instead of @code{snu-}.
 ;;                          ("sns-" . "some-nice-string-utils-"))
 ;; End:
 @end example
+
+@subsection Exceptions
+
+There are two exceptions to rules governing Shorthand transformations:
+
+@itemize @bullet
+@item
+Symbol forms comprised entirely of symbol constituents (@pxref{Syntax
+Class Table}) are exempt not transform.  For example, it's possible to
+use @code{-} or @code{/=} as shorthand prefixes, but that won't shadow
+the arithmetic @emph{functions} that have exactly that prefix as their
+full name.;
+
+@item
+Symbol forms whose name starts with the the characters @code{#_} are
+also exempted.
+@end itemize
diff --git a/src/lread.c b/src/lread.c
index 07580d1..128b46a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3805,7 +3805,12 @@ read1 (Lisp_Object readcharfun, int *pch, bool 
first_in_list)
              ptrdiff_t longhand_bytes = 0;
 
              Lisp_Object tem;
-             if (skip_shorthand)
+             if (skip_shorthand ||
+                 /* The following ASCII characters are used in the
+                    only "core" Emacs Lisp symbols that are
+                    exclusively comprised of 'symbol constituent'
+                    syntax. */
+                 strspn(read_buffer, "^*+-/<=>_|") >= nbytes)
                tem = oblookup (obarray, read_buffer, nchars, nbytes);
              else
                tem = oblookup_considering_shorthand (obarray, read_buffer,
diff --git a/test/lisp/progmodes/elisp-mode-tests.el 
b/test/lisp/progmodes/elisp-mode-tests.el
index e816d3c..400c76c 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -1094,9 +1094,8 @@ evaluation of BODY."
     (should (unintern "f-test4---"))))
 
 (ert-deftest elisp-dont-shadow-punctuation-only-symbols ()
-  :expected-result :failed ;  bug#51089
-  (let* ((shorthanded-form '(- 42 (-foo 42)))
-         (expected-longhand-form '(- 42 (fooey-foo 42)))
+  (let* ((shorthanded-form '(/= 42 (-foo 42)))
+         (expected-longhand-form '(/= 42 (fooey-foo 42)))
          (observed (let ((read-symbol-shorthands
                           '(("-" . "fooey-"))))
                      (car (read-from-string



reply via email to

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