aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/strings.texi16
-rw-r--r--lisp/emacs-lisp/shortdoc.el3
-rw-r--r--lisp/emacs-lisp/subr-x.el22
-rw-r--r--lisp/faces.el2
-rw-r--r--lisp/subr.el22
5 files changed, 38 insertions, 27 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 5cae939b7bf..b4d7bc729f5 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
390whitespace from the start and the end of @var{string}. 390whitespace from the start and the end of @var{string}.
391@end defun 391@end defun
392 392
393@defun string-trim-left string &optional regexp
394Remove the leading text that matches @var{regexp} from @var{string}.
395@var{regexp} defaults to @samp{[ \t\n\r]+}.
396@end defun
397
398@defun string-trim-right string &optional regexp
399Remove the trailing text that matches @var{regexp} from @var{string}.
400@var{regexp} defaults to @samp{[ \t\n\r]+}.
401@end defun
402
403@defun string-trim string &optional trim-left trim-right
404Remove the leading text that matches @var{trim-left} and trailing text
405that matches @var{trim-right} from from @var{string}. Both regexps
406default to @samp{[ \t\n\r]+}.
407@end defun
408
393@defun string-fill string length 409@defun string-fill string length
394Attempt to Word-wrap @var{string} so that no lines are longer than 410Attempt to Word-wrap @var{string} so that no lines are longer than
395@var{length}. Filling is done on whitespace boundaries only. If 411@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 789d6325e9a..86d5130bbed 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."
168 (replace-regexp-in-string 168 (replace-regexp-in-string
169 :eval (replace-regexp-in-string "[a-z]+" "_" "*foo*")) 169 :eval (replace-regexp-in-string "[a-z]+" "_" "*foo*"))
170 (string-trim 170 (string-trim
171 :no-manual t
172 :args (string) 171 :args (string)
173 :doc "Trim STRING of leading and trailing white space." 172 :doc "Trim STRING of leading and trailing white space."
174 :eval (string-trim " foo ")) 173 :eval (string-trim " foo "))
175 (string-trim-left 174 (string-trim-left
176 :no-manual t
177 :eval (string-trim-left "oofoo" "o+")) 175 :eval (string-trim-left "oofoo" "o+"))
178 (string-trim-right 176 (string-trim-right
179 :no-manual t
180 :eval (string-trim-right "barkss" "s+")) 177 :eval (string-trim-right "barkss" "s+"))
181 (string-truncate-left 178 (string-truncate-left
182 :no-manual t 179 :no-manual t
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index a4514454c0b..9c8c967ee9c 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'."
215 215
216(define-obsolete-function-alias 'string-reverse 'reverse "25.1") 216(define-obsolete-function-alias 'string-reverse 'reverse "25.1")
217 217
218(defsubst string-trim-left (string &optional regexp)
219 "Trim STRING of leading string matching REGEXP.
220
221REGEXP defaults to \"[ \\t\\n\\r]+\"."
222 (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
223 (substring string (match-end 0))
224 string))
225
226(defsubst string-trim-right (string &optional regexp)
227 "Trim STRING of trailing string matching REGEXP.
228
229REGEXP defaults to \"[ \\t\\n\\r]+\"."
230 (let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
231 string)))
232 (if i (substring string 0 i) string)))
233
234(defsubst string-trim (string &optional trim-left trim-right)
235 "Trim STRING of leading and trailing strings matching TRIM-LEFT and TRIM-RIGHT.
236
237TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
238 (string-trim-left (string-trim-right string trim-right) trim-left))
239
240;;;###autoload 218;;;###autoload
241(defun string-truncate-left (string length) 219(defun string-truncate-left (string length)
242 "Truncate STRING to LENGTH, replacing initial surplus with \"...\"." 220 "Truncate STRING to LENGTH, replacing initial surplus with \"...\"."
diff --git a/lisp/faces.el b/lisp/faces.el
index 10675563ea2..3ea4c940a32 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -25,8 +25,6 @@
25 25
26;;; Code: 26;;; Code:
27 27
28(eval-when-compile (require 'subr-x))
29
30(defcustom term-file-prefix (purecopy "term/") 28(defcustom term-file-prefix (purecopy "term/")
31 "If non-nil, Emacs startup performs terminal-specific initialization. 29 "If non-nil, Emacs startup performs terminal-specific initialization.
32It does this by: (load (concat term-file-prefix (getenv \"TERM\"))) 30It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
diff --git a/lisp/subr.el b/lisp/subr.el
index ef0e5e6f780..1b93fcf4100 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6200,6 +6200,28 @@ returned list are in the same order as in TREE.
6200;; for discoverability: 6200;; for discoverability:
6201(defalias 'flatten-list #'flatten-tree) 6201(defalias 'flatten-list #'flatten-tree)
6202 6202
6203(defun string-trim-left (string &optional regexp)
6204 "Trim STRING of leading string matching REGEXP.
6205
6206REGEXP defaults to \"[ \\t\\n\\r]+\"."
6207 (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
6208 (substring string (match-end 0))
6209 string))
6210
6211(defun string-trim-right (string &optional regexp)
6212 "Trim STRING of trailing string matching REGEXP.
6213
6214REGEXP defaults to \"[ \\t\\n\\r]+\"."
6215 (let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
6216 string)))
6217 (if i (substring string 0 i) string)))
6218
6219(defun string-trim (string &optional trim-left trim-right)
6220 "Trim STRING of leading and trailing strings matching TRIM-LEFT and TRIM-RIGHT.
6221
6222TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
6223 (string-trim-left (string-trim-right string trim-right) trim-left))
6224
6203;; The initial anchoring is for better performance in searching matches. 6225;; The initial anchoring is for better performance in searching matches.
6204(defconst regexp-unmatchable "\\`a\\`" 6226(defconst regexp-unmatchable "\\`a\\`"
6205 "Standard regexp guaranteed not to match any string at all.") 6227 "Standard regexp guaranteed not to match any string at all.")