summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustav Wikström <gustav@whil.se>2021-06-14 18:08:45 +0200
committerGustav Wikström <gustav@whil.se>2021-06-27 09:42:22 +0200
commitaa0fa8c75360d2aa491b9ae10e59d22de2aedc92 (patch)
tree4164e036b709c6b65b886acf0059c7ee63dd3e47
parent69a5591ad34af5a10bb801cff03a89720bef74a5 (diff)
downloadorg-mode-aa0fa8c75360d2aa491b9ae10e59d22de2aedc92.tar.gz
lisp/ox-publish.el: Speedup when looking for file changes
* lisp/ox-publish.el (org-publish-cache-file-needs-publishing): Speedup using delayed hooks and temp buffers instead of finding files.
-rw-r--r--lisp/ox-publish.el45
1 files changed, 22 insertions, 23 deletions
diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index b07f326..3b9666d 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -1290,29 +1290,28 @@ the file including them will be republished as well."
(org-inhibit-startup t)
included-files-ctime)
(when (equal (file-name-extension filename) "org")
- (let ((visiting (find-buffer-visiting filename))
- (buf (find-file-noselect filename))
- (case-fold-search t))
- (unwind-protect
- (with-current-buffer buf
- (goto-char (point-min))
- (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
- (let ((element (org-element-at-point)))
- (when (eq 'keyword (org-element-type element))
- (let* ((value (org-element-property :value element))
- (filename
- (and (string-match "\\`\\(\".+?\"\\|\\S-+\\)" value)
- (let ((m (org-strip-quotes
- (match-string 1 value))))
- ;; Ignore search suffix.
- (if (string-match "::.*?\\'" m)
- (substring m 0 (match-beginning 0))
- m)))))
- (when filename
- (push (org-publish-cache-ctime-of-src
- (expand-file-name filename))
- included-files-ctime)))))))
- (unless visiting (kill-buffer buf)))))
+ (let ((case-fold-search t))
+ (with-temp-buffer
+ (delay-mode-hooks
+ (org-mode)
+ (insert-file-contents filename)
+ (goto-char (point-min))
+ (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
+ (let ((element (org-element-at-point)))
+ (when (eq 'keyword (org-element-type element))
+ (let* ((value (org-element-property :value element))
+ (include-filename
+ (and (string-match "\\`\\(\".+?\"\\|\\S-+\\)" value)
+ (let ((m (org-strip-quotes
+ (match-string 1 value))))
+ ;; Ignore search suffix.
+ (if (string-match "::.*?\\'" m)
+ (substring m 0 (match-beginning 0))
+ m)))))
+ (when include-filename
+ (push (org-publish-cache-ctime-of-src
+ (expand-file-name include-filename (file-name-directory filename)))
+ included-files-ctime))))))))))
(or (null pstamp)
(let ((ctime (org-publish-cache-ctime-of-src filename)))
(or (time-less-p pstamp ctime)