Emacs has often been criticized for failing to provide a more extensive string manipulation API (compared to that of programming languages like Ruby and Perl, for instance). As many programs (extensions) running on top of it are doing quite a lot of string manipulation, having a good string API is important. To compensate the lack of certain primitives in Emacs itself a lot of package authors are using these days packages like s.el or simply adding the string functions they need directly to their packages (to reduce the number of third-party deps).
In Emacs 24.4 finally the situation is improving. Finally, we’re getting
string-suffix-p, which was mysteriously missing even though string-prefix-p
has been part of Emacs for years:
1 2 3 4 | |
More importantly, Emacs 24.4 ships with a new built-in library called subr-x, which features
a bunch of other string manipulation functions:
string-blank-pstring-empty-pstring-joinstring-reversestring-trim-leftstring-trim-rightstring-trimstring-remove-prefixstring-remove-suffix
Here’s a brief demo of them in action:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Sure, subr-x is not as extensive as s.el (and will never be), but
I think that it’s a big step in the right direction. It’s likely that
subr-x will be extended in subsequent Emacs versions and some of the
functions from it will be promoted to built-in.
That’s all I have for now. Until next time!