[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a4ececf: Move string-trim functions to subr.el
From: |
Lars Ingebrigtsen |
Subject: |
master a4ececf: Move string-trim functions to subr.el |
Date: |
Wed, 24 Mar 2021 04:22:50 -0400 (EDT) |
branch: master
commit a4ececf004e5442fc245ccff910000fe407f7212
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Move string-trim functions to subr.el
* doc/lispref/strings.texi (Creating Strings): Document them.
* lisp/faces.el: Don't require subr-x, because that leads to build
errors.
* lisp/subr.el (string-trim, string-trim-right)
(string-trim-left): Move here from subr-x.el.
* lisp/emacs-lisp/shortdoc.el (string): Adjust.
---
doc/lispref/strings.texi | 16 ++++++++++++++++
lisp/emacs-lisp/shortdoc.el | 3 ---
lisp/emacs-lisp/subr-x.el | 22 ----------------------
lisp/faces.el | 2 --
lisp/subr.el | 22 ++++++++++++++++++++++
5 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 5cae939..b4d7bc7 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -390,6 +390,22 @@ whitespace to a single space character, as well as
removing all
whitespace from the start and the end of @var{string}.
@end defun
+@defun string-trim-left string &optional regexp
+Remove the leading text that matches @var{regexp} from @var{string}.
+@var{regexp} defaults to @samp{[ \t\n\r]+}.
+@end defun
+
+@defun string-trim-right string &optional regexp
+Remove the trailing text that matches @var{regexp} from @var{string}.
+@var{regexp} defaults to @samp{[ \t\n\r]+}.
+@end defun
+
+@defun string-trim string &optional trim-left trim-right
+Remove the leading text that matches @var{trim-left} and trailing text
+that matches @var{trim-right} from from @var{string}. Both regexps
+default to @samp{[ \t\n\r]+}.
+@end defun
+
@defun string-fill string length
Attempt to Word-wrap @var{string} so that no lines are longer than
@var{length}. Filling is done on whitespace boundaries only. If
diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el
index 789d632..86d5130 100644
--- a/lisp/emacs-lisp/shortdoc.el
+++ b/lisp/emacs-lisp/shortdoc.el
@@ -168,15 +168,12 @@ There can be any number of :example/:result elements."
(replace-regexp-in-string
:eval (replace-regexp-in-string "[a-z]+" "_" "*foo*"))
(string-trim
- :no-manual t
:args (string)
:doc "Trim STRING of leading and trailing white space."
:eval (string-trim " foo "))
(string-trim-left
- :no-manual t
:eval (string-trim-left "oofoo" "o+"))
(string-trim-right
- :no-manual t
:eval (string-trim-right "barkss" "s+"))
(string-truncate-left
:no-manual t
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index a451445..9c8c967 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -215,28 +215,6 @@ The variable list SPEC is the same as in `if-let'."
(define-obsolete-function-alias 'string-reverse 'reverse "25.1")
-(defsubst string-trim-left (string &optional regexp)
- "Trim STRING of leading string matching REGEXP.
-
-REGEXP defaults to \"[ \\t\\n\\r]+\"."
- (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
- (substring string (match-end 0))
- string))
-
-(defsubst string-trim-right (string &optional regexp)
- "Trim STRING of trailing string matching REGEXP.
-
-REGEXP defaults to \"[ \\t\\n\\r]+\"."
- (let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
- string)))
- (if i (substring string 0 i) string)))
-
-(defsubst string-trim (string &optional trim-left trim-right)
- "Trim STRING of leading and trailing strings matching TRIM-LEFT and
TRIM-RIGHT.
-
-TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
- (string-trim-left (string-trim-right string trim-right) trim-left))
-
;;;###autoload
(defun string-truncate-left (string length)
"Truncate STRING to LENGTH, replacing initial surplus with \"...\"."
diff --git a/lisp/faces.el b/lisp/faces.el
index 1067556..3ea4c94 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -25,8 +25,6 @@
;;; Code:
-(eval-when-compile (require 'subr-x))
-
(defcustom term-file-prefix (purecopy "term/")
"If non-nil, Emacs startup performs terminal-specific initialization.
It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
diff --git a/lisp/subr.el b/lisp/subr.el
index ef0e5e6..1b93fcf 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6200,6 +6200,28 @@ returned list are in the same order as in TREE.
;; for discoverability:
(defalias 'flatten-list #'flatten-tree)
+(defun string-trim-left (string &optional regexp)
+ "Trim STRING of leading string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
+ (substring string (match-end 0))
+ string))
+
+(defun string-trim-right (string &optional regexp)
+ "Trim STRING of trailing string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
+ string)))
+ (if i (substring string 0 i) string)))
+
+(defun string-trim (string &optional trim-left trim-right)
+ "Trim STRING of leading and trailing strings matching TRIM-LEFT and
TRIM-RIGHT.
+
+TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
+ (string-trim-left (string-trim-right string trim-right) trim-left))
+
;; The initial anchoring is for better performance in searching matches.
(defconst regexp-unmatchable "\\`a\\`"
"Standard regexp guaranteed not to match any string at all.")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master a4ececf: Move string-trim functions to subr.el,
Lars Ingebrigtsen <=