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.
This commit is contained in:
João Távora 2021-10-11 22:19:51 +01:00
parent b3d0f53b29
commit cf1409db71
3 changed files with 25 additions and 4 deletions

View 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

View 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,

View 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