summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ecay <aaronecay@gmail.com>2016-09-03 02:05:10 +0100
committerAaron Ecay <aaronecay@gmail.com>2016-09-03 02:05:10 +0100
commit1c18efb6152c9faeec381ca9de456fcdd4a519be (patch)
treee40c011e041dcbba5e500e1c836896144deb5b2b
parentc997bf7ff1f2cfc7ecf4dee85ef4e9c4dc1be03a (diff)
downloadorg-mode-1c18efb6152c9faeec381ca9de456fcdd4a519be.tar.gz
String handling improvements.
* lisp/org-agenda.el (org-agenda-export-csv-mapper): Use `replace-regexp-in-string'. * lisp/org-capture.el (org-capture): Use `string-prefix-p'. * lisp/org-compat.el (string-blank-p, string-remove-prefix): * lisp/org-compat.el (string-remove-suffix): Add compatibility defuns for emacs 24.3. * lisp/org-datetree.el (org-datetree-cleanup): Use `string-suffix-p'. * lisp/org-footnote.el (org-footnote-normalize-label): Use `string-remove-prefix'. * lisp/org-gnus.el (org-gnus-group-link): Use `string-prefix-p'. * lisp/org-list.el (org-list-struct): (org-list-get-list-type, org-list-send-item): (org-list-use-alpha-bul-p): Use `string-match-p'. * lisp/org.el (org-paste-subtree): Use `string-suffix-p'. (org-open-file, org-refile-get-targets): Use `replace-regexp-in-string'. (org-make-tags-matcher): Use `string-prefix-p'. (org-set-tags): Use `string-(prefix,suffix)-p'. * lisp/ox-beamer.el (org-beamer--element-has-overlay-p): (org-beamer--format-block): Use `string-(prefix,suffix)-p'. * lisp/ox-html.el (org-html-fix-class-name): Use `replace-regexp-in-string'. * lisp/ox-md.el (org-md-verbatim): Use `string-(prefix,suffix)-p'. (org-md-paragraph): Use `string-prefix-p'.
-rw-r--r--lisp/org-agenda.el4
-rw-r--r--lisp/org-capture.el2
-rw-r--r--lisp/org-compat.el18
-rw-r--r--lisp/org-datetree.el2
-rw-r--r--lisp/org-footnote.el6
-rw-r--r--lisp/org-gnus.el2
-rw-r--r--lisp/org-list.el8
-rw-r--r--lisp/org.el23
-rw-r--r--lisp/ox-beamer.el6
-rw-r--r--lisp/ox-html.el5
-rw-r--r--lisp/ox-md.el8
11 files changed, 46 insertions, 38 deletions
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 842c744..0878449 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3255,9 +3255,7 @@ This ensures the export commands can easily use it."
((not res) "")
((stringp res) res)
(t (prin1-to-string res))))
- (while (string-match "," res)
- (setq res (replace-match ";" t t res)))
- (org-trim res)))
+ (org-trim (replace-regexp-in-string "," ";" res nil t))))
;;;###autoload
(defun org-store-agenda-views (&rest parameters)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 34ac854..70111f9 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -628,7 +628,7 @@ of the day at point (if any) or the current HH:MM time."
(equal (car (org-capture-get :target)) 'function))
((error quit)
(if (and (buffer-base-buffer (current-buffer))
- (string-match "\\`CAPTURE-" (buffer-name)))
+ (string-prefix-p "CAPTURE-" (buffer-name)))
(kill-buffer (current-buffer)))
(set-window-configuration (org-capture-get :return-to-wconf))
(error "Capture template `%s': %s"
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 2c41c50..a9ade38 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -430,7 +430,23 @@ attention to case differences."
(let ((start-pos (- (length string) (length suffix))))
(and (>= start-pos 0)
(eq t (compare-strings suffix nil nil
- string start-pos nil ignore-case))))))
+ string start-pos nil ignore-case)))))
+
+ (defsubst string-blank-p (string)
+ "Check whether STRING is either empty or only whitespace."
+ (string-match-p "\\`[ \t\n\r]*\\'" string))
+
+ (defsubst string-remove-prefix (prefix string)
+ "Remove PREFIX from STRING if present."
+ (if (string-prefix-p prefix string)
+ (substring string (length prefix))
+ string))
+
+ (defsubst string-remove-suffix (suffix string)
+ "Remove SUFFIX from STRING if present."
+ (if (string-suffix-p suffix string)
+ (substring string 0 (- (length string) (length suffix)))
+ string)))
(provide 'org-compat)
diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el
index 9133b1c..2a921bf 100644
--- a/lisp/org-datetree.el
+++ b/lisp/org-datetree.el
@@ -192,7 +192,7 @@ before running this command, even though the command tries to be smart."
(max (line-beginning-position)
(- (match-beginning 0) org-ds-keyword-length))
(match-beginning 0))))
- (when (or (string-match "-\\'" tmp)
+ (when (or (string-suffix-p "-" tmp)
(string-match dre tmp)
(string-match sre tmp))
(throw 'next nil))
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 5a6e05c..40c7e1f 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -563,10 +563,8 @@ value if point was successfully moved."
If LABEL is the empty string or constituted of white spaces only,
return nil instead."
(let ((label (org-trim label)))
- (cond
- ((equal "" label) nil)
- ((string-match "\\`fn:" label) (replace-match "" nil nil label))
- (t label))))
+ (unless (equal "" label)
+ (string-remove-prefix "fn:" label))))
(defun org-footnote-get-definition (label)
"Return label, boundaries and definition of the footnote LABEL."
diff --git a/lisp/org-gnus.el b/lisp/org-gnus.el
index 9408f01..67fb396 100644
--- a/lisp/org-gnus.el
+++ b/lisp/org-gnus.el
@@ -107,7 +107,7 @@ Otherwise create a link to the group inside Gnus.
If `org-store-link' was called with a prefix arg the meaning of
`org-gnus-prefer-web-links' is reversed."
(let ((unprefixed-group (replace-regexp-in-string "^[^:]+:" "" group)))
- (if (and (string-match "^nntp" group) ;; Only for nntp groups
+ (if (and (string-prefix-p "nntp" group) ;; Only for nntp groups
(org-xor current-prefix-arg
org-gnus-prefer-web-links))
(concat (if (string-match "gmane" unprefixed-group)
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 067f455..0440496 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -658,7 +658,7 @@ Assume point is at an item."
(match-string-no-properties 2) ; counter
(match-string-no-properties 3) ; checkbox
;; Description tag.
- (and (save-match-data (string-match "[-+*]" bullet))
+ (and (string-match-p "[-+*]" bullet)
(match-string-no-properties 4)))))))
(end-before-blank
(function
@@ -1025,7 +1025,7 @@ Possible types are `descriptive', `ordered' and `unordered'. The
type is determined by the first item of the list."
(let ((first (org-list-get-list-begin item struct prevs)))
(cond
- ((string-match "[[:alnum:]]" (org-list-get-bullet first struct)) 'ordered)
+ ((string-match-p "[[:alnum:]]" (org-list-get-bullet first struct)) 'ordered)
((org-list-get-tag first struct) 'descriptive)
(t 'unordered))))
@@ -1471,7 +1471,7 @@ This function returns, destructively, the new list structure."
(save-excursion
(goto-char (org-list-get-last-item item struct prevs))
(point-at-eol)))
- ((string-match "\\`[0-9]+\\'" dest)
+ ((string-match-p "\\`[0-9]+\\'" dest)
(let* ((all (org-list-get-all-items item struct prevs))
(len (length all))
(index (mod (string-to-number dest) len)))
@@ -1645,7 +1645,7 @@ as returned by `org-list-prevs-alist'."
(while item
(let ((count (org-list-get-counter item struct)))
;; Virtually determine current bullet
- (if (and count (string-match "[a-zA-Z]" count))
+ (if (and count (string-match-p "[a-zA-Z]" count))
;; Counters are not case-sensitive.
(setq ascii (string-to-char (upcase count)))
(setq ascii (1+ ascii)))
diff --git a/lisp/org.el b/lisp/org.el
index 83d8aac..fae497d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8803,7 +8803,7 @@ When REMOVE is non-nil, remove the subtree from the clipboard."
(setq beg (point))
(and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
(insert-before-markers txt)
- (unless (string-match "\n\\'" txt) (insert "\n"))
+ (unless (string-suffix-p "\n" txt) (insert "\n"))
(setq newend (point))
(org-reinstall-markers-in-region beg)
(setq end (point))
@@ -11486,12 +11486,11 @@ If the file does not exist, an error is thrown."
;; Remove quotes around the file name - we'll use shell-quote-argument.
(while (string-match "['\"]%s['\"]" cmd)
(setq cmd (replace-match "%s" t t cmd)))
- (while (string-match "%s" cmd)
- (setq cmd (replace-match
- (save-match-data
- (shell-quote-argument
- (convert-standard-filename file)))
- t t cmd)))
+ (setq cmd (replace-regexp-in-string
+ "%s"
+ (shell-quote-argument (convert-standard-filename file))
+ cmd
+ nil t))
;; Replace "%1", "%2" etc. in command with group matches from regex
(save-match-data
@@ -11780,9 +11779,7 @@ order.")
(nreverse targets)))
(defun org-protect-slash (s)
- (while (string-match "/" s)
- (setq s (replace-match "\\" t t s)))
- s)
+ (replace-regexp-in-string "/" "\\/" s nil t))
(defun org--get-outline-path-1 (&optional use-cache)
"Return outline path to current headline.
@@ -14590,7 +14587,7 @@ See also `org-scan-tags'."
(progn
(setq tagsmatch (substring match 0 (match-beginning 0)))
(setq todomatch (substring match (match-end 0)))
- (when (string-match "\\`!" todomatch)
+ (when (string-prefix-p "!" todomatch)
(setq org--matcher-tags-todo-only t)
(setq todomatch (substring todomatch 1)))
(when (string-match "\\`\\s-*\\'" todomatch)
@@ -15143,8 +15140,8 @@ When JUST-ALIGN is non-nil, only align tags."
":")))
(if (not (org-string-nw-p tags)) (setq tags "")
- (unless (string-match ":\\'" tags) (setq tags (concat tags ":")))
- (unless (string-match "\\`:" tags) (setq tags (concat ":" tags))))
+ (unless (string-suffix-p ":" tags) (setq tags (concat tags ":")))
+ (unless (string-prefix-p ":" tags) (setq tags (concat ":" tags))))
;; Insert new tags at the correct column
(beginning-of-line)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index b9fc69c..2d1d53f 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -219,7 +219,8 @@ Return overlay specification, as a string, or nil."
(let ((first-object (car (org-element-contents element))))
(when (eq (org-element-type first-object) 'export-snippet)
(let ((value (org-element-property :value first-object)))
- (and (string-match "\\`<.*>\\'" value) value)))))
+ (and (string-prefix-p "<" value) (string-suffix-p ">" value)
+ value)))))
@@ -558,7 +559,8 @@ used as a communication channel."
(let ((action (org-element-property :BEAMER_ACT headline)))
(cond
((not action) (list (cons "a" "") (cons "A" "") (cons "R" "")))
- ((string-match "\\`\\[.*\\]\\'" action)
+ ((and (string-prefix-p "[" action)
+ (string-suffix-p "]" action))
(list
(cons "A" (org-beamer--normalize-argument action 'defaction))
(cons "a" "")
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 309abde..e351d9a 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1725,10 +1725,7 @@ produce code that uses these same face definitions."
(defun org-html-fix-class-name (kwd) ; audit callers of this function
"Turn todo keyword KWD into a valid class name.
Replaces invalid characters with \"_\"."
- (save-match-data
- (while (string-match "[^a-zA-Z0-9_]" kwd)
- (setq kwd (replace-match "_" t t kwd))))
- kwd)
+ (replace-regexp-in-string "[^a-zA-Z0-9_]" "_" kwd nil t))
(defun org-html-footnote-section (info)
"Format the footnote section.
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 4e33bab..c2e4966 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -168,8 +168,8 @@ CONTENTS is nil. INFO is a plist used as a communication
channel."
(let ((value (org-element-property :value verbatim)))
(format (cond ((not (string-match "`" value)) "`%s`")
- ((or (string-match "\\``" value)
- (string-match "`\\'" value))
+ ((or (string-prefix-p "`" value)
+ (string-suffix-p "`" value))
"`` %s ``")
(t "``%s``"))
value)))
@@ -426,8 +426,8 @@ CONTENTS is the paragraph contents. INFO is a plist used as
a communication channel."
(let ((first-object (car (org-element-contents paragraph))))
;; If paragraph starts with a #, protect it.
- (if (and (stringp first-object) (string-match "\\`#" first-object))
- (replace-regexp-in-string "\\`#" "\\#" contents nil t)
+ (if (and (stringp first-object) (string-prefix-p "#" first-object))
+ (concat "\\" contents)
contents)))