Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to open dired bookmarks in the same window

15 views
Skip to first unread message

Ivanov Dmitry

unread,
Oct 28, 2012, 5:25:49 AM10/28/12
to help-gn...@gnu.org
I asked a question, that nobody knows the answer:

http://stackoverflow.com/questions/13090190/emacs-how-to-open-dired-bookmarks-in-the-same-window

After inspecting the code of bookmark.el I came to conclusion, that every bookmark has a handler function, that is taken in bookmark-get-handler. I think, that I need to attach find-alternate-file function as a handler to every bookmark-directory. So it will be opened in the same buffer.

But I don't know, how to do it. Any ideas?


Drew Adams

unread,
Oct 28, 2012, 10:52:33 AM10/28/12
to Ivanov Dmitry, help-gn...@gnu.org
> http://stackoverflow.com/questions/13090190/emacs-how-to-open-
> dired-bookmarks-in-the-same-window
>
> After inspecting the code of bookmark.el I came to
> conclusion, that every bookmark has a handler function, that
> is taken in bookmark-get-handler. I think, that I need to
> attach find-alternate-file function as a handler to every
> bookmark-directory. So it will be opened in the same buffer.
>
> But I don't know, how to do it. Any ideas?

Use Bookmark+. You do not need to fiddle with the code of the bookmarks
themselves (e.g. the handler function). It is the bookmark _jump_ command that
says whether to use the same or another window when moving to the bookmark
location.

In Bookmark+:
C-x j d is `bmkp-dired-jump
C-x 4 j d is `bmkp-dired-jump-other-window'

You apparently want to use `C-x j d'.

(You can of course bind it to another key. By default, all Bookmark+ jump
commands are on prefix keys `C-x j' and `C-x 4 j'.)

http://www.emacswiki.org/BookmarkPlus


Ivanov Dmitry

unread,
Oct 28, 2012, 12:10:17 PM10/28/12
to Drew Adams, help-gn...@gnu.org
I installed bookmark+ and tried bmkp-dired-jump. But it still opens the directory in a new buffer.


Drew Adams

unread,
Oct 28, 2012, 1:19:36 PM10/28/12
to Ivanov Dmitry, help-gn...@gnu.org
> I installed bookmark+ and tried bmkp-dired-jump. But it still
> opens the directory in a new buffer.

Of course it does. `dired' always does that. And `bmkp-dired-jump' invokes
`dired'.

Your request was that jumping to the bookmark open the dir in the same _window_.
Is that not what you see with `bmkp-dired-jump'? It works for me.

If you want the opened Dired buffer to replace the _buffer_ that was current
when you asked to jump to the bookmark, then add a function that kills that
buffer to `bookmark-after-jump-hook'.

It's not clear what you want.

Be aware BTW that in Dired, even when you use `find-alternate-file' to visit a
subdir in the listing, that does not change how the command `dired' works.

For example, if you use Dired+ and you choose to reuse Dired buffers, so that
when you hit RET on a subdir name in Dired the new Dired buffer replaces the one
where you hit RET, that simply makes use of `find-alternate-file' - it does not
invoke command `dired'.

That Dired+ config choice does not change the behavior of command `dired'. So
for example, if you use `C-x d some-dir', the Dired buffer for `some-dir' does
_not_ replace the buffer that was current when you did `C-x d'.

With that Dired+ config choice, RET in Dired does replace the current Dired
buffer with the one for the subdir you hit RET on - but that's not the same
thing as invoking `dired' on it.

Do you really want to kill the current buffer - whatever it might be - when you
jump to a Dired bookmark? If so, then try doing what I suggested above: use
`bookmark-after-jump-hook'.

For example, try this command (with Bookmark+):

(defun foo (bookmark)
(interactive
(let ((alist (bmkp-dired-alist-only)))
(list (bookmark-get-bookmark
(bmkp-read-bookmark-for-type
"Dired" alist nil nil 'bmkp-dired-history)))))
(let ((this-buf (current-buffer)))
(add-hook 'bookmark-after-jump-hook
`(lambda () (kill-buffer ,this-buf)))
(bmkp-jump-1 bookmark 'switch-to-buffer nil)
(remove-hook 'bookmark-after-jump-hook
`(lambda () (kill-buffer ,this-buf)))))

HTH. I expect that you have enough info now to come up with whatever it is you
really want. If not, look in bookmark+-1.el (and perhaps dired+.el) for more
info.


0 new messages