String-manipulation utilities for Emacs Lisp.
String-utils is a collection of functions for string manipulation. This library has no user-level interface; it is only useful for programming in Emacs Lisp.
The following functions are provided:
string-utils-stringify-anything
string-utils-has-darkspace-p
string-utils-has-whitespace-p
string-utils-trim-whitespace
string-utils-compress-whitespace
string-utils-string-repeat
string-utils-escape-double-quotes
string-utils-quotemeta
string-utils-pad
string-utils-pad-list
string-utils-propertize-fillin
The most complex function is string-utils-pad
, the docstring
for which is reproduced below:
(string-utils-pad STR-VAL WIDTH &optional MODE CHAR THROW-ERROR)
Pad STR-VAL to WIDTH.
Optional MODE defaults to 'right
, but may be 'left
, 'center
, or
an integer.
When MODE is 'left
, padding characters are prepended. When MODE
is 'center
, padding characters are both appended and prepended so
that STR-VAL is centered within WIDTH.
When MODE is a positive integer, the behavior is fixed-position
padding. Similar to 'center
, padding may be added on the right
and on the left. Exactly MODE-many padding characters are
added on the left before padding to the full WIDTH on the right.
When MODE is a negative integer, the behavior is the same, except
that MODE fixes the right-side padding.
Optional CHAR sets the padding character (defaults to space).
Optional THROW-ERROR throws an error if the length of STR-VAL already exceeds WIDTH, or if the fixed-position padding requested would cause the result to exceed WIDTH. When THROW-ERROR is not set (the default), a best-attempt result is always returned.
Tabs are expanded to spaces according to the value of
tab-width
.
Returns a padded copy of string STR-VAL.
Tested only on GNU Emacs version 24.1
No external dependencies