abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

Feature request: counsel-recentf with files ordered by last visible #1560

Open wolfv6 opened 6 years ago

wolfv6 commented 6 years ago

Currently counsel-recentf lists file history in minibuffer in the order they where opened.

There is a more human friendly way to list file history. Instead of listing files in the order they were opened, list files in the order they were last visible.

This is more human friendly because it is how human memory works. I remember when I was last looking at something (not when I opened it). So when I think, "I was just looking at such-and-such. What file was that in?", I find the file listed near the top of the minibuffer.

Here is a more detailed description: List currently-visible files at the top of minibuffer. Below currently-visible files, list file history in the order that they where last visible. Every time a file disappears from view, it is moved to just below currently-visible files.

Use cases:

Example minibuffer counsel-recentflv with 2 windows currently open:

file currently open in window1 (currently open files are ordered as they appear in the frame)
file currently open in window2
file last visible at 3:10 (not-visible files are ordered by times they where last visible)
file last visible at 3:15
file last visible at 3:19
file last visible at 3:30

This might be relevant. https://www.emacswiki.org/emacs/RecentFiles mentions recentf variables: file-was-visible-p keep-default-and-visible-recentf-p keep-default-and-visible-recentf-p

abo-abo commented 6 years ago

This sounds more like a feature request for recentf. counsel-recentf is simply a client of recentf, it should not take over the responsibilities of that package.

So I suggest to open a feature request for recentf with M-x report-emacs-bug, since recentf is in Emacs core. Once the functionality is implemented there, counsel-recentf can use it.

If getting things done in the Emacs core seems too slow, you could also set up a new package on MELPA, e.g. better-recentf or something.

basil-conto commented 6 years ago

For posterity, this has been submitted as bug#31385.

zzamboni commented 4 years ago

@basil-conto thanks for submitting this. Did you ever see any progress in that recentf bug, or find a workaround? I have been wondering about this behavior myself recently.

basil-conto commented 4 years ago

@zzamboni No, sorry. I have not followed up on it because I do not use recentf, but as you can see in the linked feature request, neither has anyone else.

tau3000 commented 3 years ago

@wolfv6 @zzamboni The following works well for me.

(use-package switch-buffer-functions
  :defer t
  :after recentf
  :preface
  (defun my-recentf-track-visited-file (_prev _curr)
    (and buffer-file-name
         (recentf-add-file buffer-file-name)))
  :init
  (add-hook 'switch-buffer-functions #'my-recentf-track-visited-file))

cf. https://tsuu32.hatenablog.com/entry/2019/12/16/124052 (in Japanese)

zzamboni commented 3 years ago

@tau3000 thanks for the tip! Works well for me too. I've added this to my config: https://github.com/zzamboni/dot-doom/blob/master/doom.org#miscellaneous-keybindings