Rename elisp-shorthands to read-symbol-shorthands

The new name fits better in the family of variables that affect
the Lisp reader.

Suggested-by: Po Lu <luangruo@yahoo.com>

* doc/lispref/symbols.texi (Shorthands): Mention read-symbol-shorthands

* lisp/shorthands.el (hack-read-symbol-shorthands)
(hack-read-symbol-shorthands)
(shorthands-font-lock-shorthands): Use read-symbol-shorthands

* lisp/progmodes/elisp-mode.el (elisp--completion-local-symbols)
(elisp--completion-local-symbols)
(elisp-shorthands): Use read-symbol-shorthands

* src/lread.c:
(syms_of_lread): Define Vread_symbol_shorthands
(oblookup_considering_shorthand): Use Vread_symbol_shorthands.

* test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-read-buffer):
(elisp-shorthand-read-from-string): Use read-symbol-shorthands

* test/lisp/progmodes/elisp-mode-resources/simple-shorthand-test.el
Use new symbol name read-symbol-shorthands.
This commit is contained in:
João Távora 2021-10-03 12:14:41 +01:00
parent e6fbc45b7b
commit 137fa2d716
6 changed files with 44 additions and 44 deletions

View file

@ -666,7 +666,7 @@ different things. However, this practice commonly originates very
long symbols names, which are inconvenient to type and read after a long symbols names, which are inconvenient to type and read after a
while. Shorthands solve these issues in a clean way. while. Shorthands solve these issues in a clean way.
@defvar elisp-shorthands @defvar read-symbol-shorthands
This variable's value is an alist whose elements have the form This variable's value is an alist whose elements have the form
@code{(@var{shorthand-prefix} . @var{longhand-prefix})}. Each element @code{(@var{shorthand-prefix} . @var{longhand-prefix})}. Each element
instructs the Lisp reader to read every symbol form which starts with instructs the Lisp reader to read every symbol form which starts with
@ -704,7 +704,7 @@ alleviate that.
(snu-split "\\(\r\n\\|[\n\r]\\)" s)) (snu-split "\\(\r\n\\|[\n\r]\\)" s))
;; Local Variables: ;; Local Variables:
;; elisp-shorthands: (("snu-" . "some-nice-string-utils-")) ;; read-symbol-shorthands: (("snu-" . "some-nice-string-utils-"))
;; End: ;; End:
@end lisp @end lisp
@ -719,19 +719,19 @@ waiting for ElDoc (@pxref{Lisp Doc, , Local Variables in Files, emacs,
The GNU Emacs Manual}) to hint at the true full name of the symbol The GNU Emacs Manual}) to hint at the true full name of the symbol
under point in the echo area. under point in the echo area.
Since @code{elisp-shorthands} is a file-local variable, it is possible Since @code{read-symbol-shorthands} is a file-local variable, it is
that multiple libraries depending on possible that multiple libraries depending on
@file{some-nice-string-utils-lines.el} refer to the same symbols under @file{some-nice-string-utils-lines.el} refer to the same symbols under
@emph{different} shorthands, or not using shorthands at all. In the @emph{different} shorthands, or not using shorthands at all. In the
next example, the @file{my-tricks.el} library refers to the next example, the @file{my-tricks.el} library refers to the symbol
symbol @code{some-nice-string-utils-lines} using the @code{some-nice-string-utils-lines} using the @code{sns-} prefix
@code{sns-} prefix instead of @code{snu-}. instead of @code{snu-}.
@example @example
(defun t-reverse-lines (s) (string-join (reverse (sns-lines s)) "\n") (defun t-reverse-lines (s) (string-join (reverse (sns-lines s)) "\n")
;; Local Variables: ;; Local Variables:
;; elisp-shorthands: (("t-" . "my-tricks-") ;; read-symbol-shorthands: (("t-" . "my-tricks-")
;; ("sns-" . "some-nice-string-utils-")) ;; ("sns-" . "some-nice-string-utils-"))
;; End: ;; End:
@end example @end example

View file

@ -548,7 +548,7 @@ in `completion-at-point-functions' (which see)."
(lambda (s) (lambda (s)
(push s retval) (push s retval)
(cl-loop (cl-loop
for (shorthand . longhand) in elisp-shorthands for (shorthand . longhand) in read-symbol-shorthands
for full-name = (symbol-name s) for full-name = (symbol-name s)
when (string-prefix-p longhand full-name) when (string-prefix-p longhand full-name)
do (let ((sym (make-symbol do (let ((sym (make-symbol
@ -559,17 +559,17 @@ in `completion-at-point-functions' (which see)."
(push sym retval) (push sym retval)
retval)))) retval))))
retval))) retval)))
(cond ((null elisp-shorthands) obarray) (cond ((null read-symbol-shorthands) obarray)
((and obarray-cache ((and obarray-cache
(gethash (cons (current-buffer) elisp-shorthands) (gethash (cons (current-buffer) read-symbol-shorthands)
obarray-cache))) obarray-cache)))
(obarray-cache (obarray-cache
(puthash (cons (current-buffer) elisp-shorthands) (puthash (cons (current-buffer) read-symbol-shorthands)
(obarray-plus-shorthands) (obarray-plus-shorthands)
obarray-cache)) obarray-cache))
(t (t
(setq obarray-cache (make-hash-table :test #'equal)) (setq obarray-cache (make-hash-table :test #'equal))
(puthash (cons (current-buffer) elisp-shorthands) (puthash (cons (current-buffer) read-symbol-shorthands)
(obarray-plus-shorthands) (obarray-plus-shorthands)
obarray-cache))))) obarray-cache)))))
@ -2126,7 +2126,7 @@ Runs in a batch-mode Emacs. Interactively use variable
(pp collected))) (pp collected)))
(put 'elisp-shorthands 'safe-local-variable #'consp) (put 'read-symbol-shorthands 'safe-local-variable #'consp)
(provide 'elisp-mode) (provide 'elisp-mode)
;;; elisp-mode.el ends here ;;; elisp-mode.el ends here

View file

@ -28,13 +28,13 @@
(require 'files) (require 'files)
(eval-when-compile (require 'cl-lib)) (eval-when-compile (require 'cl-lib))
(defun hack-elisp-shorthands (fullname) (defun hack-read-symbol-shorthands (fullname)
"Return value of `elisp-shorthands' file-local variable in FULLNAME. "Return value of `read-symbol-shorthands' file-local variable in FULLNAME.
FULLNAME is the absolute file name of an Elisp .el file which FULLNAME is the absolute file name of an Elisp .el file which
potentially specifies a file-local value for `elisp-shorthands'. potentially specifies a file-local value for
The Elisp code in FULLNAME isn't read or evaluated in any way, `read-symbol-shorthands'. The Elisp code in FULLNAME isn't read
except for extraction of the buffer-local value of or evaluated in any way, except for extraction of the
`elisp-shorthands'." buffer-local value of `read-symbol-shorthands'."
(let* ((size (nth 7 (file-attributes fullname))) (let* ((size (nth 7 (file-attributes fullname)))
(from (max 0 (- size 3000))) (from (max 0 (- size 3000)))
(to size)) (to size))
@ -49,13 +49,13 @@ except for extraction of the buffer-local value of
;; detail of files.el. That function should be exported, ;; detail of files.el. That function should be exported,
;; possibly be refactored into two parts, since we're only ;; possibly be refactored into two parts, since we're only
;; interested in basic "Local Variables" parsing. ;; interested in basic "Local Variables" parsing.
(alist-get 'elisp-shorthands (hack-local-variables--find-variables))))) (alist-get 'read-symbol-shorthands (hack-local-variables--find-variables)))))
(defun load-with-shorthands-and-code-conversion (fullname file noerror nomessage) (defun load-with-shorthands-and-code-conversion (fullname file noerror nomessage)
"Like `load-with-code-conversion', but also consider Elisp shorthands. "Like `load-with-code-conversion', but also consider Elisp shorthands.
This function uses shorthands defined in the file FULLNAME's local This function uses shorthands defined in the file FULLNAME's local
value of `elisp-shorthands', when it processes that file's Elisp code." value of `read-symbol-shorthands', when it processes that file's Elisp code."
(let ((elisp-shorthands (hack-elisp-shorthands fullname))) (let ((read-symbol-shorthands (hack-read-symbol-shorthands fullname)))
(load-with-code-conversion fullname file noerror nomessage))) (load-with-code-conversion fullname file noerror nomessage)))
@ -78,7 +78,7 @@ value of `elisp-shorthands', when it processes that file's Elisp code."
finally (return (1- i)))) finally (return (1- i))))
(defun shorthands-font-lock-shorthands (limit) (defun shorthands-font-lock-shorthands (limit)
(when elisp-shorthands (when read-symbol-shorthands
(while (re-search-forward (while (re-search-forward
(eval-when-compile (eval-when-compile
(concat "\\_<\\(" lisp-mode-symbol-regexp "\\)\\_>")) (concat "\\_<\\(" lisp-mode-symbol-regexp "\\)\\_>"))

View file

@ -4626,29 +4626,29 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff
return tem; return tem;
} }
/* Like 'oblookup', but considers 'Velisp_shorthands', potentially /* Like 'oblookup', but considers 'Vread_symbol_shorthands',
recognizing that IN is shorthand for some other longhand name, potentially recognizing that IN is shorthand for some other
which is then then placed in OUT. In that case, memory is longhand name, which is then then placed in OUT. In that case,
malloc'ed for OUT (which the caller must free) while SIZE_OUT and memory is malloc'ed for OUT (which the caller must free) while
SIZE_BYTE_OUT respectively hold the character and byte sizes of the SIZE_OUT and SIZE_BYTE_OUT respectively hold the character and byte
transformed symbol name. If IN is not recognized shorthand for any sizes of the transformed symbol name. If IN is not recognized
other symbol, OUT is set to point to NULL and 'oblookup' is shorthand for any other symbol, OUT is set to point to NULL and
called. */ 'oblookup' is called. */
Lisp_Object Lisp_Object
oblookup_considering_shorthand (Lisp_Object obarray, const char *in, oblookup_considering_shorthand (Lisp_Object obarray, const char *in,
ptrdiff_t size, ptrdiff_t size_byte, char **out, ptrdiff_t size, ptrdiff_t size_byte, char **out,
ptrdiff_t *size_out, ptrdiff_t *size_byte_out) ptrdiff_t *size_out, ptrdiff_t *size_byte_out)
{ {
Lisp_Object tail = Velisp_shorthands; Lisp_Object tail = Vread_symbol_shorthands;
/* First, assume no transformation will take place. */ /* First, assume no transformation will take place. */
*out = NULL; *out = NULL;
/* Then, iterate each pair in Velisp_shorthands. */ /* Then, iterate each pair in Vread_symbol_shorthands. */
FOR_EACH_TAIL_SAFE (tail) FOR_EACH_TAIL_SAFE (tail)
{ {
Lisp_Object pair = XCAR (tail); Lisp_Object pair = XCAR (tail);
/* Be lenient to 'elisp-shorthands': if some element isn't a /* Be lenient to 'read-symbol-shorthands': if some element isn't a
cons, or some member of that cons isn't a string, just skip cons, or some member of that cons isn't a string, just skip
to the next element. */ to the next element. */
if (!CONSP (pair)) if (!CONSP (pair))
@ -5446,10 +5446,10 @@ that are loaded before your customizations are read! */);
DEFSYM (Qchar_from_name, "char-from-name"); DEFSYM (Qchar_from_name, "char-from-name");
DEFVAR_LISP ("elisp-shorthands", Velisp_shorthands, DEFVAR_LISP ("read-symbol-shorthands", Vread_symbol_shorthands,
doc: /* Alist of known symbol-name shorthands. doc: /* Alist of known symbol-name shorthands.
This variable's value can only be set via file-local variables. This variable's value can only be set via file-local variables.
See Info node `(elisp)Shorthands' for more details. */); See Info node `(elisp)Shorthands' for more details. */);
Velisp_shorthands = Qnil; Vread_symbol_shorthands = Qnil;
DEFSYM (Qobarray_cache, "obarray-cache"); DEFSYM (Qobarray_cache, "obarray-cache");
} }

