mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-28 10:56:57 +00:00
org-export: Explicit error when using invalid syntax for INCLUDE keywords
* contrib/lisp/org-export.el (org-export-expand-include-keyword): Error out when file isn't specified within double quotes. * testing/lisp/test-org-export.el: Add test.
This commit is contained in:
parent
99110c60a6
commit
a8c026cb26
@ -2771,7 +2771,7 @@ 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: \\(.*\\)" nil t)
|
(while (re-search-forward "^[ \t]*#\\+INCLUDE: +\\(.*\\)[ \t]*$" nil t)
|
||||||
(when (eq (org-element-type (save-match-data (org-element-at-point)))
|
(when (eq (org-element-type (save-match-data (org-element-at-point)))
|
||||||
'keyword)
|
'keyword)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
@ -2803,6 +2803,7 @@ paths."
|
|||||||
;; Remove keyword.
|
;; Remove keyword.
|
||||||
(delete-region (point) (progn (forward-line) (point)))
|
(delete-region (point) (progn (forward-line) (point)))
|
||||||
(cond
|
(cond
|
||||||
|
((not file) (error "Invalid syntax in INCLUDE keyword"))
|
||||||
((not (file-readable-p file)) (error "Cannot include file %s" file))
|
((not (file-readable-p file)) (error "Cannot include file %s" file))
|
||||||
;; Check if files has already been parsed. Look after
|
;; Check if files has already been parsed. Look after
|
||||||
;; inclusion lines too, as different parts of the same file
|
;; inclusion lines too, as different parts of the same file
|
||||||
|
@ -386,6 +386,10 @@ text
|
|||||||
|
|
||||||
(ert-deftest test-org-export/expand-include ()
|
(ert-deftest test-org-export/expand-include ()
|
||||||
"Test file inclusion in an Org buffer."
|
"Test file inclusion in an Org buffer."
|
||||||
|
;; Error when file isn't specified.
|
||||||
|
(should-error
|
||||||
|
(org-test-with-temp-text "#+INCLUDE: dummy.org"
|
||||||
|
(org-export-expand-include-keyword)))
|
||||||
;; Full insertion with recursive inclusion.
|
;; Full insertion with recursive inclusion.
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
(format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
|
(format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
|
||||||
|
Loading…
Reference in New Issue
Block a user