Fix #3685: don't mutate org buffer when tangling

If the buffer doesn't change, the cursor won't move.
This commit is contained in:
Henrik Lissner 2020-08-04 13:43:14 -04:00
parent 9f84bc334b
commit 8580b53e8e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -16,8 +16,7 @@ byte-compiled from.")
(print-group! (print-group!
(let* ((default-directory doom-private-dir) (let* ((default-directory doom-private-dir)
(org (expand-file-name +literate-config-file)) (org (expand-file-name +literate-config-file))
(dest (concat (file-name-sans-extension +literate-config-file) ".el")) (dest (concat (file-name-sans-extension +literate-config-file) ".el")))
(backup (make-temp-file "config.org.backup")))
(and (require 'ox) (and (require 'ox)
(require 'ob-tangle) (require 'ob-tangle)
(unwind-protect (unwind-protect
@ -26,18 +25,18 @@ byte-compiled from.")
(print! (info "%s") (apply #'format msg args)))) (print! (info "%s") (apply #'format msg args))))
;; Prevent infinite recursion due to recompile-on-save ;; Prevent infinite recursion due to recompile-on-save
;; hooks later. ;; hooks later.
(org-mode-hook nil)) (org-mode-hook nil)
;; Do the ol' switcheroo because `org-babel-tangle' writes ;; Operate on a copy because `org-babel-tangle' has
;; changes to the user's literate config, which would impose on ;; side-effects we don't want to impose on the User's
;; the user. ;; config permanently.
(backup (make-temp-file (concat (file-name-nondirectory org) "."))))
(copy-file org backup t) (copy-file org backup t)
(with-current-buffer (find-file-noselect org) (with-current-buffer (find-file-noselect backup)
;; Tangling won't ordinarily expand #+INCLUDE directives, so ;; Tangling won't ordinarily expand #+INCLUDE directives
;; we do it ourselves.
(org-export-expand-include-keyword) (org-export-expand-include-keyword)
(org-babel-tangle nil dest)) (org-babel-tangle nil dest)
(kill-buffer (current-buffer)))
t) t)
(ignore-errors (copy-file backup org t))
(ignore-errors (delete-file backup))) (ignore-errors (delete-file backup)))
;; Write an empty file to serve as our mtime cache ;; Write an empty file to serve as our mtime cache
(with-temp-file +literate-config-cache-file))))) (with-temp-file +literate-config-cache-file)))))