diff options
author | Aaron Ecay <aaronecay@gmail.com> | 2016-09-03 01:55:45 +0100 |
---|---|---|
committer | Aaron Ecay <aaronecay@gmail.com> | 2016-09-03 01:55:45 +0100 |
commit | a3adfb062b2fb5da03813f898bb40543e91dc175 (patch) | |
tree | 7cc3264f34f89a0487c1b3e5d72db2256b6ba759 | |
parent | 79999af2646e9ce01db51272bcafeb9981a3381b (diff) | |
download | org-mode-a3adfb062b2fb5da03813f898bb40543e91dc175.tar.gz |
Introduce new function for removing paired delimiters from string.
* lisp/org-macs.el (org-unbracket-string): New function.
* lisp/ob-core.el (org-babel-strip-quotes):
* lisp/ob-lua.el (org-babel-lua-read-string):
* lisp/ox-beamer.el (org-beamer--normalize-argument): Use it.
-rw-r--r-- | lisp/ob-core.el | 5 | ||||
-rw-r--r-- | lisp/ob-lua.el | 4 | ||||
-rw-r--r-- | lisp/org-macs.el | 10 | ||||
-rw-r--r-- | lisp/ox-beamer.el | 19 |
4 files changed, 19 insertions, 19 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 47606da..ec9198a 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3084,10 +3084,7 @@ Callers of this function will probably want to add an entry to (defun org-babel-strip-quotes (string) "Strip \\\"s from around a string, if applicable." - (if (and (string-prefix-p "\"" string) - (string-suffix-p "\"" string)) - (substring string 1 -1) - string)) + (org-unbracket-string "\"" "\"" string)) (provide 'ob-core) diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el index 31c7671..5f9c7ef 100644 --- a/lisp/ob-lua.el +++ b/lisp/ob-lua.el @@ -394,9 +394,7 @@ fd:close()" (defun org-babel-lua-read-string (string) "Strip 's from around Lua string." - (if (string-match "^'\\([^\000]+\\)'$" string) - (match-string 1 string) - string)) + (org-unbracket-string "'" "'" string)) (provide 'ob-lua) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index f987428..7bb6d33 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -285,6 +285,16 @@ the value in cdr." "Load FILE with optional arguments NOERROR and MUSTSUFFIX." `(load ,file 'noerror nil nil 'mustsuffix)) +(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)) + (string-remove-prefix pre (string-remove-suffix post string)) + string)) + (provide 'org-macs) ;;; org-macs.el ends here diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el index 3b42f60..b9fc69c 100644 --- a/lisp/ox-beamer.el +++ b/lisp/ox-beamer.el @@ -203,18 +203,13 @@ TYPE is a symbol among the following: `option' Return ARGUMENT within square brackets." (if (not (string-match "\\S-" argument)) "" (cl-case type - (action (if (string-match "\\`<.*>\\'" argument) argument - (format "<%s>" argument))) - (defaction (cond - ((string-match "\\`\\[<.*>\\]\\'" argument) argument) - ((string-match "\\`<.*>\\'" argument) - (format "[%s]" argument)) - ((string-match "\\`\\[\\(.*\\)\\]\\'" argument) - (format "[<%s>]" (match-string 1 argument))) - (t (format "[<%s>]" argument)))) - (option (if (string-match "\\`\\[.*\\]\\'" argument) argument - (format "[%s]" argument))) - (otherwise argument)))) + (action (format "<%s>" (org-unbracket-string "<" ">" argument))) + (defaction + (format "[<%s>]" + (org-unbracket-string "<" ">" (org-unbracket-string "[" "]" argument)))) + (option (format "[%s]" (org-unbracket-string "[" "]" argument))) + (otherwise (error "Invalid `type' argument to `org-beamer--normalize-argument': %s" + type))))) (defun org-beamer--element-has-overlay-p (element) "Non-nil when ELEMENT has an overlay specified. |