[Top][All Lists]

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

Re: substitute-in-file-name is not distributive

From: Daniel Colascione
Subject: Re: substitute-in-file-name is not distributive
Date: Wed, 24 Oct 2012 20:28:52 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1

On 10/24/2012 8:20 PM, Stefan Monnier wrote:
>> The trouble is that the core completion code makes unwarranted
>> assumptions about the behavior of expand-in-file-name.  Specifically,
>> completion--tqw-all assumes that (equal (unquote (concat (qnew foo)
>> (qnew bar)) (unquote (quote (concat foo bar))).  Why should that be
>> the case?
> Long story.  For typical escaping/quoting this does hold.
> Of course, for more general rewrites, it doesn't.
> Can you give me your file-name-handler code so I can play with it (I
> don't have Cygwin at hand, but I should be able to make up the
> difference).
> I think the problem is in completion--sifn-requote, which is definitely
> not prepared for the kind of rewrites you're doing.

Here's what I threw together to try to get this working. I took a look at
minibuffer.el and other pieces of code seem to make the same assumption. Maybe
the requote operation needs a a file-name-handler?

(defun cygwin-handler (operation &rest args)
  (when (eq operation 'substitute-in-file-name)

    ;; Convert Windows paths to Cygwin paths.  Take care to preserve
    ;; trailing "." and ".." suffixes so that completion doesn't
    ;; break.  Punt to the regular substitute-in-file-name once we've
    ;; converted the path to a Cygwin one.

    (let* ((path (car args))
           (orig-path path)
           (suffix ""))
      (when (string-match (rx bos
                              (group (* any) (or "/" "\\"))
                              (group  "." (? ".") "/")
        (setf suffix (match-string 2 path))
        (setf path (match-string 1 path)))

      (let ((posix-path
             (concat (cygwin-convert-path-from-windows path)
        (message "CYG: %S -> %S" orig-path posix-path)
        (setf args (list posix-path)))))

  (let ((inhibit-file-name-handlers
         (cons 'cygwin-handler
               (and (eq inhibit-file-name-operation operation)
        (inhibit-file-name-operation operation))
    (apply operation args)))

(add-to-list 'file-name-handler-alist '("\\\\" . cygwin-handler))

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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