Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for virtual-buffer configuration. #2169

Closed
gusbrs opened this issue Jul 25, 2019 · 4 comments
Closed

Allow for virtual-buffer configuration. #2169

gusbrs opened this issue Jul 25, 2019 · 4 comments

Comments

@gusbrs
Copy link
Contributor

@gusbrs gusbrs commented Jul 25, 2019

This is a feature request, alongside a proposed implementation.

ivy-use-virtual-buffers is brilliant, and is suggested in the documentation as one of the most basic variables to enable in Ivy. However, it bundles together recent files and bookmarks, which are quite different things. Furthermore, it doesn't treat bookmarks as such, but by design (#567, #347) it only offers the files to which the bookmarks refer.

Given that, it would be nice if Ivy allowed us to choose what to include in the virtual-buffers. If you like the idea, it could go about like:

(defcustom ivy-use-virtual-buffers nil
  "When non-nil, add recent files and/or bookmarks to `ivy-switch-buffer'.
The value `recentf' includes only recent files to the virtual
buffers list, whereas the value `bookmarks' does the same for
bookmarks.  Any other non-nil value includes both."
  :type '(choice
          (const :tag "Don't use virtual buffers" nil)
          (const :tag "Recent files" recentf)
          (const :tag "Bookmarks" bookmarks)
          (const :tag "All virtual buffers" t)))

(defun ivy--virtual-buffers ()
  "Adapted from `ido-add-virtual-buffers-to-list'."
  (require 'bookmark)
  (unless recentf-mode
    (recentf-mode 1))
  ;; start of changes
  (bookmark-maybe-load-default-file)
  (let* ((vb-recent recentf-list)
         (vb-bkm (delete "   - no file -"
                         (delq nil (mapcar #'bookmark-get-filename
                                           bookmark-alist))))
         (vb-list (cond ((eq ivy-use-virtual-buffers 'recentf)
                         vb-recent)
                        ((eq ivy-use-virtual-buffers 'bookmarks)
                         vb-bkm)
                        (ivy-use-virtual-buffers
                         (append vb-recent vb-bkm))
                        (t nil)))
         virtual-buffers)
    (dolist (head vb-list)
      ;; end of changes
      (let* ((file-name (if (stringp head)
                            head
                          (cdr head)))
             (name (cond ((eq ivy-virtual-abbreviate 'name)
                          (file-name-nondirectory file-name))
                         ((eq ivy-virtual-abbreviate 'abbreviate)
                          (abbreviate-file-name file-name))
                         (t
                          (expand-file-name file-name)))))
        (when (equal name "")
          (setq name
                (if (consp head)
                    (car head)
                  (file-name-nondirectory (directory-file-name file-name)))))
        (unless (or (equal name "")
                    (get-file-buffer file-name)
                    (assoc name virtual-buffers))
          (push (cons (copy-sequence name) file-name) virtual-buffers))))
    (when virtual-buffers
      (dolist (comp virtual-buffers)
        (put-text-property 0 (length (car comp))
                           'face 'ivy-virtual
                           (car comp)))
      (setq ivy--virtual-buffers (nreverse virtual-buffers))
      (mapcar #'car ivy--virtual-buffers))))

If you'd like more comments on why I think this is useful (particularly, the possibility of being able to exclude bookmarks, but keeping recent files, of course), I can expand.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jul 26, 2019

This is a good idea, and the change look good to me. Please PR.

@gusbrs
Copy link
Contributor Author

@gusbrs gusbrs commented Jul 26, 2019

Nice, I'll do so. But, first, I am a PR noob. I should be able to do it, but don't hesitate to correct me if need be, and please be patient. And, second, I currently don't (yet) have the papers signed with the FSF. I presume this amounts to a tiny change, so it would still be ok. Is that correct?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jul 26, 2019

Yes, changes up to 15 lines are counted as tiny and don't need an assignment.

@gusbrs
Copy link
Contributor Author

@gusbrs gusbrs commented Jul 26, 2019

Perfect, I'll prepare it then. Thanks!

astoff pushed a commit to astoff/swiper that referenced this issue Jan 1, 2021
Allow to choose between recent files, bookmarks or both to compose
ivy-switch-buffer's virtual-buffers.

Fixes abo-abo#2169
Fixes abo-abo#2172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants