Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2013-05-07 17:49:01 +02:00
commit 29ab1bb74e
1 changed files with 73 additions and 65 deletions

View File

@ -3256,73 +3256,81 @@ working directory. It is used to properly resolve relative
paths." paths."
(let ((case-fold-search t)) (let ((case-fold-search t))
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward "^[ \t]*#\\+INCLUDE: +\\(.*\\)[ \t]*$" nil t) (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
(when (eq (org-element-type (save-match-data (org-element-at-point))) (let ((element (save-match-data (org-element-at-point))))
'keyword) (when (eq (org-element-type element) 'keyword)
(beginning-of-line) (beginning-of-line)
;; Extract arguments from keyword's value. ;; Extract arguments from keyword's value.
(let* ((value (match-string 1)) (let* ((value (org-element-property :value element))
(ind (org-get-indentation)) (ind (org-get-indentation))
(file (and (string-match "^\"\\(\\S-+\\)\"" value) (file (let ((f (if (eq (aref value 0) ?\") (read value)
(prog1 (expand-file-name (match-string 1 value) dir) (and (string-match "^\\S-+" value)
(setq value (replace-match "" nil nil value))))) (match-string 0 value)))))
(lines (setq value
(and (string-match (progn
":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value) (string-match (format "^\"?%s\"?[ \t]*" f)
(prog1 (match-string 1 value) value)
(setq value (replace-match "" nil nil value))))) (replace-match "" nil nil value)))
(env (cond ((string-match "\\<example\\>" value) 'example) (expand-file-name f dir)))
((string-match "\\<src\\(?: +\\(.*\\)\\)?" value) (lines
(match-string 1 value)))) (and (string-match
;; Minimal level of included file defaults to the child ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\""
;; level of the current headline, if any, or one. It value)
;; only applies is the file is meant to be included as (prog1 (match-string 1 value)
;; an Org one. (setq value (replace-match "" nil nil value)))))
(minlevel (env (cond ((string-match "\\<example\\>" value) 'example)
(and (not env) ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
(if (string-match ":minlevel +\\([0-9]+\\)" value) (match-string 1 value))))
(prog1 (string-to-number (match-string 1 value)) ;; Minimal level of included file defaults to the child
(setq value (replace-match "" nil nil value))) ;; level of the current headline, if any, or one. It
(let ((cur (org-current-level))) ;; only applies is the file is meant to be included as
(if cur (1+ (org-reduced-level cur)) 1)))))) ;; an Org one.
;; Remove keyword. (minlevel
(delete-region (point) (progn (forward-line) (point))) (and (not env)
(cond (if (string-match ":minlevel +\\([0-9]+\\)" value)
((not file) (error "Invalid syntax in INCLUDE keyword")) (prog1 (string-to-number (match-string 1 value))
((not (file-readable-p file)) (error "Cannot include file %s" file)) (setq value (replace-match "" nil nil value)))
;; Check if files has already been parsed. Look after (let ((cur (org-current-level)))
;; inclusion lines too, as different parts of the same file (if cur (1+ (org-reduced-level cur)) 1))))))
;; can be included too. ;; Remove keyword.
((member (list file lines) included) (delete-region (point) (progn (forward-line) (point)))
(error "Recursive file inclusion: %s" file))
(t
(cond (cond
((eq env 'example) ((not file) nil)
(insert ((not (file-readable-p file))
(let ((ind-str (make-string ind ? )) (error "Cannot include file %s" file))
(contents ;; Check if files has already been parsed. Look after
(org-escape-code-in-string ;; inclusion lines too, as different parts of the same file
(org-export--prepare-file-contents file lines)))) ;; can be included too.
(format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n" ((member (list file lines) included)
ind-str contents ind-str)))) (error "Recursive file inclusion: %s" file))
((stringp env)
(insert
(let ((ind-str (make-string ind ? ))
(contents
(org-escape-code-in-string
(org-export--prepare-file-contents file lines))))
(format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
ind-str env contents ind-str))))
(t (t
(insert (cond
(with-temp-buffer ((eq env 'example)
(let ((org-inhibit-startup t)) (org-mode)) (insert
(insert (let ((ind-str (make-string ind ? ))
(org-export--prepare-file-contents file lines ind minlevel)) (contents
(org-export-expand-include-keyword (org-escape-code-in-string
(cons (list file lines) included) (org-export--prepare-file-contents file lines))))
(file-name-directory file)) (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
(buffer-string)))))))))))) ind-str contents ind-str))))
((stringp env)
(insert
(let ((ind-str (make-string ind ? ))
(contents
(org-escape-code-in-string
(org-export--prepare-file-contents file lines))))
(format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
ind-str env contents ind-str))))
(t
(insert
(with-temp-buffer
(let ((org-inhibit-startup t)) (org-mode))
(insert
(org-export--prepare-file-contents file lines ind minlevel))
(org-export-expand-include-keyword
(cons (list file lines) included)
(file-name-directory file))
(buffer-string)))))))))))))
(defun org-export--prepare-file-contents (file &optional lines ind minlevel) (defun org-export--prepare-file-contents (file &optional lines ind minlevel)
"Prepare the contents of FILE for inclusion and return them as a string. "Prepare the contents of FILE for inclusion and return them as a string.