unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Eglen <S.J.Eglen@damtp.cam.ac.uk>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: Tassilo Horn <thorn@fastmail.fm>,
	Stephen Eglen <S.J.Eglen@damtp.cam.ac.uk>,
	4050@emacsbugs.donarmstrong.com
Subject: bug#4050: 23.1.50; iswitchb virtual buffers don't play well with symlinks
Date: Tue, 15 Sep 2009 12:00:22 +0100	[thread overview]
Message-ID: <25602.1253012422@maps> (raw)

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

I've looked athe bug that Tassilo submitted, and can see the problem.
It occurs when the name of the symlink differs from the name of the file
pointed to. e.g. if I do

ln -s teach txt/org/teaching.org

Then if I have previously visited the file as 'teach', Emacs opens it as
'teach', rather than 'teaching.org'

When iswitchb opens teach, it uses find-file-noselect, which opens the
file 'teaching.org' with that name as the buffer, rather than using the
name 'teach'.  The fix then is to tell iswitchb to use the name returned
by find-file-noselect.  I've attached a new version of the function
iswitchb-read-buffer - please can you test it to see that it solves the
problem for you Tassilo, and then I'll commit a patch.  I guess the only
issue is whether the buffer should be called the name of the symlink
'teach' or the name of the real file 'teaching.org' - is there a way to
tell Emacs to prefer the symlink name?

Thanks for the report -- I didn't even follow the recentf code in
iswitchb, it was contributed by someone else.

Stephen

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: i.el --]
[-- Type: text/x-lisp, Size: 2892 bytes --]

(defun iswitchb-read-buffer (prompt &optional default require-match
				    start matches-set)
  "Replacement for the built-in `read-buffer'.
Return the name of a buffer selected.
PROMPT is the prompt to give to the user.
DEFAULT if given is the default buffer to be selected, which will
go to the front of the list.
If REQUIRE-MATCH is non-nil, an existing buffer must be selected.
If START is a string, the selection process is started with that
string.
If MATCHES-SET is non-nil, the buflist is not updated before
the selection process begins.  Used by isearchb.el."
  (let
      (
       buf-sel
       iswitchb-final-text
       (icomplete-mode nil) ;; prevent icomplete starting up
       )

    (iswitchb-define-mode-map)
    (setq iswitchb-exit nil)
    (setq iswitchb-default
	  (if (bufferp default)
	      (buffer-name default)
	    default))
    (setq iswitchb-text (or start ""))
    (unless matches-set
      (setq iswitchb-rescan t)
      (iswitchb-make-buflist iswitchb-default)
      (iswitchb-set-matches))
    (let
	((minibuffer-local-completion-map iswitchb-mode-map)
	 ;; Record the minibuffer depth that we expect to find once
	 ;; the minibuffer is set up and iswitchb-entryfn-p is called.
	 (iswitchb-minibuf-depth (1+ (minibuffer-depth)))
	 (iswitchb-require-match require-match))
      ;; prompt the user for the buffer name
      (setq iswitchb-final-text (completing-read
				 prompt		  ;the prompt
				 '(("dummy" . 1)) ;table
				 nil		  ;predicate
				 nil ;require-match [handled elsewhere]
				 start	;initial-contents
				 'iswitchb-history)))
    (if (and (not (eq iswitchb-exit 'usefirst))
	     (get-buffer iswitchb-final-text))
	;; This happens for example if the buffer was chosen with the mouse.
	(setq iswitchb-matches (list iswitchb-final-text)
	      iswitchb-virtual-buffers nil))

    ;; If no buffer matched, but a virtual buffer was selected, visit
    ;; that file now and act as though that buffer had been selected.
    (if (and iswitchb-virtual-buffers
	     (not (iswitchb-existing-buffer-p)))
	(let ((virt (car iswitchb-virtual-buffers))
	      (new-buf))
	  ;; Keep the name of the buffer returned by find-file-noselect, as 
	  ;; the buffer 'virt' could be a symlink to a file of a different name.
	  (setq new-buf (buffer-name (find-file-noselect (cdr virt))))
	  (setq iswitchb-matches (list new-buf)
		iswitchb-virtual-buffers nil)))

    ;; Handling the require-match must be done in a better way.
    (if (and require-match
	     (not (iswitchb-existing-buffer-p)))
	(error "Must specify valid buffer"))

    (if (or (eq iswitchb-exit 'takeprompt)
	    (null iswitchb-matches))
	(setq buf-sel iswitchb-final-text)
      ;; else take head of list
      (setq buf-sel (car iswitchb-matches)))

    ;; Or possibly choose the default buffer
    (if  (equal iswitchb-final-text "")
	(setq buf-sel (car iswitchb-matches)))

    buf-sel))

             reply	other threads:[~2009-09-15 11:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-15 11:00 Stephen Eglen [this message]
2009-09-15 11:25 ` bug#4050: 23.1.50; iswitchb virtual buffers don't play well with symlinks Tassilo Horn
2009-09-15 11:43   ` Stephen Eglen
  -- strict thread matches above, loose matches on Subject: below --
2009-09-13 20:23 Chong Yidong
2009-08-05 19:11 Tassilo Horn

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25602.1253012422@maps \
    --to=s.j.eglen@damtp.cam.ac.uk \
    --cc=4050@emacsbugs.donarmstrong.com \
    --cc=cyd@stupidchicken.com \
    --cc=thorn@fastmail.fm \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).