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.
This commit is contained in:
Aaron Ecay 2016-09-03 01:55:45 +01:00
parent 79999af264
commit a3adfb062b
4 changed files with 19 additions and 19 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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.