From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org, snogglethorpe@gmail.com,
teirllm@dms.auburn.edu, miles@gnu.org
Subject: Re: file-name-shadow-mode
Date: Wed, 23 Mar 2005 17:55:28 -0500 [thread overview]
Message-ID: <jwvu0n2jaau.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87is3lw2yk.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 21 Mar 2005 08:24:38 -0500")
> How 'bout the patch below which makes no assumption (that I know of) about
> substitute-in-file-name, and will thus work correctly even with weird
> magic file name handlers.
Regarding performance of my code: I just bumped into a performance problem.
The problem is that substitute-in-file-name can take a non-negligible amount
of time to execute when there's a "~user" in the file name, because it calls
getpwnam to figure out whether "user" actually exists or not.
At least here with 8K users in our YP database, my code causes
file-name-shadow-mode to take around 0.5-1s to refresh the screen after each
key stroke if there's a ~user in the file name I'm editing.
So I've tweaked my code to streamline the common case where the shadow
doesn't need to be moved. I also fixed the problem where a file name like
"/home/foo/bar/:toto//tata" was sometimes shadowed as "r/:toto//tata"
instead of just "/tata".
Stefan
--- orig/lisp/rfn-eshadow.el
+++ mod/lisp/rfn-eshadow.el
@@ -97,7 +97,7 @@
'(face file-name-shadow field shadow)
"Properties given to the `shadowed' part of a filename in the minibuffer.
Only used when `file-name-shadow-mode' is active.
-If emacs is not running under a window system,
+If Emacs is not running under a window system,
`file-name-shadow-tty-properties' is used instead."
:type file-name-shadow-properties-custom-type
:group 'minibuffer)
@@ -123,20 +123,6 @@
\f
;;; Internal variables
-;; Regexp to locate dividing point between shadow and real pathname
-(defconst rfn-eshadow-regexp
- (cond ((memq system-type '(ms-dos windows-nt))
- ;; This horrible regexp considers the following patterns as
- ;; starting an absolute pathname, when following a `/' or an `\':
- ;; L: / // ~ $ \\ \\\\
- "\\(.*[^/]+/+?\\|/*?\\|\\)\\(~\\|$[^$]\\|$\\'\\|[][\\^a-z]:\\|//?\\([^][\\^a-z/$~]\\|[^/$~][^:]\\|[^/$~]?\\'\\)\\)")
- (t
- ;; default is for unix-style filenames
- "\\(.*/\\)\\([/~]\\|$[^$]\\|$\\'\\)"))
- "Regular expression used to match shadowed filenames.
-There should be at least one regexp group; the end of the first one
-is used as the end of the shadowed portion of the filename.")
-
;; A list of minibuffers to which we've added a post-command-hook.
(defvar rfn-eshadow-frobbed-minibufs nil)
@@ -170,31 +156,54 @@
(add-to-list 'rfn-eshadow-frobbed-minibufs (current-buffer))
(add-hook 'post-command-hook #'rfn-eshadow-update-overlay nil t)))
+(defsubst rfn-eshadow-sifn-equal (goal pos)
+ (equal goal (buffer-substring-no-properties pos (point-max))))
+
;; post-command-hook to update overlay
(defun rfn-eshadow-update-overlay ()
"Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
This is intended to be used as a minibuffer post-command-hook for
`file-name-shadow-mode'; the minibuffer should have already
been set up by `rfn-eshadow-setup-minibuffer'."
- ;; This is not really a correct implementation; it won't always do the
- ;; right thing in the presence of environment variables that
- ;; substitute-in-file-name would expand; currently it just assumes any
- ;; environment variable contains an absolute filename.
- (save-excursion
- (let ((inhibit-point-motion-hooks t))
- (goto-char (minibuffer-prompt-end))
- ;; Update the overlay (which will evaporate if it's empty).
- (move-overlay rfn-eshadow-overlay
- (point)
- (if (looking-at rfn-eshadow-regexp)
- (match-end 1)
- (point))))))
+ ;; This code usually is instantaneous, but if the file name includes
+ ;; a "~<user>", substitute-in-file-name will lookup your system's list of
+ ;; users to see whether "<user>" is an actual user or not, and that
+ ;; can sometimes take a while, so we wrap this in `while-no-input'.
+ (while-no-input
+ (condition-case nil
+ (let ((goal (substitute-in-file-name (minibuffer-contents)))
+ (mid (overlay-end rfn-eshadow-overlay))
+ (start (minibuffer-prompt-end))
+ (end (point-max)))
+ (unless
+ ;; Catch the common case where the shadow does not need to move.
+ (and mid
+ (or (eq mid end)
+ (not (rfn-eshadow-sifn-equal goal (1+ mid))))
+ (or (eq mid start)
+ (rfn-eshadow-sifn-equal goal mid)))
+ ;; Binary search for the greatest position still equivalent to
+ ;; the whole.
+ (while (or (< (1+ start) end)
+ (if (and (< (1+ end) (point-max))
+ (rfn-eshadow-sifn-equal goal (1+ end)))
+ ;; (SIFN end) != goal, but (SIFN (1+end)) == goal,
+ ;; We've reached a discontinuity: this can happen
+ ;; e.g. if `end' point to "/:...".
+ (setq start (1+ end) end (point-max))))
+ (setq mid (/ (+ start end) 2))
+ (if (equal (condition-case nil
+ (rfn-eshadow-sifn-equal goal mid)
+ (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)
+ )))
\f
-;;; Note this definition must be at the end of the file, because
-;;; `define-minor-mode' actually calls the mode-function if the
-;;; associated variable is non-nil, which requires that all needed
-;;; functions be already defined. [This is arguably a bug in d-m-m]
;;;###autoload
(define-minor-mode file-name-shadow-mode
"Toggle File-Name Shadow mode.
@@ -222,5 +231,5 @@
(provide 'rfn-eshadow)
-;;; arch-tag: dcf70a52-0115-4ec2-b1e3-4f8d3541a888
+;; arch-tag: dcf70a52-0115-4ec2-b1e3-4f8d3541a888
;;; rfn-eshadow.el ends here
next prev parent reply other threads:[~2005-03-23 22:55 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-17 9:16 file-name-shadow-mode David Kastrup
2005-03-17 12:16 ` file-name-shadow-mode Matt Hodges
2005-03-18 1:56 ` file-name-shadow-mode Miles Bader
2005-03-18 1:59 ` file-name-shadow-mode Miles Bader
2005-03-18 2:17 ` file-name-shadow-mode Nick Roberts
2005-03-18 4:35 ` file-name-shadow-mode Luc Teirlinck
2005-03-18 4:47 ` file-name-shadow-mode Stefan Monnier
2005-03-18 4:55 ` file-name-shadow-mode Luc Teirlinck
2005-03-18 5:18 ` file-name-shadow-mode Luc Teirlinck
2005-03-18 5:37 ` file-name-shadow-mode Luc Teirlinck
2005-03-18 18:20 ` file-name-shadow-mode Richard Stallman
2005-03-19 15:21 ` file-name-shadow-mode Luc Teirlinck
2005-03-19 15:45 ` file-name-shadow-mode David Kastrup
2005-03-19 16:45 ` file-name-shadow-mode Stefan Monnier
2005-03-20 2:14 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 14:13 ` file-name-shadow-mode Stefan Monnier
2005-03-20 16:02 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 16:18 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 2:30 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 3:33 ` file-name-shadow-mode Miles Bader
2005-03-20 4:28 ` file-name-shadow-mode David Kastrup
2005-03-20 17:30 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 18:10 ` file-name-shadow-mode David Kastrup
2005-03-21 1:19 ` file-name-shadow-mode Richard Stallman
2005-03-20 18:01 ` file-name-shadow-mode Richard Stallman
2005-03-20 18:24 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 18:47 ` file-name-shadow-mode David Kastrup
2005-03-20 21:11 ` file-name-shadow-mode Luc Teirlinck
2005-03-20 21:25 ` file-name-shadow-mode Luc Teirlinck
2005-03-21 13:44 ` file-name-shadow-mode Stefan Monnier
2005-03-21 22:24 ` file-name-shadow-mode Luc Teirlinck
2005-03-21 23:00 ` file-name-shadow-mode Stefan Monnier
2005-03-22 20:44 ` file-name-shadow-mode Richard Stallman
2005-03-28 21:32 ` file-name-shadow-mode Stefan Monnier
2005-03-21 13:24 ` file-name-shadow-mode Stefan Monnier
2005-03-21 14:05 ` file-name-shadow-mode David Kastrup
2005-03-21 16:48 ` file-name-shadow-mode Stefan Monnier
2005-03-22 3:34 ` file-name-shadow-mode Richard Stallman
2005-03-21 14:26 ` file-name-shadow-mode Miles Bader
2005-03-21 15:14 ` file-name-shadow-mode David Kastrup
2005-03-21 15:47 ` file-name-shadow-mode David Kastrup
2005-03-21 16:58 ` file-name-shadow-mode Stefan Monnier
2005-03-21 23:57 ` file-name-shadow-mode Luc Teirlinck
2005-03-23 22:55 ` Stefan Monnier [this message]
2005-03-24 0:04 ` file-name-shadow-mode David Kastrup
2005-03-25 6:42 ` file-name-shadow-mode Richard Stallman
2005-03-25 8:45 ` file-name-shadow-mode David Kastrup
2005-03-18 5:23 ` file-name-shadow-mode Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvu0n2jaau.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=miles@gnu.org \
--cc=snogglethorpe@gmail.com \
--cc=teirllm@dms.auburn.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.