aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2021-10-11 22:19:51 +0100
committerJoão Távora2021-10-11 22:29:16 +0100
commitcf1409db71152926767da189bf044c3a63e77128 (patch)
treedc5aa47220a48823b5e7139a630d7b790b7db89f
parentb3d0f53b296a0876ec7a55ae840868e65ed54e14 (diff)
downloademacs-cf1409db71152926767da189bf044c3a63e77128.tar.gz
emacs-cf1409db71152926767da189bf044c3a63e77128.zip
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.
-rw-r--r--doc/lispref/symbols.texi17
-rw-r--r--src/lread.c7
-rw-r--r--test/lisp/progmodes/elisp-mode-tests.el5
3 files changed, 25 insertions, 4 deletions
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-}.
735;; ("sns-" . "some-nice-string-utils-")) 735;; ("sns-" . "some-nice-string-utils-"))
736;; End: 736;; End:
737@end example 737@end example
738
739@subsection Exceptions
740
741There are two exceptions to rules governing Shorthand transformations:
742
743@itemize @bullet
744@item
745Symbol forms comprised entirely of symbol constituents (@pxref{Syntax
746Class Table}) are exempt not transform. For example, it's possible to
747use @code{-} or @code{/=} as shorthand prefixes, but that won't shadow
748the arithmetic @emph{functions} that have exactly that prefix as their
749full name.;
750
751@item
752Symbol forms whose name starts with the the characters @code{#_} are
753also exempted.
754@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)
3805 ptrdiff_t longhand_bytes = 0; 3805 ptrdiff_t longhand_bytes = 0;
3806 3806
3807 Lisp_Object tem; 3807 Lisp_Object tem;
3808 if (skip_shorthand) 3808 if (skip_shorthand ||
3809 /* The following ASCII characters are used in the
3810 only "core" Emacs Lisp symbols that are
3811 exclusively comprised of 'symbol constituent'
3812 syntax. */
3813 strspn(read_buffer, "^*+-/<=>_|") >= nbytes)
3809 tem = oblookup (obarray, read_buffer, nchars, nbytes); 3814 tem = oblookup (obarray, read_buffer, nchars, nbytes);
3810 else 3815 else
3811 tem = oblookup_considering_shorthand (obarray, read_buffer, 3816 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."
1094 (should (unintern "f-test4---")))) 1094 (should (unintern "f-test4---"))))
1095 1095
1096(ert-deftest elisp-dont-shadow-punctuation-only-symbols () 1096(ert-deftest elisp-dont-shadow-punctuation-only-symbols ()
1097 :expected-result :failed ; bug#51089 1097 (let* ((shorthanded-form '(/= 42 (-foo 42)))
1098 (let* ((shorthanded-form '(- 42 (-foo 42))) 1098 (expected-longhand-form '(/= 42 (fooey-foo 42)))
1099 (expected-longhand-form '(- 42 (fooey-foo 42)))
1100 (observed (let ((read-symbol-shorthands 1099 (observed (let ((read-symbol-shorthands
1101 '(("-" . "fooey-")))) 1100 '(("-" . "fooey-"))))
1102 (car (read-from-string 1101 (car (read-from-string