unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Emanuel Berg <incal@dataswamp.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to convert an arbitrary string into a filename
Date: Thu, 27 Apr 2023 08:51:50 +0200	[thread overview]
Message-ID: <87jzxx95rt.fsf@mbork.pl> (raw)
In-Reply-To: <87fs8mwcvf.fsf@dataswamp.org>


On 2023-04-26, at 23:29, Emanuel Berg <incal@dataswamp.org> wrote:

> Marcin Borkowski wrote:
>
>> 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?
>
> There are functions to do this to strings, what comes to mind
> is `replace-regexp-in-string', but what difference do you mean
> there are between filenames and strings that look like filenames?

Not sure if I wrote anything like that...

> To me it would be enough downcase all chars, convert chars
> with various decorations to their ASCII base equivalents (e.g.
> our Swedish å, ä, and ö to a, a, and o - not that one should
> use non-English for filenames so a bad example, but sometimes
> English has such chars as well), then use the dash char as the
> word delimiter, and after that probably just drop remaining
> non-alphanumerics.

Yeah, more or less.  (Actually, I'm a bit on the fence about downcasing,
and I agree with the rest.)

Best,

-- 
Marcin Borkowski
http://mbork.pl



  reply	other threads:[~2023-04-27  6:51 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
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jzxx95rt.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    --cc=incal@dataswamp.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).