View file

@ -1,17 +1,17 @@
(defun f-test () (defun f-test ()
(let ((elisp-shorthands '(("foo-" . "bar-")))) (let ((read-symbol-shorthands '(("foo-" . "bar-"))))
(with-temp-buffer (with-temp-buffer
(insert "(foo-bar)") (insert "(foo-bar)")
(goto-char (point-min)) (goto-char (point-min))
(read (current-buffer))))) (read (current-buffer)))))
(defun f-test2 () (defun f-test2 ()
(let ((elisp-shorthands '(("foo-" . "bar-")))) (let ((read-symbol-shorthands '(("foo-" . "bar-"))))
(read-from-string "(foo-bar)"))) (read-from-string "(foo-bar)")))
(defun f-test3 () (defun f-test3 ()
(let ((elisp-shorthands '(("foo-" . "bar-")))) (let ((read-symbol-shorthands '(("foo-" . "bar-"))))
(intern "foo-bar"))) (intern "foo-bar")))
(defvar f-test-complete-me 42) (defvar f-test-complete-me 42)
@ -34,5 +34,5 @@
;; Local Variables: ;; Local Variables:
;; elisp-shorthands: (("f-" . "elisp--foo-")) ;; read-symbol-shorthands: (("f-" . "elisp--foo-"))
;; End: ;; End:

