emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.35k stars 283 forks source link

Restrict adding certain buffers to jump list #1848

Closed gekoke closed 9 months ago

gekoke commented 9 months ago

Issue type

Is there any way to restrict certain buffers being added to the jump list?

I use dirvish, which is a wrapper around dired. Often times after I'm done using dirvish, I press q to bury its buffer. These visits get added to the evil jump list.

I'd like to avoid this behaviour for a few reasons:

I'm not sure if this behavior is specific to dirvish, or if it's the same with plain dired as well - I haven't tested that.

I would possibly even like to restrict the jump list to only file-visiting buffers, but I'm not sure if that's exactly what I want yet.

tomdl89 commented 9 months ago

Have you tried adding patterns to evil-jumps-ignored-file-patterns ? I haven't tried it myself, but looks like it should work. Let me know if it doesn't.

gekoke commented 9 months ago

Have you tried adding patterns to evil-jumps-ignored-file-patterns ? I haven't tried it myself, but looks like it should work. Let me know if it doesn't.

That sounds like what I want. I couldn't find any mention of it in the docs. I'll try it out in a bit.

Do you know if non-file-visiting buffers being added to the jump list is expected behavior?

tomdl89 commented 9 months ago

There's handling for non-file-visiting buffers in the code, so I'd say it probably is expected behaviour.

edit: ah that handling says if the buffer has no filename, but it does match evil--jumps-buffer-targets then it's a valid jump target. So unless you add non-file-visiting buffer patterns there, I guess not.

gekoke commented 9 months ago

Looks like this custom variable does what I need. https://github.com/emacs-evil/evil/blob/16506d934342fd905ce4c88684f04ddb123c02a4/evil-jumps.el#L55

gekoke commented 9 months ago

I got around to actually trying to implement the fix, but I'm running into some issues.

The buffers I wanted to ignore are dired buffers, and dired buffers are just set to the name of whatever directory they are visiting by default.

I tried to rename the dired buffers, figuring I could just match on them that way:

(use-package evil
  ;; ...
  :config
  (evil-mode 1)
  (add-hook 'dired-mode-hook (lambda () (rename-buffer (generate-new-buffer-name (format "*Dired: %s*" dired-directory)))))
  (add-to-list 'evil-jumps-ignored-file-patterns "\*Dirvish.*")
  (add-to-list 'evil-jumps-ignored-file-patterns "\*Dired:.*"))

But this doesn't seem to work. I'm guessing evil adds it to the jump list before the rename occurs? :/

gekoke commented 9 months ago

Working back from the source code, I was able to come up with this:

(use-package evil
  :config
  (evil-mode 1)
  (add-to-list 'evil-jumps-ignored-file-patterns ".*/$"))

This works because the filename that evil internally assigns to dired buffers always ends with a / character.

Perhaps a evil-jump-visit-dired-buffers custom variable or similar would be a nice-to-have.