[Top][All Lists]

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

Re: file-name-shadow-mode

From: David Kastrup
Subject: Re: file-name-shadow-mode
Date: Mon, 21 Mar 2005 15:05:38 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> How 'bout the patch below which makes no assumption (that I know of)
> about substitute-in-file-name, and will thus correctly even with
> weird magic file name handlers.

> +  (condition-case nil
> +      (let ((goal (substitute-in-file-name (minibuffer-contents)))
> +         (start (minibuffer-prompt-end))
> +         (end (point-max)))
> +     ;; Binary search for the greatest position still equivalent to
> +     ;; the whole.
> +     (while (< (1+ start) end)
> +       (let ((mid (/ (+ start end) 2)))
> +         (if (equal (condition-case nil
> +                        (substitute-in-file-name
> +                         (buffer-substring mid (point-max)))
> +                      (error nil))
> +                    goal)
> +             (setq start mid)
> +           (setq end mid))))
> +     (move-overlay rfn-eshadow-overlay (minibuffer-prompt-end) start))
> +    ;; `substitute-in-file-name' can fail on partial input.
> +    (error nil)))

Cute.  It makes the assumption, however, that there is a unique point
where that equivalence occurs.  I don't think that this is correct:
whenever you split in the middle of an environment variable name,
you'll get a nonmatch that can turn into a match if you happen to look
further.  So it would appear to me that one does not get around either
recognizing syntactical entities and skipping them completely instead
of partially, or going through the whole expression anyhow.

It would appear to me that by far the most robust and also efficient
approach would probably be to provide a
substitute-in-file-name-partially primitive that would expand
everything until the next single non-literal change, returning the
relevant information for splicing in the change and continuing the
scan.  Possibly it might come handy for other file name manipulation

David Kastrup, Kriemhildstr. 15, 44793 Bochum

reply via email to

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