bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs bug with `[' in filenames


From: Ehud Karni
Subject: Re: Emacs bug with `[' in filenames
Date: Tue, 14 Nov 2000 19:58:23 +0200

On Mon, 13 Nov 2000 23:45:43 GMT, Dave Love <d.love@dl.ac.uk> wrote:
> 
> >>>>> "EK" == Ehud Karni <ehud@unix.simonwiesel.co.il> writes:
> 
>  EK> The problem exist in UNIX too. I created a file named "abc[x]" and
>  EK> checked `find-file' (C-x C-f) on it in various ways. Trying to find
>  EK> it in the exact name quoted in different ways (i.e abc[x], abc\[x\[,
>  EK> abc\\[x\\], "abc[x]") does not work. Finding it with wildcards (i.e.
>  EK> abc*, abc?x?) DOES work.
> 
> Is Info node `Quoted File Names' not clear about this?  (`[[]' should
> effectively quote a bracket, as in globbing.)

Yes, [[] does quote the offending [ (as do replacing it by ? or *).
The problem is that this quoting is not done automaticly by the file
name completion function `file-name-all-completions' or by (interactive
F....), both are builtin functions which call `read-file-name-internal'
(defined in fileio.c).

The following elisp code will change this so the offending characters
will be quoted automaticly (I don't recommend it, it may cause other
problem when wildcards are not expanded. May be it should be an option).
This code was checked in 20.7.

(defvar original-read-file-name-internal nil
    "Save var for `read-file-name-internal' builtin function")

(or original-read-file-name-internal           ; do not set twice
    (setq original-read-file-name-internal 
          (symbol-function 'read-file-name-internal)))

(defun file-name-quote-glob (file-name)
  "Quote any globing character ([, ? *) in FILE-NAME by enclosing them in []."
       (let ((result "")                       ; result strings
             (start 0)                         ; index for search
             mb)                               ; temp match beginning
           (while (string-match "[^[][[?*]" file-name start)
               (setq mb (1+ (match-beginning 0)))
               (setq result (concat result (substring file-name start mb)
                                    "[" (substring file-name mb (1+ mb)) "]"))
               (setq start (1+ mb)))
           (concat result (substring file-name start))))

(defun read-file-name-internal-quote (STRING DIR ACTION) 
  "Replacement function for the built in function that does quoting of globing
characters by use of `file-name-quote-glob' on the original function."
       (mapcar 'file-name-quote-glob
               (funcall original-read-file-name-internal STRING DIR ACTION)))

(fset 'read-file-name-internal 'read-file-name-internal-quote) 


I don't like this solution because if `original-read-file-name-internal'
is destroyed for any reason, there is no way to call the original
builtin function. May be there should be a function (`builtin-call' ?)
that will allow calling a built in function even if it is shadowed by
an elisp function with the same name.

Ehud.


-- 
 @@@@@@ @@@ @@@@@@ @    @   Ehud Karni  Simon & Wiesel  Insurance agency
     @    @      @  @@  @   Tel: +972-3-6212-757    Fax: +972-3-6292-544
     @    @ @    @ @  @@    (USA)  Fax  and  voice  mail:  1-815-5509341
     @    @ @    @ @    @        Better     Safe     Than     Sorry
 http://www.simonwiesel.co.il    mailto:ehud@unix.simonwiesel.co.il



reply via email to

[Prev in Thread] Current Thread [Next in Thread]