summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ecay <aaronecay@gmail.com>2016-08-24 15:05:54 (GMT)
committer Aaron Ecay <aaronecay@gmail.com>2016-08-24 15:05:54 (GMT)
commit6b52bc6a2153a8c60d23d0915246a60d3ee37a52 (patch)
tree7c22f92b76d47ea0bda99a902d9dd9af9df8d1a8
parent9873e59913b696d9ece019dee4696cd0365c939c (diff)
downloadorg-mode-master.zip
org-mode-master.tar.gz
Clean up string handling.HEADmaster
* lisp/org-compat.el (string-prefix-p, string-suffix-p): Add compatibility definitions for 24.3. * lisp/ob-R.el (org-babel-edit-prep:R): * lisp/ob-core.el (org-babel-demarcate-block): * lisp/ob-js.el (org-babel-js-read): * lisp/ob-latex.el (org-babel-execute:latex): * lisp/ob-ref.el (org-babel-ref-parse): * lisp/ob-shell.el (org-babel-variable-assignments:shell): * lisp/org-protocol.el (org-protocol-create): * lisp/org-table.el (org-table-field-info): * lisp/org.el (org-get-buffer-for-internal-link): * lisp/ox-publish.el (org-publish-compare-directory-files): * lisp/ox-texinfo.el (org-texinfo-template): Use `string-{suffix,prefix}-p' instead of `string-match(-p)'. * lisp/ob-python.el (org-babel-python-read-string): Ditto, also use `substring' rather than `match-string'. * lisp/org-table.el (org-table-copy-down): (org-table-insert-hline, org-table-current-field-formula): (org-table-get-formula): Use `string-match-p' instead of `string-match'.
-rw-r--r--lisp/ob-R.el6
-rw-r--r--lisp/ob-core.el3
-rw-r--r--lisp/ob-js.el4
-rw-r--r--lisp/ob-latex.el14
-rw-r--r--lisp/ob-python.el5
-rw-r--r--lisp/ob-ref.el3
-rw-r--r--lisp/ob-shell.el2
-rw-r--r--lisp/org-compat.el22
-rw-r--r--lisp/org-protocol.el8
-rw-r--r--lisp/org-table.el13
-rw-r--r--lisp/org.el2
-rw-r--r--lisp/ox-publish.el4
-rw-r--r--lisp/ox-texinfo.el2
13 files changed, 59 insertions, 29 deletions
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 123aaaf..a17cf1d 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -91,8 +91,10 @@ this variable.")
(defvar ess-local-process-name) ; dynamically scoped
(defun org-babel-edit-prep:R (info)
(let ((session (cdr (assoc :session (nth 2 info)))))
- (when (and session (string-match "^\\*\\(.+?\\)\\*$" session))
- (save-match-data (org-babel-R-initiate-session session nil)))))
+ (when (and session
+ (string-prefix-p "*" session)
+ (string-suffix-p "*" session))
+ (org-babel-R-initiate-session session nil))))
;; The usage of utils::read.table() ensures that the command
;; read.table() can be found even in circumstances when the utils
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 88c4fcc..266ccc6 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1844,7 +1844,8 @@ region is not active then the point is demarcated."
lang "\n"
body
(if (or (= (length body) 0)
- (string-match "[\r\n]$" body)) "" "\n")
+ (string-suffix-p "\r" body)
+ (string-suffix-p "\n" body)) "" "\n")
(funcall (if lower-case-p 'downcase 'upcase) "#+end_src\n")))
(goto-char start) (move-end-of-line 1)))))
diff --git a/lisp/ob-js.el b/lisp/ob-js.el
index 452683e..791d40c 100644
--- a/lisp/ob-js.el
+++ b/lisp/ob-js.el
@@ -96,7 +96,9 @@ This function is called by `org-babel-execute-src-block'"
If RESULTS look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
(org-babel-read
- (if (and (stringp results) (string-match "^\\[[^\000]+\\]$" results))
+ (if (and (stringp results)
+ (string-prefix-p "[" results)
+ (string-suffix-p "]" results))
(org-babel-read
(concat "'"
(replace-regexp-in-string
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index a11e6e1..e4327a2 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -106,15 +106,15 @@ This function is called by `org-babel-execute-src-block'."
(org-latex-packages-alist
(append (cdr (assoc :packages params)) org-latex-packages-alist)))
(cond
- ((and (string-match "\\.png$" out-file) (not imagemagick))
+ ((and (string-suffix-p ".png" out-file) (not imagemagick))
(org-create-formula-image
body out-file org-format-latex-options in-buffer))
- ((string-match "\\.tikz$" out-file)
+ ((string-suffix-p ".tikz" out-file)
(when (file-exists-p out-file) (delete-file out-file))
(with-temp-file out-file
(insert body)))
- ((and (or (string-match "\\.svg$" out-file)
- (string-match "\\.html$" out-file))
+ ((and (or (string-suffix-p ".svg" out-file)
+ (string-suffix-p ".html" out-file))
(executable-find org-babel-latex-htlatex))
;; TODO: this is a very different way of generating the
;; frame latex document than in the pdf case. Ideally, both
@@ -144,7 +144,7 @@ This function is called by `org-babel-execute-src-block'."
(shell-command (format "%s %s" org-babel-latex-htlatex tex-file)))
(cond
((file-exists-p (concat (file-name-sans-extension tex-file) "-1.svg"))
- (if (string-match "\\.svg$" out-file)
+ (if (string-suffix-p ".svg" out-file)
(progn
(shell-command "pwd")
(shell-command (format "mv %s %s"
@@ -152,13 +152,13 @@ This function is called by `org-babel-execute-src-block'."
out-file)))
(error "SVG file produced but HTML file requested")))
((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
- (if (string-match "\\.html$" out-file)
+ (if (string-suffix-p ".html" out-file)
(shell-command "mv %s %s"
(concat (file-name-sans-extension tex-file)
".html")
out-file)
(error "HTML file produced but SVG file requested")))))
- ((or (string-match "\\.pdf$" out-file) imagemagick)
+ ((or (string-suffix-p ".pdf" out-file) imagemagick)
(with-temp-file tex-file
(require 'ox-latex)
(insert
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 475af3e..7f9886b 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -334,8 +334,9 @@ last statement in BODY, as elisp."
(defun org-babel-python-read-string (string)
"Strip \\='s from around Python string."
- (if (string-match "^'\\([^\000]+\\)'$" string)
- (match-string 1 string)
+ (if (and (string-prefix-p "'" string)
+ (string-suffix-p "'" string))
+ (substring string 1 -1)
string))
(provide 'ob-python)
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index 54ec62c..c109d89 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -91,7 +91,8 @@ the variable."
org-babel-current-src-block-location)))
(org-babel-read ref))))
(if (equal out ref)
- (if (string-match "^\".*\"$" ref)
+ (if (and (string-prefix-p "\"" ref)
+ (string-suffix-p "\"" ref))
(read ref)
(org-babel-ref-resolve ref))
out))))))
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 192a090..946b5e2 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -148,7 +148,7 @@ This function is called by `org-babel-execute-src-block'."
"hline"))))
(mapcar
(lambda (pair)
- (if (string-match "bash$" shell-file-name)
+ (if (string-suffix-p "bash" shell-file-name)
(org-babel-variable-assignments:bash
(car pair) (cdr pair) sep hline)
(org-babel-variable-assignments:sh-generic
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 3120e80..859a6c6 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -402,7 +402,7 @@ effect, which variables to use depends on the Emacs version."
`(org-unmodified ,@body)))
(def-edebug-spec org-with-silent-modifications (body))
-;; Remove this when support for Emacs < 24.4 is dropped.
+;; Functions for Emacs < 24.4 compatibility
(defun org-define-error (name message)
"Define NAME as a new error signal.
MESSAGE is a string that will be output to the echo area if such
@@ -412,6 +412,26 @@ Implements `define-error' for older emacsen."
(put name 'error-conditions
(copy-sequence (cons name (get 'error 'error-conditions))))))
+(unless (fboundp 'string-prefix-p)
+ ;; From Emacs subr.el.
+ (defun string-prefix-p (prefix string &optional ignore-case)
+ "Return non-nil if PREFIX is a prefix of STRING.
+If IGNORE-CASE is non-nil, the comparison is done without paying attention
+to case differences."
+ (let ((prefix-length (length prefix)))
+ (if (> prefix-length (length string)) nil
+ (eq t (compare-strings prefix 0 prefix-length string
+ 0 prefix-length ignore-case)))))
+
+ (defun string-suffix-p (suffix string &optional ignore-case)
+ "Return non-nil if SUFFIX is a suffix of STRING.
+If IGNORE-CASE is non-nil, the comparison is done without paying
+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))))))
+
(provide 'org-compat)
;;; org-compat.el ends here
diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el
index d598ac2..52b9ea5 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -678,14 +678,14 @@ the cdr of an element in `org-publish-project-alist', reuse
(minibuffer-allow-text-properties nil))
(setq base-url (read-string "Base URL of published content: " base-url nil base-url t))
- (if (not (string-match "\\/$" base-url))
- (setq base-url (concat base-url "/")))
+ (or (string-suffix-p "/" base-url)
+ (setq base-url (concat base-url "/")))
(setq working-dir
(expand-file-name
(read-directory-name "Local working directory: " working-dir working-dir t)))
- (if (not (string-match "\\/$" working-dir))
- (setq working-dir (concat working-dir "/")))
+ (or (string-suffix-p "/" working-dir)
+ (setq working-dir (concat working-dir "/")))
(setq strip-suffix
(read-string
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 7c29f59..2562f02 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1163,7 +1163,7 @@ to a number. In the case of a timestamp, increment by days."
(user-error "No non-empty field found")
(if (and org-table-copy-increment
(not (equal orig-n 0))
- (string-match "^[-+^/*0-9eE.]+$" txt)
+ (string-match-p "^[-+^/*0-9eE.]+$" txt)
(< (string-to-number txt) 100000000))
(setq txt (calc-eval (concat txt "+" (number-to-string inc)))))
(insert txt)
@@ -1306,7 +1306,10 @@ is always the old value."
(concat ", formula: "
(org-table-formula-to-user
(concat
- (if (string-match "^[$@]"(car eqn)) "" "$")
+ (if (or (string-prefix-p "$" (car eqn))
+ (string-prefix-p "@" (car eqn)))
+ ""
+ "$")
(car eqn) "=" (cdr eqn))))
"")))))
@@ -1579,7 +1582,7 @@ With prefix ABOVE, insert above the current line."
(if (not (org-at-table-p))
(user-error "Not at a table"))
(when (eobp) (insert "\n") (backward-char 1))
- (if (not (string-match "|[ \t]*$" (org-current-line-string)))
+ (if (not (string-match-p "|[ \t]*$" (org-current-line-string)))
(org-table-align))
(let ((line (org-table-clean-line
(buffer-substring (point-at-bol) (point-at-eol))))
@@ -2185,7 +2188,7 @@ with \"=\" or \":=\"."
(assoc ref stored-list)
(assoc scol stored-list))))
(cond (key (car ass))
- (ass (concat (if (string-match "^[0-9]+$" (car ass)) "=" ":=")
+ (ass (concat (if (string-match-p "^[0-9]+$" (car ass)) "=" ":=")
(cdr ass))))))
(noerror nil)
(t (error "No formula active for the current field")))))
@@ -2209,7 +2212,7 @@ When NAMED is non-nil, look for a named equation."
(org-table-may-need-update nil)
(stored (cdr (assoc scol stored-list)))
(eq (cond
- ((and stored equation (string-match "^ *=? *$" equation))
+ ((and stored equation (string-match-p "^ *=? *$" equation))
stored)
((stringp equation)
equation)
diff --git a/lisp/org.el b/lisp/org.el
index 8a5780b..4cd3b33 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11283,7 +11283,7 @@ of matched result, with is either `dedicated' or `fuzzy'."
(cond
((not org-display-internal-link-with-indirect-buffer)
buffer)
- ((string-match "(Clone)$" (buffer-name buffer))
+ ((string-suffix-p "(Clone)" (buffer-name buffer))
(message "Buffer is already a clone, not making another one")
;; we also do not modify visibility in this case
buffer)
diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 0b83759..912cb25 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -412,9 +412,9 @@ This splices all the components into the list."
(pcase org-publish-sitemap-sort-files
(`alphabetically
(let* ((adir (file-directory-p a))
- (aorg (and (string-match "\\.org$" a) (not adir)))
+ (aorg (and (string-suffix-p ".org" a) (not adir)))
(bdir (file-directory-p b))
- (borg (and (string-match "\\.org$" b) (not bdir)))
+ (borg (and (string-suffix-p ".org" b) (not bdir)))
(A (if aorg (concat (file-name-directory a)
(org-publish-find-title a)) a))
(B (if borg (concat (file-name-directory b)
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index aec9b0b..39cb8ad 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -585,7 +585,7 @@ holding export options."
(let ((dirdesc
(let ((desc (plist-get info :texinfo-dirdesc)))
(cond ((not desc) nil)
- ((string-match-p "\\.$" desc) desc)
+ ((string-suffix-p "." desc) desc)
(t (concat desc "."))))))
(if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
"\n"