emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 87e422f: Beef up the Emacs string utility set a bit


From: Clément Pit-Claudel
Subject: Re: master 87e422f: Beef up the Emacs string utility set a bit
Date: Mon, 21 Dec 2020 15:20:56 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 12/21/20 1:44 PM, Lars Ingebrigtsen wrote:
> I've been going through
> 
> https://github.com/magnars/s.el
> 
> to see whether there's anything there that seems both 1) useful and 2)
> Emacs doesn't have already, but there was less than I remembered,
> really.  With the five functions I added, the rest are mostly just
> aliases for stuff we have in Emacs 28.
> 
> Things I wasn't sure about:
> 
> s-chomp (s)
> 
> Is this really useful?  Emacs is so un-line-oriented that I can't recall
> having removed newlines from a string ever...

Look for (replace-regexp-in-string "\n$" "" and variants, or string-trim-right. 
 One common use case is in conjunction with shell-command-to-string.  Even if 
it was in Emacs, though, I'm not sure I'd find it and use it instead of 
string-trim-end.

> s-shared-start (s1 s2)
> s-shared-end (s1 s2)

It's useful for computing relative paths (as done by file-relative-name) and 
for abbreviating entries in a list (finding the common prefix of many entries 
and abbreviating them all that way).  It's a trivial extension of 
compare-strings, but discoverability isn't great.  The implementation of 
s-shared-start in s.el is inefficient, but my patch 
(https://github.com/magnars/s.el/pull/134/files) was never merged.

An efficient implementation of s-shared-end would be nice, but I think it would 
require generalizing compare-strings.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]