From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleksandr Gavenko Newsgroups: gmane.emacs.help Subject: Re: [elisp] Look for function that create safe file name from string... Date: Tue, 10 Jul 2012 17:34:29 +0300 Organization: At home. Message-ID: <87txxfelca.fsf@desktop.home.int> References: <87sjd0af41.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1341930919 16052 80.91.229.3 (10 Jul 2012 14:35:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Jul 2012 14:35:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 10 16:35:17 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SobX2-0006dI-Gu for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jul 2012 16:35:16 +0200 Original-Received: from localhost ([::1]:46538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobX1-0003ok-GI for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jul 2012 10:35:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobWn-0003cj-Eu for help-gnu-emacs@gnu.org; Tue, 10 Jul 2012 10:35:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SobWf-00082Y-52 for help-gnu-emacs@gnu.org; Tue, 10 Jul 2012 10:35:00 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:49382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobWe-00082D-Uj for help-gnu-emacs@gnu.org; Tue, 10 Jul 2012 10:34:53 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SobWV-00061R-HX for help-gnu-emacs@gnu.org; Tue, 10 Jul 2012 16:34:43 +0200 Original-Received: from 46.185.20.32 ([46.185.20.32]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jul 2012 16:34:43 +0200 Original-Received: from gavenkoa by 46.185.20.32 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jul 2012 16:34:43 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 46.185.20.32 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:Sei+3TtQwk98qMaCiRz3Oc3QtNw= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85761 Archived-At: >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 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!