Преглед изворни кода

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'.
Aaron Ecay пре 8 година
родитељ
комит
1c18efb615
11 измењених фајлова са 46 додато и 38 уклоњено
  1. 1 3
      lisp/org-agenda.el
  2. 1 1
      lisp/org-capture.el
  3. 17 1
      lisp/org-compat.el
  4. 1 1
      lisp/org-datetree.el
  5. 2 4
      lisp/org-footnote.el
  6. 1 1
      lisp/org-gnus.el
  7. 4 4
      lisp/org-list.el
  8. 10 13
      lisp/org.el
  9. 4 2
      lisp/ox-beamer.el
  10. 1 4
      lisp/ox-html.el
  11. 4 4
      lisp/ox-md.el

+ 1 - 3
lisp/org-agenda.el

@@ -3255,9 +3255,7 @@ This ensures the export commands can easily use it."
 	   ((not res) "")
 	   ((not res) "")
 	   ((stringp res) res)
 	   ((stringp res) res)
 	   (t (prin1-to-string 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
 ;;;###autoload
 (defun org-store-agenda-views (&rest parameters)
 (defun org-store-agenda-views (&rest parameters)

+ 1 - 1
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))
 	       (equal (car (org-capture-get :target)) 'function))
 	    ((error quit)
 	    ((error quit)
 	     (if (and (buffer-base-buffer (current-buffer))
 	     (if (and (buffer-base-buffer (current-buffer))
-		      (string-match "\\`CAPTURE-" (buffer-name)))
+		      (string-prefix-p "CAPTURE-" (buffer-name)))
 		 (kill-buffer (current-buffer)))
 		 (kill-buffer (current-buffer)))
 	     (set-window-configuration (org-capture-get :return-to-wconf))
 	     (set-window-configuration (org-capture-get :return-to-wconf))
 	     (error "Capture template `%s': %s"
 	     (error "Capture template `%s': %s"

+ 17 - 1
lisp/org-compat.el

@@ -430,7 +430,23 @@ attention to case differences."
     (let ((start-pos (- (length string) (length suffix))))
     (let ((start-pos (- (length string) (length suffix))))
       (and (>= start-pos 0)
       (and (>= start-pos 0)
 	   (eq t (compare-strings suffix nil nil
 	   (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)
 (provide 'org-compat)
 
 

+ 1 - 1
lisp/org-datetree.el

@@ -192,7 +192,7 @@ before running this command, even though the command tries to be smart."
 		    (max (line-beginning-position)
 		    (max (line-beginning-position)
 			 (- (match-beginning 0) org-ds-keyword-length))
 			 (- (match-beginning 0) org-ds-keyword-length))
 		    (match-beginning 0))))
 		    (match-beginning 0))))
-	  (when (or (string-match "-\\'" tmp)
+	  (when (or (string-suffix-p "-" tmp)
 		    (string-match dre tmp)
 		    (string-match dre tmp)
 		    (string-match sre tmp))
 		    (string-match sre tmp))
 	    (throw 'next nil))
 	    (throw 'next nil))

+ 2 - 4
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,
 If LABEL is the empty string or constituted of white spaces only,
 return nil instead."
 return nil instead."
   (let ((label (org-trim label)))
   (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)
 (defun org-footnote-get-definition (label)
   "Return label, boundaries and definition of the footnote LABEL."
   "Return label, boundaries and definition of the footnote LABEL."

+ 1 - 1
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
 If `org-store-link' was called with a prefix arg the meaning of
 `org-gnus-prefer-web-links' is reversed."
 `org-gnus-prefer-web-links' is reversed."
   (let ((unprefixed-group (replace-regexp-in-string "^[^:]+:" "" group)))
   (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-xor current-prefix-arg
 		      org-gnus-prefer-web-links))
 		      org-gnus-prefer-web-links))
 	(concat (if (string-match "gmane" unprefixed-group)
 	(concat (if (string-match "gmane" unprefixed-group)

+ 4 - 4
lisp/org-list.el

@@ -658,7 +658,7 @@ Assume point is at an item."
 		       (match-string-no-properties 2) ; counter
 		       (match-string-no-properties 2) ; counter
 		       (match-string-no-properties 3) ; checkbox
 		       (match-string-no-properties 3) ; checkbox
 		       ;; Description tag.
 		       ;; Description tag.
-		       (and (save-match-data (string-match "[-+*]" bullet))
+		       (and (string-match-p "[-+*]" bullet)
 			    (match-string-no-properties 4)))))))
 			    (match-string-no-properties 4)))))))
 	   (end-before-blank
 	   (end-before-blank
 	    (function
 	    (function
@@ -1025,7 +1025,7 @@ Possible types are `descriptive', `ordered' and `unordered'.  The
 type is determined by the first item of the list."
 type is determined by the first item of the list."
   (let ((first (org-list-get-list-begin item struct prevs)))
   (let ((first (org-list-get-list-begin item struct prevs)))
     (cond
     (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)
      ((org-list-get-tag first struct) 'descriptive)
      (t 'unordered))))
      (t 'unordered))))
 
 
@@ -1471,7 +1471,7 @@ This function returns, destructively, the new list structure."
 		      (save-excursion
 		      (save-excursion
 			(goto-char (org-list-get-last-item item struct prevs))
 			(goto-char (org-list-get-last-item item struct prevs))
 			(point-at-eol)))
 			(point-at-eol)))
-		     ((string-match "\\`[0-9]+\\'" dest)
+		     ((string-match-p "\\`[0-9]+\\'" dest)
 		      (let* ((all (org-list-get-all-items item struct prevs))
 		      (let* ((all (org-list-get-all-items item struct prevs))
 			     (len (length all))
 			     (len (length all))
 			     (index (mod (string-to-number dest) len)))
 			     (index (mod (string-to-number dest) len)))
@@ -1645,7 +1645,7 @@ as returned by `org-list-prevs-alist'."
 	   (while item
 	   (while item
 	     (let ((count (org-list-get-counter item struct)))
 	     (let ((count (org-list-get-counter item struct)))
 	       ;; Virtually determine current bullet
 	       ;; 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.
 		   ;; Counters are not case-sensitive.
 		   (setq ascii (string-to-char (upcase count)))
 		   (setq ascii (string-to-char (upcase count)))
 		 (setq ascii (1+ ascii)))
 		 (setq ascii (1+ ascii)))

+ 10 - 13
lisp/org.el

@@ -8803,7 +8803,7 @@ When REMOVE is non-nil, remove the subtree from the clipboard."
      (setq beg (point))
      (setq beg (point))
      (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
      (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
      (insert-before-markers txt)
      (insert-before-markers txt)
-     (unless (string-match "\n\\'" txt) (insert "\n"))
+     (unless (string-suffix-p "\n" txt) (insert "\n"))
      (setq newend (point))
      (setq newend (point))
      (org-reinstall-markers-in-region beg)
      (org-reinstall-markers-in-region beg)
      (setq end (point))
      (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.
       ;; Remove quotes around the file name - we'll use shell-quote-argument.
       (while (string-match "['\"]%s['\"]" cmd)
       (while (string-match "['\"]%s['\"]" cmd)
 	(setq cmd (replace-match "%s" t t 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
       ;; Replace "%1", "%2" etc. in command with group matches from regex
       (save-match-data
       (save-match-data
@@ -11780,9 +11779,7 @@ order.")
     (nreverse targets)))
     (nreverse targets)))
 
 
 (defun org-protect-slash (s)
 (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)
 (defun org--get-outline-path-1 (&optional use-cache)
   "Return outline path to current headline.
   "Return outline path to current headline.
@@ -14590,7 +14587,7 @@ See also `org-scan-tags'."
 	(progn
 	(progn
 	  (setq tagsmatch (substring match 0 (match-beginning 0)))
 	  (setq tagsmatch (substring match 0 (match-beginning 0)))
 	  (setq todomatch (substring match (match-end 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 org--matcher-tags-todo-only t)
 	    (setq todomatch (substring todomatch 1)))
 	    (setq todomatch (substring todomatch 1)))
 	  (when (string-match "\\`\\s-*\\'" todomatch)
 	  (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 "")
 	  (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
 	  ;; Insert new tags at the correct column
 	  (beginning-of-line)
 	  (beginning-of-line)

+ 4 - 2
lisp/ox-beamer.el

@@ -219,7 +219,8 @@ Return overlay specification, as a string, or nil."
   (let ((first-object (car (org-element-contents element))))
   (let ((first-object (car (org-element-contents element))))
     (when (eq (org-element-type first-object) 'export-snippet)
     (when (eq (org-element-type first-object) 'export-snippet)
       (let ((value (org-element-property :value first-object)))
       (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)))
 	  (let ((action (org-element-property :BEAMER_ACT headline)))
 	    (cond
 	    (cond
 	     ((not action) (list (cons "a" "") (cons "A" "") (cons "R" "")))
 	     ((not action) (list (cons "a" "") (cons "A" "") (cons "R" "")))
-	     ((string-match "\\`\\[.*\\]\\'" action)
+	     ((and (string-prefix-p "[" action)
+		   (string-suffix-p "]" action))
 	      (list
 	      (list
 	       (cons "A" (org-beamer--normalize-argument action 'defaction))
 	       (cons "A" (org-beamer--normalize-argument action 'defaction))
 	       (cons "a" "")
 	       (cons "a" "")

+ 1 - 4
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
 (defun org-html-fix-class-name (kwd)	; audit callers of this function
   "Turn todo keyword KWD into a valid class name.
   "Turn todo keyword KWD into a valid class name.
 Replaces invalid characters with \"_\"."
 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)
 (defun org-html-footnote-section (info)
   "Format the footnote section.
   "Format the footnote section.

+ 4 - 4
lisp/ox-md.el

@@ -168,8 +168,8 @@ CONTENTS is nil.  INFO is a plist used as a communication
 channel."
 channel."
   (let ((value (org-element-property :value verbatim)))
   (let ((value (org-element-property :value verbatim)))
     (format (cond ((not (string-match "`" value)) "`%s`")
     (format (cond ((not (string-match "`" value)) "`%s`")
-		  ((or (string-match "\\``" value)
-		       (string-match "`\\'" value))
+		  ((or (string-prefix-p "`" value)
+		       (string-suffix-p "`" value))
 		   "`` %s ``")
 		   "`` %s ``")
 		  (t "``%s``"))
 		  (t "``%s``"))
 	    value)))
 	    value)))
@@ -426,8 +426,8 @@ CONTENTS is the paragraph contents.  INFO is a plist used as
 a communication channel."
 a communication channel."
   (let ((first-object (car (org-element-contents paragraph))))
   (let ((first-object (car (org-element-contents paragraph))))
     ;; If paragraph starts with a #, protect it.
     ;; 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)))
       contents)))