From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Florian von Savigny Newsgroups: gmane.emacs.bugs Subject: otherwise nice bugfix which doesn't work Date: 02 Jan 2004 02:08:08 +0100 Organization: 1&1 Internet AG Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1073006988 12433 80.91.224.253 (2 Jan 2004 01:29:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 2 Jan 2004 01:29:48 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 02 02:29:43 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AcE8F-0005gl-00 for ; Fri, 02 Jan 2004 02:29:43 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AcF4D-0002NT-QU for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Jan 2004 21:29:37 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AcF48-0002Mm-T6 for bug-gnu-emacs@prep.ai.mit.edu; Thu, 01 Jan 2004 21:29:32 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AcEl4-00069i-0e for bug-gnu-emacs@prep.ai.mit.edu; Thu, 01 Jan 2004 21:10:21 -0500 Original-Received: from [216.168.1.22] (helo=trinity.supernews.net) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AcEl0-00065t-IS for bug-gnu-emacs@prep.ai.mit.edu; Thu, 01 Jan 2004 21:09:46 -0500 Original-Received: from mxintern.kundenserver.de ([212.227.126.201]:52810 helo=mxintern.schlund.de) by trinity.supernews.net with esmtp (Exim 4.24; FreeBSD) id 1AcDnV-000MOs-8u for gnu-emacs-bug@moderators.isc.org; Fri, 02 Jan 2004 01:08:17 +0000 Original-Received: from [195.20.224.124] (helo=news.schlund.de) by mxintern.kundenserver.de with esmtp (Exim 3.35 #1) id 1AcDnO-0008Ri-00 for gnu-emacs-bug@moderators.isc.org; Fri, 02 Jan 2004 02:08:10 +0100 Original-Received: from news by news.schlund.de with local (Exim 3.35 #1 (Debian)) id 1AcDnN-0001r7-00 for ; Fri, 02 Jan 2004 02:08:09 +0100 Original-To: gnu-emacs-bug@moderators.isc.org Original-Path: news.online.de!not-for-mail Original-Newsgroups: gnu.emacs.bug Original-Lines: 162 Original-NNTP-Posting-Host: pd9506f44.dip0.t-ipconnect.de Original-X-Trace: online.de 1073005689 7135 217.80.111.68 (2 Jan 2004 01:08:09 GMT) Original-X-Complaints-To: abuse@einsundeins.com Original-NNTP-Posting-Date: Fri, 2 Jan 2004 01:08:09 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:6451 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:6451 Hi, I decided to post this here since it is intendend to fix a minor annoyance for those people using Emacs under a *nix system who mount file systems like vfat (but it should work for any fs). Under these circumstances, Emacs is unaware that some characters will be illegal (as distinct from when it is running under Windoze). This has become apparent to me because my home directory is on a vfat partition, and Emacs tries to save my "*mail*" buffers to auto save files which contain asterisks in their names, which naturally fails, and this causes very annoying interruptions. Using very valuable advice from Eli Zaretskii, I wrote the below solution, which works like a swell, but has the disadvantage of reliably messing some things up I did not expect to be related: - trying to find a file is sanctioned by "Wrong type argument: stringp, nil" - M-x mail does swap you to a "*mail*" buffer, but it is the "*scratch*" buffer it puts in mail-mode (and it also inserts the header lines there) There must be something very basic I don't know. ;;; alien-fs.el --- make Emacs avoid forbidden characters in filenames ;;; if creating files on alien filesystems ;; Copyright (C) 2003 Free Software Foundation, Inc. ;; Author: Florian v. Savigny ;; Credits to: Eli Zaretskii (who made this possible) ;; This file is part of GNU Emacs. ;;; (Copyright information left out here) ;;; Commentary: ;;; There is as yet no mechanism for Emacs to behave appropriately ;;; when creating files on alien file systems; i.e. if Emacs is ;;; running under GNU/Linux and tries to create e.g. an auto-save-file ;;; on a VFAT partition, it is unaware it must not use the characters ;;; "\/:*?"<>|" for its name, and hence will fail if it happens to use ;;; one of them. ;;; This file provides two functions: one that returns the filesystem ;;; type for a given file by querying "df", and one re-definition of ;;; convert-standard-filename that uses the former to convert the ;;; filename argument only if necessary and with customisable and ;;; fine-grained rules for each filesystem type. These rules are ;;; specified in the variable filename-fs-specific-char-conversions. ;;; It can be hoped that convert-standard-filename will in the future ;;; be called by all functions that create a file. As this does not ;;; yet seem to be the case, however, this file has stolen a way of ;;; doing this for make-auto-save-file-name at least (see below) from ;;; w32-fns.el. (defun filename-get-fs-type (filename) "Takes an absolute or relative filename and returns the type of file system (in the notation used by mount(8)) that emacs will, or would, put this file on. Whether the filename supplied is (would be) legal on that filesystem is not tested." (let (fs) (setq filename (file-name-directory (expand-file-name filename))) (call-process "df" nil "*df*" nil "-T" filename) (set-buffer "*df*") (goto-char (point-min)) (search-forward-regexp "^/dev/[^ ]+[ ]+\\([^ ]+\\)[ ]" nil t) ; the character classes include tabs here - maybe unnecessarily. (setq fs (match-string 1)) (kill-buffer "*df*") fs)) (defvar filename-fs-specific-char-conversions '(("vfat" . (("\\*" . "%a") (":" . "%c") ("\\?" . "%!") ("\"" . "%q") ("<" . "%l") (">" . "%g") ("|" . "%p") ("ä" . "ae") ("ö" . "oe") ("ü" . "ue") ("ß" . "ss"))) ) "List of dotted pairs the car of which is a filesystem identifier (see mount(8) which ones are valid) and the cdr is a list of rules how to convert filename characters for the given filesystem. Each rule is also a dotted pair, and conversions are performed in the order the rules are specified. Note that the car of the rule is in regexp notation, hence you can specify character classes to be replaced all by the same character (as in \"(\"[*?\"<]\" . \"!\")).") (defun convert-standard-filename (filename) "Standard emacs function re-written to be filesystem-sensitive. It converts any filename to something suitable for the type of filesystem the latter is going to be stored on. Filesystem-specific conversion rules must be stored in `filename-fs-specific-char-conversions'. If the latter contains no entry for the type of filesystem in question, the filename is returned unchanged." (let ((int 0) (fs (filename-get-fs-type filename)) rule) (if (setq rules (assoc fs filename-fs-specific-char-conversions)) ; test if there is an entry for this filesystem (while (setq rule (nth int (cdr rules))) (while (string-match (car rule) filename) (setq filename (replace-match (cdr rule) nil t filename))) (setq int (+ int 1))) ; this was the true part: no else part needed )) filename) ;; the following is taken literally from w32-fns.el: ;; Avoid creating auto-save file names containing invalid characters. (fset 'original-make-auto-save-file-name (symbol-function 'make-auto-save-file-name)) (defun make-auto-save-file-name () "Return file name to use for auto-saves of current buffer. Does not consider `auto-save-visited-file-name' as that variable is checked before calling this function. You can redefine this for customization. See also `auto-save-file-name-p'." (convert-standard-filename (original-make-auto-save-file-name))) ;;; end of file Any comment would be greatly appreciated, since I would very much like to have this working. "It works like a swell" would be worded more precisely as "the functions work as expected when trying them out in the *scratch* buffer", i.e. (make-auto-save-file-name) will yield sth. like "/home/florian/#*scratch*#720hEM#" if the above file is not loaded, but "/home/florian/#%ascratch%a#720hEM#" if it is (/home/florian is on a vfat partition). On an ext2 partition, the names will both have asterisks, no matter whether the file is loaded or not. -- Florian v. Savigny If you are going to reply in private, please be patient, as I only check for mail something like once a week. - Si vous allez répondre personellement, patientez s.v.p., car je ne lis les courriels qu'environ une fois par semaine.