macro: find-file non-literally, but start in fundamental-mode?

Lexically bind auto-mode-alist to nil, so emacs opens the file initially
in the global major-mode, which is traditionally fundamental-mode. cc @nobiot
This commit is contained in:
Jethro Kuan
2021-05-03 19:01:05 +08:00
parent 683605c813
commit 3d4c93a2a0

View File

@ -48,19 +48,19 @@ If FILE is nil, execute BODY in the current buffer.
Kills the buffer if KEEP-BUF-P is nil, and FILE is not yet visited." Kills the buffer if KEEP-BUF-P is nil, and FILE is not yet visited."
(declare (indent 2) (debug t)) (declare (indent 2) (debug t))
`(let* (new-buf `(let* (new-buf
(auto-mode-alist nil)
(buf (or (and (not ,file) (buf (or (and (not ,file)
(current-buffer)) ;If FILE is nil, use current buffer (current-buffer)) ;If FILE is nil, use current buffer
(find-buffer-visiting ,file) ; If FILE is already visited, find buffer (find-buffer-visiting ,file) ; If FILE is already visited, find buffer
(progn (progn
(setq new-buf t) (setq new-buf t)
(find-file-noselect ,file nil t)))) ; Else, visit FILE and return buffer (find-file-noselect ,file)))) ; Else, visit FILE and return buffer
res) res)
(with-current-buffer buf (with-current-buffer buf
(kill-local-variable 'buffer-file-coding-system)
(kill-local-variable 'find-file-literally)
(unless (equal major-mode 'org-mode) (unless (equal major-mode 'org-mode)
(delay-mode-hooks (delay-mode-hooks
(let ((org-inhibit-startup t)) (let ((org-inhibit-startup t)
(org-agenda-files nil))
(org-mode)))) (org-mode))))
(setq res (progn ,@body)) (setq res (progn ,@body))
(unless (and new-buf (not ,keep-buf-p)) (unless (and new-buf (not ,keep-buf-p))