mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-22 07:09:54 +00:00
Simplify hack-read-symbol-shorthands again (bug#50946)
* lisp/loadup.el (load-source-file-function): Don't set twice. * lisp/shorthands.el (hack-read-symbol-shorthands): Simplify. (load-with-shorthands-and-code-conversion): Remove. * lisp/international/mule.el (load-with-code-conversion): Call hack-read-symbol-shorthands-function. Set up shorthands. (hack-read-symbol-shorthands-function): New variable.
This commit is contained in:
parent
4831426158
commit
d3a832a61a
@ -294,6 +294,9 @@ attribute."
|
||||
|
||||
(apply 'define-charset-internal name (mapcar 'cdr attrs))))
|
||||
|
||||
(defvar hack-read-symbol-shorthands-function nil
|
||||
"Holds function to compute `read-symbol-shorthands'.")
|
||||
|
||||
(defun load-with-code-conversion (fullname file &optional noerror nomessage)
|
||||
"Execute a file of Lisp code named FILE whose absolute name is FULLNAME.
|
||||
The file contents are decoded before evaluation if necessary.
|
||||
@ -319,7 +322,8 @@ Return t if file exists."
|
||||
(let ((load-true-file-name fullname)
|
||||
(load-file-name fullname)
|
||||
(set-auto-coding-for-load t)
|
||||
(inhibit-file-name-operation nil))
|
||||
(inhibit-file-name-operation nil)
|
||||
shorthands)
|
||||
(with-current-buffer buffer
|
||||
;; So that we don't get completely screwed if the
|
||||
;; file is encoded in some complicated character set,
|
||||
@ -328,6 +332,13 @@ Return t if file exists."
|
||||
;; Don't let deactivate-mark remain set.
|
||||
(let (deactivate-mark)
|
||||
(insert-file-contents fullname))
|
||||
(setq shorthands
|
||||
;; We need this indirection because hacking local
|
||||
;; variables in too early seems to have cause
|
||||
;; recursive load loops (bug#50946). Thus it
|
||||
;; remains nil until it is save to do so.
|
||||
(and hack-read-symbol-shorthands-function
|
||||
(funcall hack-read-symbol-shorthands-function)))
|
||||
;; If the loaded file was inserted with no-conversion or
|
||||
;; raw-text coding system, make the buffer unibyte.
|
||||
;; Otherwise, eval-buffer might try to interpret random
|
||||
@ -338,11 +349,13 @@ Return t if file exists."
|
||||
(set-buffer-multibyte nil))
|
||||
;; Make `kill-buffer' quiet.
|
||||
(set-buffer-modified-p nil))
|
||||
;; Have the original buffer current while we eval.
|
||||
(eval-buffer buffer nil
|
||||
;; This is compatible with what `load' does.
|
||||
(if dump-mode file fullname)
|
||||
nil t))
|
||||
;; Have the original buffer current while we eval,
|
||||
;; but consider shorthands of the eval'ed one.
|
||||
(let ((read-symbol-shorthands shorthands))
|
||||
(eval-buffer buffer nil
|
||||
;; This is compatible with what `load' does.
|
||||
(if dump-mode file fullname)
|
||||
nil t)))
|
||||
(let (kill-buffer-hook kill-buffer-query-functions)
|
||||
(kill-buffer buffer)))
|
||||
(do-after-load-evaluation fullname)
|
||||
|
@ -355,7 +355,6 @@
|
||||
(load "paren")
|
||||
|
||||
(load "shorthands")
|
||||
(setq load-source-file-function #'load-with-shorthands-and-code-conversion)
|
||||
|
||||
(load "emacs-lisp/eldoc")
|
||||
(load "cus-start") ;Late to reduce customize-rogue (needs loaddefs.el anyway)
|
||||
|
@ -26,37 +26,18 @@
|
||||
|
||||
;;; Code:
|
||||
(require 'files)
|
||||
(require 'mule)
|
||||
(eval-when-compile (require 'cl-lib))
|
||||
|
||||
(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
|
||||
`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))
|
||||
(with-temp-buffer
|
||||
(while (and (< (buffer-size) 3000) (>= from 0))
|
||||
(insert-file-contents fullname nil from to)
|
||||
(setq to from
|
||||
from (cond
|
||||
((= from 0) -1)
|
||||
(t (max 0 (- from 100))))))
|
||||
;; FIXME: relies on the `hack-local-variables--find-variables'
|
||||
;; 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 'read-symbol-shorthands (hack-local-variables--find-variables)))))
|
||||
(defun hack-read-symbol-shorthands ()
|
||||
"Compute `read-symbol-shorthands' from Local Variables section."
|
||||
;; FIXME: relies on the `hack-local-variables--find-variables'
|
||||
;; 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 '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 `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)))
|
||||
(setq hack-read-symbol-shorthands-function #'hack-read-symbol-shorthands)
|
||||
|
||||
|
||||
;; FIXME: move this all to progmodes/elisp-mode.el? OTOH it'd make
|
||||
|
Loading…
Reference in New Issue
Block a user