diff options
| author | Lars Ingebrigtsen | 2020-12-21 18:53:32 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-12-21 18:53:40 +0100 |
| commit | 87e422f1044068a4d27e5e4bfdbc664d9e4bbc43 (patch) | |
| tree | 0a383378932cbe4b51a33299df2f3cbf9abaac20 /doc | |
| parent | e352abeac16725c226c1246e3c83f71b8d3fa689 (diff) | |
| download | emacs-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.texi | 38 |
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 | |||
| 381 | usual value is @w{@code{"[ \f\t\n\r\v]+"}}. | 381 | usual value is @w{@code{"[ \f\t\n\r\v]+"}}. |
| 382 | @end defvar | 382 | @end defvar |
| 383 | 383 | ||
| 384 | @defun slice-string string regexp | ||
| 385 | Split @var{string} into a list of strings on @var{regexp} boundaries. | ||
| 386 | As opposed to @code{split-string}, the boundaries are included in the | ||
| 387 | result 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 | ||
| 396 | Clean up the whitespace in @var{string} by collapsing stretches of | ||
| 397 | whitespace to a single space character, as well as removing all | ||
| 398 | whitespace from the start and the end of @var{string}. | ||
| 399 | @end defun | ||
| 400 | |||
| 401 | @defun string-fill string length | ||
| 402 | Attempt to Word-wrap @var{string} so that no lines are longer than | ||
| 403 | @var{length}. Filling is done on whitespace boundaries only. If | ||
| 404 | there are individual words that are longer than @var{length}, these | ||
| 405 | will not be shortened. | ||
| 406 | @end defun | ||
| 407 | |||
| 408 | @defun string-limit string length | ||
| 409 | Return a string that's shorter than @var{length}. If @var{string} is | ||
| 410 | shorter than @var{length}, @var{string} is returned as is. If | ||
| 411 | @var{length} is positive, return a substring of @var{string} | ||
| 412 | consisting of the first @var{length} characters. If @var{length} is | ||
| 413 | negative, return a string of the @var{-length} last characters | ||
| 414 | instead. | ||
| 415 | @end defun | ||
| 416 | |||
| 417 | @defun string-lines string &optional omit-nulls | ||
| 418 | Split @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 |