ox: Tolerate included file names without double quotes

* lisp/ox.el (org-export-expand-include-keyword): Tolerate included
  file names without double quotes.
This commit is contained in:
Nicolas Goaziou 2013-05-07 17:47:59 +02:00
parent 0df6bcdf2a
commit bd27a005bb
1 changed files with 73 additions and 65 deletions

View File

@ -3256,19 +3256,26 @@ working directory. It is used to properly resolve relative
paths."
(let ((case-fold-search t))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#\\+INCLUDE: +\\(.*\\)[ \t]*$" nil t)
(when (eq (org-element-type (save-match-data (org-element-at-point)))
'keyword)
(while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
(let ((element (save-match-data (org-element-at-point))))
(when (eq (org-element-type element) 'keyword)
(beginning-of-line)
;; Extract arguments from keyword's value.
(let* ((value (match-string 1))
(let* ((value (org-element-property :value element))
(ind (org-get-indentation))
(file (and (string-match "^\"\\(\\S-+\\)\"" value)
(prog1 (expand-file-name (match-string 1 value) dir)
(setq value (replace-match "" nil nil value)))))
(file (let ((f (if (eq (aref value 0) ?\") (read value)
(and (string-match "^\\S-+" value)
(match-string 0 value)))))
(setq value
(progn
(string-match (format "^\"?%s\"?[ \t]*" f)
value)
(replace-match "" nil nil value)))
(expand-file-name f dir)))
(lines
(and (string-match
":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
value)
(prog1 (match-string 1 value)
(setq value (replace-match "" nil nil value)))))
(env (cond ((string-match "\\<example\\>" value) 'example)
@ -3288,8 +3295,9 @@ paths."
;; Remove keyword.
(delete-region (point) (progn (forward-line) (point)))
(cond
((not file) (error "Invalid syntax in INCLUDE keyword"))
((not (file-readable-p file)) (error "Cannot include file %s" file))
((not file) nil)
((not (file-readable-p file))
(error "Cannot include file %s" file))
;; Check if files has already been parsed. Look after
;; inclusion lines too, as different parts of the same file
;; can be included too.
@ -3322,7 +3330,7 @@ paths."
(org-export-expand-include-keyword
(cons (list file lines) included)
(file-name-directory file))
(buffer-string))))))))))))
(buffer-string)))))))))))))
(defun org-export--prepare-file-contents (file &optional lines ind minlevel)
"Prepare the contents of FILE for inclusion and return them as a string.