diff --git a/lisp/org-lint.el b/lisp/org-lint.el index a311b1d02..f22a6b3e2 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -589,7 +589,7 @@ Use :header-args: instead" (path (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value) (save-match-data - (org-unbracket-string "\"" "\"" (match-string 1 value)))))) + (org-strip-quotes (match-string 1 value)))))) (if (not path) (list (org-element-property :post-affiliated k) "Missing location argument in INCLUDE keyword") diff --git a/lisp/org-macro.el b/lisp/org-macro.el index ec686d9c5..10e35cc3e 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -110,7 +110,7 @@ Return an alist containing all macro templates found." (if old-cell (setcdr old-cell template) (push (cons name template) templates)))) ;; Enter setup file. - (let* ((uri (org-unbracket-string "\"" "\"" (org-trim val))) + (let* ((uri (org-strip-quotes (org-trim val))) (uri-is-url (org-file-url-p uri)) (uri (if uri-is-url uri diff --git a/lisp/org-macs.el b/lisp/org-macs.el index c731cef08..6da69c75d 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -899,14 +899,17 @@ Otherwise return nil." (defun org-unbracket-string (pre post string) "Remove PRE/POST from the beginning/end of STRING. Both PRE and POST must be pre-/suffixes of STRING, or neither is -removed." - (if (and (string-prefix-p pre string) - (string-suffix-p post string)) - (substring string (length pre) (- (length post))) - string)) +removed. Return the new string. If STRING is nil, return nil." + (declare (indent 2)) + (and string + (if (and (string-prefix-p pre string) + (string-suffix-p post string)) + (substring string (length pre) (- (length post))) + string))) (defun org-strip-quotes (string) - "Strip double quotes from around a string, if applicable." + "Strip double quotes from around STRING, if applicable. +If STRING is nil, return nil." (org-unbracket-string "\"" "\"" string)) (defsubst org-current-line-string (&optional to-here) diff --git a/lisp/org.el b/lisp/org.el index 95cdd0000..d57c1ab58 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5173,8 +5173,7 @@ Return value contains the following keys: `archive', `category', ((equal key "SETUPFILE") (unless buffer-read-only ; Do not check in Gnus messages. (let ((f (and (org-string-nw-p value) - (expand-file-name - (org-unbracket-string "\"" "\"" value))))) + (expand-file-name (org-strip-quotes value))))) (when (and f (file-readable-p f) (not (member f files))) (with-temp-buffer (setq default-directory (file-name-directory f)) @@ -20084,28 +20083,27 @@ Otherwise, return a user error." (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) - ;; At a src-block with a session and function called with - ;; an ARG: switch to the buffer related to the inferior - ;; process. + ;; At a source block with a session and function called + ;; with an ARG: switch to the buffer related to the + ;; inferior process. (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) (`keyword - (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) - (org-open-link-from-string - (format "[[%s]]" - (expand-file-name - (let ((value (org-element-property :value element))) - (cond ((org-file-url-p value) - (user-error "The file is specified as a URL, cannot be edited")) - ((not (org-string-nw-p value)) - (user-error "No file to edit")) - ((string-match "\\`\"\\(.*?\\)\"" value) - (match-string 1 value)) - ((string-match "\\`[^ \t\"]\\S-*" value) - (match-string 0 value)) - (t (user-error "No valid file specified"))))))) - (user-error "No special environment to edit here"))) + (unless (member (org-element-property :key element) + '("INCLUDE" "SETUPFILE")) + (user-error "No special environment to edit here")) + (org-open-link-from-string + (format "[[%s]]" + (expand-file-name + (let ((value (org-strip-quotes + (org-element-property :value element)))) + (cond + ((not (org-string-nw-p value)) + (user-error "No file to edit")) + ((org-file-url-p value) + (user-error "Files located with a URL cannot be edited")) + (t value))))))) (`table (if (eq (org-element-property :type element) 'table.el) (org-edit-table.el) diff --git a/lisp/ox.el b/lisp/ox.el index 45c94159a..743fcd772 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -1499,7 +1499,7 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored." (cond ;; Options in `org-export-special-keywords'. ((equal key "SETUPFILE") - (let* ((uri (org-unbracket-string "\"" "\"" (org-trim val))) + (let* ((uri (org-strip-quotes (org-trim val))) (uri-is-url (org-file-url-p uri)) (uri (if uri-is-url uri @@ -1650,7 +1650,7 @@ an alist where associations are (VARIABLE-NAME VALUE)." "BIND") (push (read (format "(%s)" val)) alist) ;; Enter setup file. - (let* ((uri (org-unbracket-string "\"" "\"" val)) + (let* ((uri (org-strip-quotes val)) (uri-is-url (org-file-url-p uri)) (uri (if uri-is-url uri @@ -3283,8 +3283,8 @@ storing and resolving footnotes. It is created automatically." (ind (current-indentation)) location (file - (and (string-match - "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value) + (and (string-match "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" + value) (prog1 (save-match-data (let ((matched (match-string 1 value))) @@ -3293,9 +3293,8 @@ storing and resolving footnotes. It is created automatically." (setq location (match-string 2 matched)) (setq matched (replace-match "" nil nil matched 1))) - (expand-file-name - (org-unbracket-string "\"" "\"" matched) - dir))) + (expand-file-name (org-strip-quotes matched) + dir))) (setq value (replace-match "" nil nil value))))) (only-contents (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"