* [elisp] Look for function that create safe file name from string...
@ 2012-07-09 19:12 Oleksandr Gavenko
2012-07-09 20:54 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Oleksandr Gavenko @ 2012-07-09 19:12 UTC (permalink / raw)
To: help-gnu-emacs
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...
--
Best regards!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elisp] Look for function that create safe file name from string...
[not found] <mailman.4423.1341861152.855.help-gnu-emacs@gnu.org>
@ 2012-07-09 19:50 ` Pascal J. Bourguignon
2012-07-10 14:34 ` Oleksandr Gavenko
0 siblings, 1 reply; 4+ messages in thread
From: Pascal J. Bourguignon @ 2012-07-09 19:50 UTC (permalink / raw)
To: help-gnu-emacs
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)))
(clean-filename "Subject: Re: [elisp] Look for function that create
safe file name from string...")
--> "Subject-Re-elisp-Look-for-function-that-createsafe-file-name-from-string..."
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elisp] Look for function that create safe file name from string...
2012-07-09 19:12 Oleksandr Gavenko
@ 2012-07-09 20:54 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2012-07-09 20:54 UTC (permalink / raw)
To: help-gnu-emacs
> From: Oleksandr Gavenko <gavenkoa@gmail.com>
> Date: Mon, 09 Jul 2012 22:12:07 +0300
>
> 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...
I think you will find a few ideas in make-auto-save-file-name.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elisp] Look for function that create safe file name from string...
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
0 siblings, 0 replies; 4+ messages in thread
From: Oleksandr Gavenko @ 2012-07-10 14:34 UTC (permalink / raw)
To: help-gnu-emacs
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!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-10 14:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
2012-07-09 19:12 Oleksandr Gavenko
2012-07-09 20:54 ` Eli Zaretskii
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.