aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorLars Ingebrigtsen2020-12-21 18:53:32 +0100
committerLars Ingebrigtsen2020-12-21 18:53:40 +0100
commit87e422f1044068a4d27e5e4bfdbc664d9e4bbc43 (patch)
tree0a383378932cbe4b51a33299df2f3cbf9abaac20 /doc
parente352abeac16725c226c1246e3c83f71b8d3fa689 (diff)
downloademacs-87e422f1044068a4d27e5e4bfdbc664d9e4bbc43.tar.gz
emacs-87e422f1044068a4d27e5e4bfdbc664d9e4bbc43.zip
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')
-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
381usual value is @w{@code{"[ \f\t\n\r\v]+"}}. 381usual value is @w{@code{"[ \f\t\n\r\v]+"}}.
382@end defvar 382@end defvar
383 383
384@defun slice-string string regexp
385Split @var{string} into a list of strings on @var{regexp} boundaries.
386As opposed to @code{split-string}, the boundaries are included in the
387result set:
388
389@example
390(slice-string " two words " " +")
391 @result{} (" two" " words" " ")
392@end example
393@end defun
394
395@defun string-clean-whitespace string
396Clean up the whitespace in @var{string} by collapsing stretches of
397whitespace to a single space character, as well as removing all
398whitespace from the start and the end of @var{string}.
399@end defun
400
401@defun string-fill string length
402Attempt to Word-wrap @var{string} so that no lines are longer than
403@var{length}. Filling is done on whitespace boundaries only. If
404there are individual words that are longer than @var{length}, these
405will not be shortened.
406@end defun
407
408@defun string-limit string length
409Return a string that's shorter than @var{length}. If @var{string} is
410shorter than @var{length}, @var{string} is returned as is. If
411@var{length} is positive, return a substring of @var{string}
412consisting of the first @var{length} characters. If @var{length} is
413negative, return a string of the @var{-length} last characters
414instead.
415@end defun
416
417@defun string-lines string &optional omit-nulls
418Split @var{string} into a list of strings on newline boundaries. If
419@var{omit-nulls}, remove empty lines from the results.
420@end defun
421
384@node Modifying Strings 422@node Modifying Strings
385@section Modifying Strings 423@section Modifying Strings
386@cindex modifying strings 424@cindex modifying strings