summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2014-04-18 15:11:42 +0200
committerBastien Guerry <bzg@altern.org>2014-04-18 15:11:42 +0200
commit7925d42d43c35093c2a7b943fc44d36043f9786d (patch)
treec8c49fbf4e082a618a02e24bfc90dd3f4e636596
parenta13e133f5a5330f82683fe490d6d697d9aa55c51 (diff)
downloadorg-mode-7925d42d43c35093c2a7b943fc44d36043f9786d.tar.gz
Alias `org-babel-trim' and `org-babel-chomp' to `org-trim' and `org-trim-trailing'.
* org.el (org-trim): Rewrite and make a defsubst. * org-bibtex.el (org-bibtex-get): Use `org-trim' instead of `org-babel-trim'. * ob-core.el (org-babel-trim): Delete and alias to `org-trim'. (org-babel-chomp): Delete and alias to `org-trim-trailing'. (org-trim-trailing): New defsubst. (org-babel-examplize-region): Fix version.
-rw-r--r--lisp/ob-core.el27
-rw-r--r--lisp/org-bibtex.el3
-rw-r--r--lisp/org.el10
3 files changed, 14 insertions, 26 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 0e8c57f..860c077 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -99,6 +99,9 @@
(declare-function org-element-context "org-element" (&optional ELEMENT))
(declare-function org-every "org" (pred seq))
+(defalias 'org-babel-trim 'org-trim)
+(defalias 'org-babel-chomp 'org-trim-trailing)
+
(defgroup org-babel nil
"Code block evaluation and management in `org-mode' documents."
:tag "Babel"
@@ -2302,7 +2305,11 @@ file's directory then expand relative links."
(define-obsolete-function-alias
'org-babel-examplize-region
- 'org-babel-examplify-region "24.5")
+ 'org-babel-examplify-region "25.1")
+
+(defsubst org-trim-trailing (s)
+ "Strip trailing spaces and carriage returns from string S."
+ (replace-regexp-in-string "[ \f\t\n\r\v]+\\'" "" s))
(defun org-babel-examplify-region (beg end &optional results-switches)
"Comment out region using the inline '==' or ': ' org example quote."
@@ -2740,24 +2747,6 @@ If the table is trivial, then return it as a scalar."
(match-string 1 cell))
cell) t))
-(defun org-babel-chomp (string &optional regexp)
- "Strip trailing spaces and carriage returns from STRING.
-Default regexp used is \"[ \f\t\n\r\v]\" but can be
-overwritten by specifying a regexp as a second argument."
- (let ((regexp (or regexp "[ \f\t\n\r\v]")))
- (while (and (> (length string) 0)
- (string-match regexp (substring string -1)))
- (setq string (substring string 0 -1)))
- string))
-
-(defun org-babel-trim (string &optional regexp)
- "Strip leading and trailing spaces and carriage returns from STRING.
-Like `org-babel-chomp' only it runs on both the front and back
-of the string."
- (org-babel-chomp (org-reverse-string
- (org-babel-chomp (org-reverse-string string) regexp))
- regexp))
-
(defun org-babel-tramp-handle-call-process-region
(start end program &optional delete buffer display &rest args)
"Use Tramp to handle `call-process-region'.
diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el
index cdb12b7..e7f0be5 100644
--- a/lisp/org-bibtex.el
+++ b/lisp/org-bibtex.el
@@ -120,7 +120,6 @@
(declare-function bibtex-generate-autokey "bibtex" ())
(declare-function bibtex-parse-entry "bibtex" (&optional content))
(declare-function bibtex-url "bibtex" (&optional pos no-browse))
-(declare-function org-babel-trim "ob" (string &optional regexp))
;;; Bibtex data
@@ -299,7 +298,7 @@ This variable is relevant only if `org-bibtex-tags-are-keywords' is t."
(org-entry-get (point) (upcase property))
(org-entry-get (point) (concat org-bibtex-prefix
(upcase property)))))))
- (when it (org-babel-trim it))))
+ (when it (org-trim it))))
(defun org-bibtex-put (property value)
(let ((prop (upcase (if (keywordp property)
diff --git a/lisp/org.el b/lisp/org.el
index f6a93d4..0ce0823 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21578,11 +21578,11 @@ N may optionally be the number of spaces to remove."
(or (buffer-base-buffer buffer)
buffer)))
-(defun org-trim (s)
- "Remove whitespace at beginning and end of string."
- (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
- (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
- s)
+(defsubst org-trim (s)
+ "Remove whitespace at the beginning and the end of string S."
+ (replace-regexp-in-string
+ "\\`[ \f\t\n\r\v]+" ""
+ (replace-regexp-in-string "[ \f\t\n\r\v]+\\'" "" s)))
(defun org-wrap (string &optional width lines)
"Wrap string to either a number of lines, or a width in characters.