summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-11-10 08:58:31 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-11-10 08:58:31 +0100
commitf5c2659bb86f3f9744c897b6f8f94825594e24a8 (patch)
tree2ff721f3b64e9e558dbf82a7c8c6112316bf2da1
parentfefe3d1a37d273297e539742f84c5e72427abaaf (diff)
downloadorg-mode-f5c2659bb86f3f9744c897b6f8f94825594e24a8.tar.gz
Use `org-strip-quote' when possible
* lisp/org-macs.el (org-unbracket-string): (org-strip-quotes): Allow nil values. * lisp/org-lint.el (org-lint-wrong-include-link-parameter): * lisp/org-macro.el (org-macro--collect-macros): * lisp/org.el (org--setup-collect-keywords): (org-edit-special): * lisp/ox.el (org-export--get-inbuffer-options): (org-export--list-bound-variables): (org-export-expand-include-keyword): Use `org-strip-quote' instead of `org-unbracket-string' whenever possible.
-rw-r--r--lisp/org-lint.el2
-rw-r--r--lisp/org-macro.el2
-rw-r--r--lisp/org-macs.el15
-rw-r--r--lisp/org.el38
-rw-r--r--lisp/ox.el13
5 files changed, 35 insertions, 35 deletions
diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index a311b1d..f22a6b3 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 ec686d9..10e35cc 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 c731cef..6da69c7 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 95cdd00..d57c1ab 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 45c9415..743fcd7 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-*\\)?"