summaryrefslogtreecommitdiff
path: root/doc/lispref/strings.texi
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-12-21 18:53:32 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2020-12-21 18:53:40 +0100
commit87e422f1044068a4d27e5e4bfdbc664d9e4bbc43 (patch)
tree0a383378932cbe4b51a33299df2f3cbf9abaac20 /doc/lispref/strings.texi
parente352abeac16725c226c1246e3c83f71b8d3fa689 (diff)
downloademacs-87e422f1044068a4d27e5e4bfdbc664d9e4bbc43.tar.gz
Beef up the Emacs string utility set a bit
* doc/lispref/strings.texi (Modifying Strings): Document them. * lisp/emacs-lisp/shortdoc.el (string): Add examples. * lisp/emacs-lisp/subr-x.el (string-clean-whitespace) (string-fill, string-limit, string-lines, slice-string): New functions.
Diffstat (limited to 'doc/lispref/strings.texi')
-rw-r--r--doc/lispref/strings.texi38
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 0f157c39d63..e4ca2617512 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -381,6 +381,44 @@ The default value of @var{separators} for @code{split-string}. Its
usual value is @w{@code{"[ \f\t\n\r\v]+"}}.
@end defvar
+@defun slice-string string regexp
+Split @var{string} into a list of strings on @var{regexp} boundaries.
+As opposed to @code{split-string}, the boundaries are included in the
+result set:
+
+@example
+(slice-string " two words " " +")
+ @result{} (" two" " words" " ")
+@end example
+@end defun
+
+@defun string-clean-whitespace string
+Clean up the whitespace in @var{string} by collapsing stretches of
+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-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
+there are individual words that are longer than @var{length}, these
+will not be shortened.
+@end defun
+
+@defun string-limit string length
+Return a string that's shorter than @var{length}. If @var{string} is
+shorter than @var{length}, @var{string} is returned as is. If
+@var{length} is positive, return a substring of @var{string}
+consisting of the first @var{length} characters. If @var{length} is
+negative, return a string of the @var{-length} last characters
+instead.
+@end defun
+
+@defun string-lines string &optional omit-nulls
+Split @var{string} into a list of strings on newline boundaries. If
+@var{omit-nulls}, remove empty lines from the results.
+@end defun
+
@node Modifying Strings
@section Modifying Strings
@cindex modifying strings