From: João Távora Date: Mon, 11 Oct 2021 21:19:51 +0000 (+0100) Subject: Don't apply shorthands to punctuation-only symbols (bug#51089) X-Git-Tag: emacs-28.0.90~312 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cf1409db71152926767da189bf044c3a63e77128;p=emacs.git 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. --- diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index 9c33e2c8ec2..ed7dce1c091 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 07580d11d13..128b46aefef 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 e816d3c1b02..400c76c187f 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