From: Platon Pronko <platon7pronko@gmail.com>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 13:39:37 +0800 [thread overview]
Message-ID: <1c536017-2a39-c533-de41-ccbad7033f7d@gmail.com> (raw)
In-Reply-To: <87v8hj8db7.fsf@mbork.pl>
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
next prev parent reply other threads:[~2023-04-26 5:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 3:55 How to convert an arbitrary string into a filename Marcin Borkowski
2023-04-26 4:03 ` Platon Pronko
2023-04-26 4:42 ` Marcin Borkowski
2023-04-26 5:39 ` Platon Pronko [this message]
2023-04-26 18:32 ` Marcin Borkowski
2023-04-26 5:42 ` Yuri Khan
2023-04-26 18:32 ` Marcin Borkowski
2023-04-26 10:08 ` Jean Louis
2023-04-26 12:30 ` Jean Louis
2023-04-26 13:07 ` Eli Zaretskii
2023-04-27 4:52 ` Jean Louis
2023-04-27 5:53 ` Eli Zaretskii
2023-04-27 8:06 ` Platon Pronko
2023-04-26 18:30 ` Marcin Borkowski
2023-04-26 21:29 ` Emanuel Berg
2023-04-27 6:51 ` Marcin Borkowski
2023-04-26 21:32 ` Emanuel Berg
2023-04-27 6:49 ` Marcin Borkowski
2023-04-29 6:20 ` James Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1c536017-2a39-c533-de41-ccbad7033f7d@gmail.com \
--to=platon7pronko@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@mbork.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.