From: Oleksandr Gavenko <gavenkoa@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: [elisp] Look for function that create safe file name from string...
Date: Tue, 10 Jul 2012 17:34:29 +0300 [thread overview]
Message-ID: <87txxfelca.fsf@desktop.home.int> (raw)
In-Reply-To: 87sjd0af41.fsf@kuiper.lan.informatimago.com
From Eli Zaretskii:
> I think you will find a few ideas in make-auto-save-file-name.
>
I look sources and most useful thing I find (for me) is replacement of '/'
with '!'. Also this piece are good:
;; Restrict the characters used in the file name to those which
;; are known to be safe on all filesystems, url-encoding the
;; rest.
...
(while (string-match "[^A-Za-z0-9-_.~#+]" buffer-name limit)
...
But I lose Russian chars...
On 2012-07-09, Pascal J. Bourguignon wrote:
> Oleksandr Gavenko <gavenkoa@gmail.com> writes:
>
>> I decide store my message after sending it to mail/news.
>>
>> As file name I use date and message header.
>>
>> But message header may contain danger symbol. One of errors I get when '/'
>> char present in file name...
>>
>> So I look for function that safely escape string to get file name in portable
>> for Emacs way...
>
> (defun alphanumericp (ch)
> (find ch "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
>
> (defun clean-filename (name)
> (remove-if-not (lambda (ch) (or (alphanumericp ch) (find ch "-_.")))
> (substitute ?- 32 name)))
>
I like your solution. But as I need Russian/Ukrainian chars I write another
code (without cl dependency):
(defconst my-safe-filename-char-regex "[[:alnum:]-_!.@]"
"Safe file names.")
(defun my-clean-filename (filename)
(mapconcat
(lambda (ch) (or (when (string-match my-safe-filename-char-regex (char-to-string ch)) (char-to-string ch)) "-"))
filename "") )
Resulted file name does not contain spaces, so I can easy write sh scripts on
these files.
Thanks for help to both!
--
Best regards!
next prev parent reply other threads:[~2012-07-10 14:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.4423.1341861152.855.help-gnu-emacs@gnu.org>
2012-07-09 19:50 ` [elisp] Look for function that create safe file name from string Pascal J. Bourguignon
2012-07-10 14:34 ` Oleksandr Gavenko [this message]
2012-07-09 19:12 Oleksandr Gavenko
2012-07-09 20:54 ` Eli Zaretskii
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=87txxfelca.fsf@desktop.home.int \
--to=gavenkoa@gmail.com \
--cc=help-gnu-emacs@gnu.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).