(defvar hack-read-symbol-shorthands-function nil
"Holds function to compute `read-symbol-shorthands'.")
-(defun load-with-code-conversion (fullname file &optional noerror nomessage)
+(defun load-with-code-conversion (fullname file &optional noerror nomessage
+ eval-function)
"Execute a file of Lisp code named FILE whose absolute name is FULLNAME.
The file contents are decoded before evaluation if necessary.
-If optional third arg NOERROR is non-nil,
- report no error if FILE doesn't exist.
-Print messages at start and end of loading unless
- optional fourth arg NOMESSAGE is non-nil.
+
+If optional third arg NOERROR is non-nil, report no error if FILE
+doesn't exist.
+
+Print messages at start and end of loading unless optional fourth
+arg NOMESSAGE is non-nil.
+
+If EVAL-FUNCTION, call that instead of calling `eval-buffer'
+directly. It is called with two paramameters: The buffer object
+and the file name.
+
Return t if file exists."
(if (null (file-readable-p fullname))
(and (null noerror)
;; 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)))
+ (if eval-function
+ (funcall eval-function buffer
+ (if dump-mode file fullname))
+ (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)
;; actually exist on some systems.
(when (file-exists-p truename)
(setq file-ex truename))
- (load file-ex nil t t)))
+ (command-line--load-script file-ex)))
((equal argi "-insert")
(setq inhibit-startup-screen t)
(display-startup-screen (> displayable-buffers-len 0))))))
+(defun command-line--load-script (file)
+ (load-with-code-conversion
+ file file nil nil
+ (lambda (buffer file)
+ (with-current-buffer buffer
+ (goto-char (point-min))
+ ;; Removing the #! and then calling `eval-buffer' will make the
+ ;; reader not signal an error if it then turns out that the
+ ;; buffer is empty.
+ (when (looking-at "#!")
+ (delete-line))
+ (eval-buffer buffer nil file nil t)))))
+
(defun command-line-normalize-file-name (file)
"Collapse multiple slashes to one, to handle non-Emacs file names."
(save-match-data