ox-publish: Fix too many opened buffer upon publishing

* lisp/ox-publish.el (org-publish-cache-file-needs-publishing): Create
  a new buffer for Org files only.

Reported-by: Éric Würbel <eric.wurbel@univ-amu.fr>
<http://permalink.gmane.org/gmane.emacs.orgmode/110190>
This commit is contained in:
Nicolas Goaziou 2016-11-11 00:45:21 +01:00
parent dd2a0d3361
commit c6f9aeb06e
1 changed files with 28 additions and 29 deletions

View File

@ -1199,39 +1199,38 @@ the file including them will be republished as well."
(unless org-publish-cache (unless org-publish-cache
(error (error
"`org-publish-cache-file-needs-publishing' called, but no cache present")) "`org-publish-cache-file-needs-publishing' called, but no cache present"))
(let* ((case-fold-search t) (let* ((key (org-publish-timestamp-filename filename pub-dir pub-func))
(key (org-publish-timestamp-filename filename pub-dir pub-func))
(pstamp (org-publish-cache-get key)) (pstamp (org-publish-cache-get key))
(org-inhibit-startup t) (org-inhibit-startup t)
(visiting (find-buffer-visiting filename))
(buf (find-file-noselect (expand-file-name filename)))
included-files-ctime) included-files-ctime)
(when (equal (file-name-extension filename) "org") (when (equal (file-name-extension filename) "org")
(unwind-protect (let ((visiting (find-buffer-visiting filename))
(with-current-buffer buf (buf (find-file-noselect filename))
(goto-char (point-min)) (case-fold-search t))
(while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t) (unwind-protect
(let* ((element (org-element-at-point)) (with-current-buffer buf
(included-file (goto-char (point-min))
(and (eq (org-element-type element) 'keyword) (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
(let ((value (org-element-property :value element))) (let* ((element (org-element-at-point))
(and value (included-file
(string-match (and (eq (org-element-type element) 'keyword)
"\\`\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" (let ((value (org-element-property :value element)))
value) (and value
(let ((m (match-string 1 value))) (string-match
(org-unbracket-string "\\`\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)"
"\"" "\"" value)
;; Ignore search suffix. (let ((m (match-string 1 value)))
(if (string-match "\\(::\\(.*?\\)\\)\"?\\'" (org-unbracket-string
m) "\"" "\""
(substring m 0 (match-beginning 0)) ;; Ignore search suffix.
m)))))))) (if (string-match "::.*?\"?\\'" m)
(when included-file (substring m 0 (match-beginning 0))
(push (org-publish-cache-ctime-of-src m))))))))
(expand-file-name included-file)) (when included-file
included-files-ctime))))) (push (org-publish-cache-ctime-of-src
(unless visiting (kill-buffer buf)))) (expand-file-name included-file))
included-files-ctime)))))
(unless visiting (kill-buffer buf)))))
(or (null pstamp) (or (null pstamp)
(let ((ctime (org-publish-cache-ctime-of-src filename))) (let ((ctime (org-publish-cache-ctime-of-src filename)))
(or (< pstamp ctime) (or (< pstamp ctime)