Selectrum: Virtual buffers?

Created on 25 Jan 2020  路  17Comments  路  Source: raxod502/selectrum

One thing I like about ivy is the injection of recent files into the switch buffer list. Is that in your plans for selectrum/prescient?

Most helpful comment

I added a command for that in the wiki

All 17 comments

Not as an option to modify the behavior of switch-to-buffer. But you could implement such a command yourself using selectrum-completing-read, and use it instead of switch-to-buffer. What do you think of that?

Thanks. Here's a proof of concept:

(defun kvf/recentf-find-file ()
  "Find a recent file using selectrum."
  (interactive)
  (let ((file (selectrum-completing-read "Choose recent file: "
                                         (mapcar 'abbreviate-file-name recentf-list)
                                         nil t)))
    (when file
      (find-file file))))

If it's important to you to show both files and buffers at the same time, I would suggest checking the source code of selectrum-read-buffer and modifying it to augment the list with files from recentf.

Thanks. I'll close this issue and will continue experimenting when I have time.

Hey @fintelkai, I'm looking for the same functionality (easy access to recentf, which I'm also used to via virtual buffers). What have you come up with since January? Or a broader question, what are folks using to access recently opened files if not through counsel/ivy's virtual buffers? I am struggling to find a function or package that even just lists recently opened files: everyone seems to do it through ido/ivy/helm.

Edit: Honestly what you've posted does like 90% of what I want, bound to C-x C-r like I had counsel-recentf. It's actually kind of nice that my buffer list is longer littered with a million files.

@andschwa I'm currently experimenting with Doom, which has a recent file function, using ivy or helm and processing the recentf list.

It seem that adding virtual buffers from recentf-list is not that easy as merely appending filenames from the recentf-list to the list of buffer names.

Looking at the virtual buffer implementations in ido and ivy (adapted from ido), the candidates from recentf-list are in the form of a list of alist '((name1 . path1) (name2 . path2)). The names serve for sorting, filtering and displaying results in the minibuffer and paths are for visiting the files (e.g. find-file-nonselect). Therefore the combined list of buffers and virtual buffers is passed to either switch-to-buffer or find-file.

In the current selectrum implementation, selectrum-read-buffer is set as read-buffer-function which at most serves for switching to buffer and not visiting files. Am I understanding it correctly?

I added a command for that in the wiki

Oo a wiki...thanks @clemera!

@andschwa Thanks for adding another one. I adjusted it to use completing-read. Whenever possible we should try to avoid to depend on selectrum.

@clemera That's hilarious, I just noticed that when I was looking at in my init.el and fixed it at the same time. Thanks! I borrowed the yank-pop replacement too 馃槃

@andschwa Hehe, I think mine shouldn't depend on selectrum either, but I kind of like the narrowing by prefix.

@clemera, thank you for selectrum-switch-buffer+
I appended my own list of frequently edited files to recentf-list, this way I use only one command instead of three or four to edit the buffer/file I need.

I have linked to the wiki from the README.

Does selectrum-switch-buffer+ still work on the latest version of selectrum? I am getting

Error in post-command-hook (selectrum--minibuffer-post-command-hook): (void-variable cb)

You have to enable lexical binding, by putting a

;; -*- lexical-binding: t -*-

at the top of the file.

I added this information also to the top of the wiki page. I cannot wait until lexical binding becomes the global default; in Emacs 27 it was changed for interactive evaluation but file buffers still use dynamic binding by default.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angrybacon picture angrybacon  路  10Comments

piranha picture piranha  路  7Comments

ashton314 picture ashton314  路  12Comments

gcv picture gcv  路  9Comments

adrianparvino picture adrianparvino  路  4Comments