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
(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
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
(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
(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)))))
(pp collected)))
\f
-(put 'elisp-shorthands 'safe-local-variable #'consp)
+(put 'read-symbol-shorthands 'safe-local-variable #'consp)
(provide 'elisp-mode)
;;; elisp-mode.el ends here
(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))
;; 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)))
\f
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 "\\)\\_>"))
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))
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");
}
(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)
;; Local Variables:
-;; elisp-shorthands: (("f-" . "elisp--foo-"))
+;; read-symbol-shorthands: (("f-" . "elisp--foo-"))
;; End:
(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)
(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))