View file

@ -1026,7 +1026,7 @@ evaluation of BODY."
(shorthand-sname (format "s-%s" gsym)) (shorthand-sname (format "s-%s" gsym))
(expected (intern (format "shorthand-longhand-%s" gsym)))) (expected (intern (format "shorthand-longhand-%s" gsym))))
(cl-assert (not (intern-soft shorthand-sname))) (cl-assert (not (intern-soft shorthand-sname)))
(should (equal (let ((elisp-shorthands (should (equal (let ((read-symbol-shorthands
'(("s-" . "shorthand-longhand-")))) '(("s-" . "shorthand-longhand-"))))
(with-temp-buffer (with-temp-buffer
(insert shorthand-sname) (insert shorthand-sname)
@ -1040,7 +1040,7 @@ evaluation of BODY."
(shorthand-sname (format "s-%s" gsym)) (shorthand-sname (format "s-%s" gsym))
(expected (intern (format "shorthand-longhand-%s" gsym)))) (expected (intern (format "shorthand-longhand-%s" gsym))))
(cl-assert (not (intern-soft shorthand-sname))) (cl-assert (not (intern-soft shorthand-sname)))
(should (equal (let ((elisp-shorthands (should (equal (let ((read-symbol-shorthands
'(("s-" . "shorthand-longhand-")))) '(("s-" . "shorthand-longhand-"))))
(car (read-from-string shorthand-sname))) (car (read-from-string shorthand-sname)))
expected)) expected))