]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't apply shorthands to punctuation-only symbols (bug#51089)
authorJoão Távora <joaotavora@gmail.com>
Mon, 11 Oct 2021 21:19:51 +0000 (22:19 +0100)
committerJoão Távora <joaotavora@gmail.com>
Mon, 11 Oct 2021 21:29:16 +0000 (22:29 +0100)
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
src/lread.c
test/lisp/progmodes/elisp-mode-tests.el

index 9c33e2c8ec2f7e0f966fcc573335445d555f6b19..ed7dce1c09146bdc9034ac5b1516be483b3e20e6 100644 (file)
@@ -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
index 07580d11d13566bbba74d980fed04b2748b88ea1..128b46aefefadb00e8a8cc95576a0bc601afc119 100644 (file)
@@ -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,
index e816d3c1b029557309c8edd6a6dcad699c533581..400c76c187ffa2dc728acc4319622df810857397 100644 (file)
@@ -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