combine switch-to-buffer, recentf, bookmarks together #347

Closed
stardiviner opened this Issue Jan 15, 2016 · 19 comments

Projects

None yet

2 participants

@stardiviner

I wish ivy(counsel) can provide a function to combine switch-to-buffer, recentf, bookmark together.
I want this function because I always open files, I don't know whether I closed buffer (it's in recentf), or not opened still in bookmark list. I want a union entry to access all of them despiting their state difference.
I like the behavior of helm-mini. It provide user to put resources into entry.

@abo-abo
Owner
abo-abo commented Jan 15, 2016

ivy-switch-buffer already combines switch-to-buffer and recentf. I can add an option for bookmarks, but it's probably better to have them separate: bookmarks are for quick access and change rarely; aggregating them into ivy-switch-buffer would mean that either they would be dead weight increasing the number of candidates for no reason, or bookmark-jump would become obsolete although it's faster for having less candidates and changing the candidate list rarely.

@stardiviner

I see.
If you think combine them together is un-necessary in official repository.
I can accept define a user custom function in my init file.
Can you provide the code to do this? Thanks.

@abo-abo
Owner
abo-abo commented Jan 18, 2016
(setq ivy-use-virtual-buffers t)

Makes ivy-switch-buffer use bookmarks and recentf. Such an old feature that I forgot that it did bookmarks too.

@abo-abo
Owner
abo-abo commented Jan 18, 2016

By the way, this customization is also shown in (Info-goto-node "(ivy)").

@stardiviner

I tried option ivy-use-virtual-buffers. It includes recentf. But does not have bookmarks.

@abo-abo
Owner
abo-abo commented Jan 18, 2016

It completes off bookmarks-alist. Do you have that variable configured properly (should be the case if you didn't touch it)?

@stardiviner

I check out bookmark-alist, but it is nil. I tested with emacs -q. It is fine.
I will debug my configs. Thanks.

@stardiviner

I found ivy switch buffers shows candidates does not match with my bookmarks result. (I also tested with emacs -q.)
Here are steps I use in emacs -q:

  1. package-initialize
  2. (require 'bookmark)
;; load bookmarks from file.
(with-eval-after-load 'bookmark
  (setq-default bookmark-default-file
                (expand-file-name "bookmarks.el" user-emacs-directory))
  (bookmark-maybe-load-default-file))
  1. (require 'swiper)
(setq ivy-use-virtual-buffers t ; treat recentf, bookmarks as virtual buffers.
        ivy-height 5
        ivy-display-style 'fancy
        ivy-count-format "(%d/%d) "
        ivy-initial-inputs-alist nil ; remove initial ^ input.
        ivy-extra-directories nil ; remove . and .. directory.
        ivy-wrap nil
        )
(ivy-mode 1)
  1. (global-set-key [remap switch-to-buffer] 'ivy-switch-buffer)

Here are two screenshots. one is using bookmark list, and another is using ivy-switch-buffer.

http://imgur.com/gallery/T3Hga/

@abo-abo
Owner
abo-abo commented Jan 19, 2016

Eval:

(mapcar (lambda (bookmark)
          (cdr (assoc 'filename bookmark)))
        bookmark-alist)

Should return a list of strings.

@stardiviner

This returned list of strings is correct with bookmark-bmenu-list result.

@abo-abo
Owner
abo-abo commented Jan 19, 2016

Have a look at:

(progn
  (ivy--virtual-buffers)
  ivy--virtual-buffers)

Maybe bisect your config until the return result becomes correct.

@stardiviner

After evaluating upper code, the returned result is wrong.
I will bisect my init files.
Thanks for your help.

@stardiviner

I got different candidates result after setting ivy-virtual-abbreviate to 'full. The 'full value result is correct.

@stardiviner

I know why now, because ivy-virtual-abbreviate 'name (uniquify) is enabled, makes bookmarks which has same file-name-nondirectory. They are combined to one candidate.

@abo-abo
Owner
abo-abo commented Jan 19, 2016

I've been using 'name for a very long time, with no problems. Other people prefer 'full. Something like 'uniquify is in the works, but it's boring to debug and release.

@stardiviner

with uniquify.
The bookmarks which has file path to the same filename like bellowing:

#("/home/stardiviner/Org/Wiki/Computer/Programming/Programming Languages/Python/Data/Packages/Packages.org" 0 103
   (face ivy-virtual))
 #("/home/stardiviner/Org/Wiki/Computer/Programming/Programming Languages/JavaScript/Data/Packages/Packages.org" 0 107
   (face ivy-virtual))
 #("/home/stardiviner/Org/Wiki/Computer/Programming/Programming Languages/TeX/Data/Macro Packages/Macro Packages.org" 0 112
   (face ivy-virtual))
 #("/home/stardiviner/Org/Wiki/Computer/Programming/Programming Languages/Julia/Data/Packages/Packages.org" 0 102
   (face ivy-virtual))

I think ivy should not use bookmark filename path value as candidate, should use bookmark name instead. This can avoid uniquify like this issue.

@abo-abo
Owner
abo-abo commented Jan 19, 2016

Nothing says that the bookmark names are unique wrt buffer names.

@stardiviner

Emm, right.

@stardiviner

I will 'full as the value. Problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment