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:
parent
e6fbc45b7b
commit
137fa2d716
6 changed files with 44 additions and 44 deletions
|
@ -666,7 +666,7 @@ different things. However, this practice commonly originates very
|
|||
long symbols names, which are inconvenient to type and read after a
|
||||
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
|
||||
@code{(@var{shorthand-prefix} . @var{longhand-prefix})}. Each element
|
||||
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))
|
||||
|
||||
;; Local Variables:
|
||||
;; elisp-shorthands: (("snu-" . "some-nice-string-utils-"))
|
||||
;; read-symbol-shorthands: (("snu-" . "some-nice-string-utils-"))
|
||||
;; End:
|
||||
@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
|
||||
under point in the echo area.
|
||||
|
||||
Since @code{elisp-shorthands} is a file-local variable, it is possible
|
||||
that multiple libraries depending on
|
||||
Since @code{read-symbol-shorthands} is a file-local variable, it is
|
||||
possible that multiple libraries depending on
|
||||
@file{some-nice-string-utils-lines.el} refer to the same symbols under
|
||||
@emph{different} shorthands, or not using shorthands at all. In the
|
||||
next example, the @file{my-tricks.el} library refers to the
|
||||
symbol @code{some-nice-string-utils-lines} using the
|
||||
@code{sns-} prefix instead of @code{snu-}.
|
||||
next example, the @file{my-tricks.el} library refers to the symbol
|
||||
@code{some-nice-string-utils-lines} using the @code{sns-} prefix
|
||||
instead of @code{snu-}.
|
||||
|
||||
@example
|
||||
(defun t-reverse-lines (s) (string-join (reverse (sns-lines s)) "\n")
|
||||
|
||||
;; Local Variables:
|
||||
;; elisp-shorthands: (("t-" . "my-tricks-")
|
||||
;; ("sns-" . "some-nice-string-utils-"))
|
||||
;; read-symbol-shorthands: (("t-" . "my-tricks-")
|
||||
;; ("sns-" . "some-nice-string-utils-"))
|
||||
;; End:
|
||||
@end example
|
||||
|
|
|
@ -548,7 +548,7 @@ in `completion-at-point-functions' (which see)."
|
|||
(lambda (s)
|
||||
(push s retval)
|
||||
(cl-loop
|
||||
for (shorthand . longhand) in elisp-shorthands
|
||||
for (shorthand . longhand) in read-symbol-shorthands
|
||||
for full-name = (symbol-name s)
|
||||
when (string-prefix-p longhand full-name)
|
||||
do (let ((sym (make-symbol
|
||||
|
@ -559,17 +559,17 @@ in `completion-at-point-functions' (which see)."
|
|||
(push sym retval)
|
||||
retval))))
|
||||
retval)))
|
||||
(cond ((null elisp-shorthands) obarray)
|
||||
(cond ((null read-symbol-shorthands) obarray)
|
||||
((and obarray-cache
|
||||
(gethash (cons (current-buffer) elisp-shorthands)
|
||||
(gethash (cons (current-buffer) read-symbol-shorthands)
|
||||
obarray-cache)))
|
||||
(obarray-cache
|
||||
(puthash (cons (current-buffer) elisp-shorthands)
|
||||
(puthash (cons (current-buffer) read-symbol-shorthands)
|
||||
(obarray-plus-shorthands)
|
||||
obarray-cache))
|
||||
(t
|
||||
(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-cache)))))
|
||||
|
||||
|
@ -2126,7 +2126,7 @@ Runs in a batch-mode Emacs. Interactively use variable
|
|||
(pp collected)))
|
||||
|
||||
|
||||
(put 'elisp-shorthands 'safe-local-variable #'consp)
|
||||
(put 'read-symbol-shorthands 'safe-local-variable #'consp)
|
||||
|
||||
(provide 'elisp-mode)
|
||||
;;; elisp-mode.el ends here
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
(require 'files)
|
||||
(eval-when-compile (require 'cl-lib))
|
||||
|
||||
(defun hack-elisp-shorthands (fullname)
|
||||
"Return value of `elisp-shorthands' file-local variable in FULLNAME.
|
||||
(defun hack-read-symbol-shorthands (fullname)
|
||||
"Return value of `read-symbol-shorthands' file-local variable in FULLNAME.
|
||||
FULLNAME is the absolute file name of an Elisp .el file which
|
||||
potentially specifies a file-local value for `elisp-shorthands'.
|
||||
The Elisp code in FULLNAME isn't read or evaluated in any way,
|
||||
except for extraction of the buffer-local value of
|
||||
`elisp-shorthands'."
|
||||
potentially specifies a file-local value for
|
||||
`read-symbol-shorthands'. The Elisp code in FULLNAME isn't read
|
||||
or evaluated in any way, except for extraction of the
|
||||
buffer-local value of `read-symbol-shorthands'."
|
||||
(let* ((size (nth 7 (file-attributes fullname)))
|
||||
(from (max 0 (- size 3000)))
|
||||
(to size))
|
||||
|
@ -49,13 +49,13 @@ except for extraction of the buffer-local value of
|
|||
;; detail of files.el. That function should be exported,
|
||||
;; possibly be refactored into two parts, since we're only
|
||||
;; 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)
|
||||
"Like `load-with-code-conversion', but also consider Elisp shorthands.
|
||||
This function uses shorthands defined in the file FULLNAME's local
|
||||
value of `elisp-shorthands', when it processes that file's Elisp code."
|
||||
(let ((elisp-shorthands (hack-elisp-shorthands fullname)))
|
||||
value of `read-symbol-shorthands', when it processes that file's Elisp code."
|
||||
(let ((read-symbol-shorthands (hack-read-symbol-shorthands fullname)))
|
||||
(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))))
|
||||
|
||||
(defun shorthands-font-lock-shorthands (limit)
|
||||
(when elisp-shorthands
|
||||
(when read-symbol-shorthands
|
||||
(while (re-search-forward
|
||||
(eval-when-compile
|
||||
(concat "\\_<\\(" lisp-mode-symbol-regexp "\\)\\_>"))
|
||||
|
|
26
src/lread.c
26
src/lread.c
|
@ -4626,29 +4626,29 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff
|
|||
return tem;
|
||||
}
|
||||
|
||||
/* Like 'oblookup', but considers 'Velisp_shorthands', potentially
|
||||
recognizing that IN is shorthand for some other longhand name,
|
||||
which is then then placed in OUT. In that case, memory is
|
||||
malloc'ed for OUT (which the caller must free) while SIZE_OUT and
|
||||
SIZE_BYTE_OUT respectively hold the character and byte sizes of the
|
||||
transformed symbol name. If IN is not recognized shorthand for any
|
||||
other symbol, OUT is set to point to NULL and 'oblookup' is
|
||||
called. */
|
||||
/* Like 'oblookup', but considers 'Vread_symbol_shorthands',
|
||||
potentially recognizing that IN is shorthand for some other
|
||||
longhand name, which is then then placed in OUT. In that case,
|
||||
memory is malloc'ed for OUT (which the caller must free) while
|
||||
SIZE_OUT and SIZE_BYTE_OUT respectively hold the character and byte
|
||||
sizes of the transformed symbol name. If IN is not recognized
|
||||
shorthand for any other symbol, OUT is set to point to NULL and
|
||||
'oblookup' is called. */
|
||||
|
||||
Lisp_Object
|
||||
oblookup_considering_shorthand (Lisp_Object obarray, const char *in,
|
||||
ptrdiff_t size, ptrdiff_t size_byte, char **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. */
|
||||
*out = NULL;
|
||||
/* Then, iterate each pair in Velisp_shorthands. */
|
||||
/* Then, iterate each pair in Vread_symbol_shorthands. */
|
||||
FOR_EACH_TAIL_SAFE (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
|
||||
to the next element. */
|
||||
if (!CONSP (pair))
|
||||
|
@ -5446,10 +5446,10 @@ that are loaded before your customizations are read! */);
|
|||
|
||||
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.
|
||||
This variable's value can only be set via file-local variables.
|
||||
See Info node `(elisp)Shorthands' for more details. */);
|
||||
Velisp_shorthands = Qnil;
|
||||
Vread_symbol_shorthands = Qnil;
|
||||
DEFSYM (Qobarray_cache, "obarray-cache");
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
(defun f-test ()
|
||||
(let ((elisp-shorthands '(("foo-" . "bar-"))))
|
||||
(let ((read-symbol-shorthands '(("foo-" . "bar-"))))
|
||||
(with-temp-buffer
|
||||
(insert "(foo-bar)")
|
||||
(goto-char (point-min))
|
||||
(read (current-buffer)))))
|
||||
|
||||
(defun f-test2 ()
|
||||
(let ((elisp-shorthands '(("foo-" . "bar-"))))
|
||||
(let ((read-symbol-shorthands '(("foo-" . "bar-"))))
|
||||
(read-from-string "(foo-bar)")))
|
||||
|
||||
|
||||
(defun f-test3 ()
|
||||
(let ((elisp-shorthands '(("foo-" . "bar-"))))
|
||||
(let ((read-symbol-shorthands '(("foo-" . "bar-"))))
|
||||
(intern "foo-bar")))
|
||||
|
||||
(defvar f-test-complete-me 42)
|
||||
|
@ -34,5 +34,5 @@
|
|||
|
||||
|
||||
;; Local Variables:
|
||||
;; elisp-shorthands: (("f-" . "elisp--foo-"))
|
||||
;; read-symbol-shorthands: (("f-" . "elisp--foo-"))
|
||||
;; End:
|
||||
|
|
|
@ -1026,7 +1026,7 @@ evaluation of BODY."
|
|||
(shorthand-sname (format "s-%s" gsym))
|
||||
(expected (intern (format "shorthand-longhand-%s" gsym))))
|
||||
(cl-assert (not (intern-soft shorthand-sname)))
|
||||
(should (equal (let ((elisp-shorthands
|
||||
(should (equal (let ((read-symbol-shorthands
|
||||
'(("s-" . "shorthand-longhand-"))))
|
||||
(with-temp-buffer
|
||||
(insert shorthand-sname)
|
||||
|
@ -1040,7 +1040,7 @@ evaluation of BODY."
|
|||
(shorthand-sname (format "s-%s" gsym))
|
||||
(expected (intern (format "shorthand-longhand-%s" gsym))))
|
||||
(cl-assert (not (intern-soft shorthand-sname)))
|
||||
(should (equal (let ((elisp-shorthands
|
||||
(should (equal (let ((read-symbol-shorthands
|
||||
'(("s-" . "shorthand-longhand-"))))
|
||||
(car (read-from-string shorthand-sname)))
|
||||
expected))
|
||||
|
|
Loading…
Add table
Reference in a new issue