forked from mirrors/org-mode
Clean up string handling.
* 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'.
This commit is contained in:
parent
9873e59913
commit
6b52bc6a21
|
@ -91,8 +91,10 @@ this variable.")
|
||||||
(defvar ess-local-process-name) ; dynamically scoped
|
(defvar ess-local-process-name) ; dynamically scoped
|
||||||
(defun org-babel-edit-prep:R (info)
|
(defun org-babel-edit-prep:R (info)
|
||||||
(let ((session (cdr (assoc :session (nth 2 info)))))
|
(let ((session (cdr (assoc :session (nth 2 info)))))
|
||||||
(when (and session (string-match "^\\*\\(.+?\\)\\*$" session))
|
(when (and session
|
||||||
(save-match-data (org-babel-R-initiate-session session nil)))))
|
(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
|
;; The usage of utils::read.table() ensures that the command
|
||||||
;; read.table() can be found even in circumstances when the utils
|
;; read.table() can be found even in circumstances when the utils
|
||||||
|
|
|
@ -1844,7 +1844,8 @@ region is not active then the point is demarcated."
|
||||||
lang "\n"
|
lang "\n"
|
||||||
body
|
body
|
||||||
(if (or (= (length body) 0)
|
(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")))
|
(funcall (if lower-case-p 'downcase 'upcase) "#+end_src\n")))
|
||||||
(goto-char start) (move-end-of-line 1)))))
|
(goto-char start) (move-end-of-line 1)))))
|
||||||
|
|
||||||
|
|
|
@ -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
|
If RESULTS look like a table, then convert them into an
|
||||||
Emacs-lisp table, otherwise return the results as a string."
|
Emacs-lisp table, otherwise return the results as a string."
|
||||||
(org-babel-read
|
(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
|
(org-babel-read
|
||||||
(concat "'"
|
(concat "'"
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
|
|
|
@ -106,15 +106,15 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
(org-latex-packages-alist
|
(org-latex-packages-alist
|
||||||
(append (cdr (assoc :packages params)) org-latex-packages-alist)))
|
(append (cdr (assoc :packages params)) org-latex-packages-alist)))
|
||||||
(cond
|
(cond
|
||||||
((and (string-match "\\.png$" out-file) (not imagemagick))
|
((and (string-suffix-p ".png" out-file) (not imagemagick))
|
||||||
(org-create-formula-image
|
(org-create-formula-image
|
||||||
body out-file org-format-latex-options in-buffer))
|
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))
|
(when (file-exists-p out-file) (delete-file out-file))
|
||||||
(with-temp-file out-file
|
(with-temp-file out-file
|
||||||
(insert body)))
|
(insert body)))
|
||||||
((and (or (string-match "\\.svg$" out-file)
|
((and (or (string-suffix-p ".svg" out-file)
|
||||||
(string-match "\\.html$" out-file))
|
(string-suffix-p ".html" out-file))
|
||||||
(executable-find org-babel-latex-htlatex))
|
(executable-find org-babel-latex-htlatex))
|
||||||
;; TODO: this is a very different way of generating the
|
;; TODO: this is a very different way of generating the
|
||||||
;; frame latex document than in the pdf case. Ideally, both
|
;; 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)))
|
(shell-command (format "%s %s" org-babel-latex-htlatex tex-file)))
|
||||||
(cond
|
(cond
|
||||||
((file-exists-p (concat (file-name-sans-extension tex-file) "-1.svg"))
|
((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
|
(progn
|
||||||
(shell-command "pwd")
|
(shell-command "pwd")
|
||||||
(shell-command (format "mv %s %s"
|
(shell-command (format "mv %s %s"
|
||||||
|
@ -152,13 +152,13 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
out-file)))
|
out-file)))
|
||||||
(error "SVG file produced but HTML file requested")))
|
(error "SVG file produced but HTML file requested")))
|
||||||
((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
|
((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"
|
(shell-command "mv %s %s"
|
||||||
(concat (file-name-sans-extension tex-file)
|
(concat (file-name-sans-extension tex-file)
|
||||||
".html")
|
".html")
|
||||||
out-file)
|
out-file)
|
||||||
(error "HTML file produced but SVG file requested")))))
|
(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
|
(with-temp-file tex-file
|
||||||
(require 'ox-latex)
|
(require 'ox-latex)
|
||||||
(insert
|
(insert
|
||||||
|
|
|
@ -334,8 +334,9 @@ last statement in BODY, as elisp."
|
||||||
|
|
||||||
(defun org-babel-python-read-string (string)
|
(defun org-babel-python-read-string (string)
|
||||||
"Strip \\='s from around Python string."
|
"Strip \\='s from around Python string."
|
||||||
(if (string-match "^'\\([^\000]+\\)'$" string)
|
(if (and (string-prefix-p "'" string)
|
||||||
(match-string 1 string)
|
(string-suffix-p "'" string))
|
||||||
|
(substring string 1 -1)
|
||||||
string))
|
string))
|
||||||
|
|
||||||
(provide 'ob-python)
|
(provide 'ob-python)
|
||||||
|
|
|
@ -91,7 +91,8 @@ the variable."
|
||||||
org-babel-current-src-block-location)))
|
org-babel-current-src-block-location)))
|
||||||
(org-babel-read ref))))
|
(org-babel-read ref))))
|
||||||
(if (equal out ref)
|
(if (equal out ref)
|
||||||
(if (string-match "^\".*\"$" ref)
|
(if (and (string-prefix-p "\"" ref)
|
||||||
|
(string-suffix-p "\"" ref))
|
||||||
(read ref)
|
(read ref)
|
||||||
(org-babel-ref-resolve ref))
|
(org-babel-ref-resolve ref))
|
||||||
out))))))
|
out))))))
|
||||||
|
|
|
@ -148,7 +148,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
"hline"))))
|
"hline"))))
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (pair)
|
(lambda (pair)
|
||||||
(if (string-match "bash$" shell-file-name)
|
(if (string-suffix-p "bash" shell-file-name)
|
||||||
(org-babel-variable-assignments:bash
|
(org-babel-variable-assignments:bash
|
||||||
(car pair) (cdr pair) sep hline)
|
(car pair) (cdr pair) sep hline)
|
||||||
(org-babel-variable-assignments:sh-generic
|
(org-babel-variable-assignments:sh-generic
|
||||||
|
|
|
@ -402,7 +402,7 @@ effect, which variables to use depends on the Emacs version."
|
||||||
`(org-unmodified ,@body)))
|
`(org-unmodified ,@body)))
|
||||||
(def-edebug-spec org-with-silent-modifications (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)
|
(defun org-define-error (name message)
|
||||||
"Define NAME as a new error signal.
|
"Define NAME as a new error signal.
|
||||||
MESSAGE is a string that will be output to the echo area if such
|
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
|
(put name 'error-conditions
|
||||||
(copy-sequence (cons name (get 'error '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)
|
(provide 'org-compat)
|
||||||
|
|
||||||
;;; org-compat.el ends here
|
;;; org-compat.el ends here
|
||||||
|
|
|
@ -678,13 +678,13 @@ the cdr of an element in `org-publish-project-alist', reuse
|
||||||
(minibuffer-allow-text-properties nil))
|
(minibuffer-allow-text-properties nil))
|
||||||
|
|
||||||
(setq base-url (read-string "Base URL of published content: " base-url nil base-url t))
|
(setq base-url (read-string "Base URL of published content: " base-url nil base-url t))
|
||||||
(if (not (string-match "\\/$" base-url))
|
(or (string-suffix-p "/" base-url)
|
||||||
(setq base-url (concat base-url "/")))
|
(setq base-url (concat base-url "/")))
|
||||||
|
|
||||||
(setq working-dir
|
(setq working-dir
|
||||||
(expand-file-name
|
(expand-file-name
|
||||||
(read-directory-name "Local working directory: " working-dir working-dir t)))
|
(read-directory-name "Local working directory: " working-dir working-dir t)))
|
||||||
(if (not (string-match "\\/$" working-dir))
|
(or (string-suffix-p "/" working-dir)
|
||||||
(setq working-dir (concat working-dir "/")))
|
(setq working-dir (concat working-dir "/")))
|
||||||
|
|
||||||
(setq strip-suffix
|
(setq strip-suffix
|
||||||
|
|
|
@ -1163,7 +1163,7 @@ to a number. In the case of a timestamp, increment by days."
|
||||||
(user-error "No non-empty field found")
|
(user-error "No non-empty field found")
|
||||||
(if (and org-table-copy-increment
|
(if (and org-table-copy-increment
|
||||||
(not (equal orig-n 0))
|
(not (equal orig-n 0))
|
||||||
(string-match "^[-+^/*0-9eE.]+$" txt)
|
(string-match-p "^[-+^/*0-9eE.]+$" txt)
|
||||||
(< (string-to-number txt) 100000000))
|
(< (string-to-number txt) 100000000))
|
||||||
(setq txt (calc-eval (concat txt "+" (number-to-string inc)))))
|
(setq txt (calc-eval (concat txt "+" (number-to-string inc)))))
|
||||||
(insert txt)
|
(insert txt)
|
||||||
|
@ -1306,7 +1306,10 @@ is always the old value."
|
||||||
(concat ", formula: "
|
(concat ", formula: "
|
||||||
(org-table-formula-to-user
|
(org-table-formula-to-user
|
||||||
(concat
|
(concat
|
||||||
(if (string-match "^[$@]"(car eqn)) "" "$")
|
(if (or (string-prefix-p "$" (car eqn))
|
||||||
|
(string-prefix-p "@" (car eqn)))
|
||||||
|
""
|
||||||
|
"$")
|
||||||
(car eqn) "=" (cdr eqn))))
|
(car eqn) "=" (cdr eqn))))
|
||||||
"")))))
|
"")))))
|
||||||
|
|
||||||
|
@ -1579,7 +1582,7 @@ With prefix ABOVE, insert above the current line."
|
||||||
(if (not (org-at-table-p))
|
(if (not (org-at-table-p))
|
||||||
(user-error "Not at a table"))
|
(user-error "Not at a table"))
|
||||||
(when (eobp) (insert "\n") (backward-char 1))
|
(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))
|
(org-table-align))
|
||||||
(let ((line (org-table-clean-line
|
(let ((line (org-table-clean-line
|
||||||
(buffer-substring (point-at-bol) (point-at-eol))))
|
(buffer-substring (point-at-bol) (point-at-eol))))
|
||||||
|
@ -2185,7 +2188,7 @@ with \"=\" or \":=\"."
|
||||||
(assoc ref stored-list)
|
(assoc ref stored-list)
|
||||||
(assoc scol stored-list))))
|
(assoc scol stored-list))))
|
||||||
(cond (key (car ass))
|
(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))))))
|
(cdr ass))))))
|
||||||
(noerror nil)
|
(noerror nil)
|
||||||
(t (error "No formula active for the current field")))))
|
(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)
|
(org-table-may-need-update nil)
|
||||||
(stored (cdr (assoc scol stored-list)))
|
(stored (cdr (assoc scol stored-list)))
|
||||||
(eq (cond
|
(eq (cond
|
||||||
((and stored equation (string-match "^ *=? *$" equation))
|
((and stored equation (string-match-p "^ *=? *$" equation))
|
||||||
stored)
|
stored)
|
||||||
((stringp equation)
|
((stringp equation)
|
||||||
equation)
|
equation)
|
||||||
|
|
|
@ -11283,7 +11283,7 @@ of matched result, with is either `dedicated' or `fuzzy'."
|
||||||
(cond
|
(cond
|
||||||
((not org-display-internal-link-with-indirect-buffer)
|
((not org-display-internal-link-with-indirect-buffer)
|
||||||
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")
|
(message "Buffer is already a clone, not making another one")
|
||||||
;; we also do not modify visibility in this case
|
;; we also do not modify visibility in this case
|
||||||
buffer)
|
buffer)
|
||||||
|
|
|
@ -412,9 +412,9 @@ This splices all the components into the list."
|
||||||
(pcase org-publish-sitemap-sort-files
|
(pcase org-publish-sitemap-sort-files
|
||||||
(`alphabetically
|
(`alphabetically
|
||||||
(let* ((adir (file-directory-p a))
|
(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))
|
(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)
|
(A (if aorg (concat (file-name-directory a)
|
||||||
(org-publish-find-title a)) a))
|
(org-publish-find-title a)) a))
|
||||||
(B (if borg (concat (file-name-directory b)
|
(B (if borg (concat (file-name-directory b)
|
||||||
|
|
|
@ -585,7 +585,7 @@ holding export options."
|
||||||
(let ((dirdesc
|
(let ((dirdesc
|
||||||
(let ((desc (plist-get info :texinfo-dirdesc)))
|
(let ((desc (plist-get info :texinfo-dirdesc)))
|
||||||
(cond ((not desc) nil)
|
(cond ((not desc) nil)
|
||||||
((string-match-p "\\.$" desc) desc)
|
((string-suffix-p "." desc) desc)
|
||||||
(t (concat desc "."))))))
|
(t (concat desc "."))))))
|
||||||
(if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
|
(if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
|
||||||
"\n"
|
"\n"
|
||||||
|
|
Loading…
Reference in New Issue