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: Platon Pronko
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 13:39:37 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1

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").

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



reply via email to

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