diff options
author | João Távora <joaotavora@gmail.com> | 2020-09-19 22:16:38 +0100 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2021-09-27 01:07:11 +0100 |
commit | 71857d410635743d437ce1ee73dff69de50030d6 (patch) | |
tree | fa5491b2f0c8106dfbc3efaa6e01d363871eefef /lisp/international/mule.el | |
parent | 6237bad419a23fcbefb2c33728522b1bb52cb557 (diff) | |
download | emacs-71857d410635743d437ce1ee73dff69de50030d6.tar.gz |
Move most of the shorthand implementation to C code
It passes the tests designed for the previous Elisp implementation.
Likely, this isn't the final form of the implementation. For one, the
reader is much slower and allocates a Lisp string for every atom read,
regardless if its already interned or not. This has the potential to
be catastrophic in terms of GC.
Also rename the main variable to elisp-shorthands, from the
repetitive shorthand-shorthands.
For some reason, I had to put 'hack-elisp-shorthands' and
'load-with-shorthands-and-code-conversion', the new source-file
loading functions, in lisp/international/mule.el.
Otherwise, lisp/loadup.el wouldn't see them, for some reason that I
didn't investigate. This should probably be fixed.
* lisp/shorthand.el: Remove.
* test/lisp/shorthand-tests.el: Remove.
* src/lread.c:
(read1, Fintern, Fintern_soft, Funintern): Use
oblookup_considering_shorthand.
(oblookup_considering_shorthand): New helper.
(syms_of_lread): Declare elisp-shorthands.
* lisp/progmodes/elisp-mode.el (elisp-shorthands):
Put a safe-local-variable spec.
* test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-read-buffer)
(elisp-shorthand-read-from-string)
(elisp-shorthand-byte-compile-a-file)
(elisp-shorthand-load-a-file): New tests.
* test/lisp/progmodes/elisp-resources/simple-shorthand-test.el: New file
* lisp/loadup.el (load-source-file-function): Set to
load-with-shorthands-and-code-conversion.
* lisp/international/mule.el (hack-elisp-shorthands): Move here.
(load-with-shorthands-and-code-conversion): And here.
Diffstat (limited to 'lisp/international/mule.el')
-rw-r--r-- | lisp/international/mule.el | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el index ee116976eaa..deb801ff1af 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el @@ -294,6 +294,31 @@ attribute." (apply 'define-charset-internal name (mapcar 'cdr attrs)))) +(defun hack-elisp-shorthands (fullname) + "Return value of the `elisp-shorthands' file-local variable in FULLNAME. +FULLNAME is the full name of an Elisp file which potentially +specifies a file-local value for `elisp-shorthands'. The Elisp +code isn't read or evaluated in any way, we merely extract what +the buffer-local value of `elisp-shorthands' would be if the file +had been found by `find-file'." + (let ((size (nth 7 (file-attributes fullname)))) + (with-temp-buffer + (insert-file-contents fullname nil (max 0 (- size 3000)) size) + (goto-char (point-max)) + (let* ((found (search-backward-regexp "elisp-shorthands:[ \t]*" 0 t)) + (val (and found + (goto-char (match-end 0)) + (ignore-errors (read (current-buffer))))) + (probe val) + aux) + (catch 'done + (when (consp probe) + (while (setq aux (pop probe)) + (unless (and (consp aux) + (stringp (car aux)) + (stringp (cdr aux))) + (throw 'done nil))) + val)))))) (defun load-with-code-conversion (fullname file &optional noerror nomessage) "Execute a file of Lisp code named FILE whose absolute name is FULLNAME. @@ -354,6 +379,11 @@ Return t if file exists." (message "Loading %s...done" file))) t))) +(defun load-with-shorthands-and-code-conversion (fullname file noerror nomessage) + "As `load-with-code-conversion', also considering Elisp shorthands." + (let ((elisp-shorthands (hack-elisp-shorthands fullname))) + (load-with-code-conversion fullname file noerror nomessage))) + (defun charset-info (charset) "Return a vector of information of CHARSET. This function is provided for backward compatibility. |