help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to convert an arbitrary string into a filename


From: Marcin Borkowski
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 20:32:50 +0200
User-agent: mu4e 1.1.0; emacs 30.0.50

On 2023-04-26, at 07:39, Platon Pronko <platon7pronko@gmail.com> wrote:

> On 2023-04-26 12:42, Marcin Borkowski wrote:
>> On 2023-04-26, at 06:03, Platon Pronko <platon7pronko@gmail.com>
>> wrote:
>> 
>>> On 2023-04-26 11:55, Marcin Borkowski wrote:
>>>> Hi all,
>>>> given an arbitrary string, say "Hello, world!!!", I want to have
>>>> a filename with all the runs of weird characters (that is,
>>>> non-alphanumeric ones) converted to dashes (say, "Hello-world").  Is
>>>> there a function for that in Emacs already or should I write my own?
>>>
>>> Something like this?
>>>
>>> (let ((input "Hello, world!!!"))
>>>    (replace-regexp-in-string "[^a-zA-Z0-9]+" "-" input))
>>> ;; "Hello-world-"
>> More or less, possibly with trimming - I know it's simple, I just
>> didn't
>> want to do it if it already exists.  Which I still don't know...  (I
>> suppose not, but I'm not sure.)
>
> The term you are looking for is "slug" ("slugify").

Thanks!

> Quick google search indicates that there's nothing built-in, but there might 
> be some implementations inside other packages. Here's a reference to an 
> implementation in org-roam package: 
> https://mailb.org/pipermail/emacs-berlin/2022/000897.html
>
> Also might be of interest:
> https://github.com/masasam/emacs-easy-hugo/issues/64
> https://melpa.org/#/unidecode

Thanks, too!

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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