punassuming / ranger.el

Bringing the goodness of ranger to dired!
699 stars 52 forks source link

Switch buffer returning to previous buffer in cases when not necessary #178

Open Luis-Henriquez-Perez opened 6 years ago

Luis-Henriquez-Perez commented 6 years ago

While in a buffer, opening deer, and selecting a file to open, the buffer I started with flashes on the screen and is visible for a short time just before deer opens the selected file. With dired this does not happen (or maybe it happens so fast I can't perceive it.) Its a minor thing but I find it distracting.

Steps to reproduce:

  1. open emacs
  2. start in a buffer (like scratch)
  3. open deer window
  4. navigate to a file and select it

Observed Behavior original buffer flashes on screen for a certain amount of time (depends on how big the file you're opening is).

Luis-Henriquez-Perez commented 6 years ago

I think I found the culprit: it's ranger revert. Specifically, its the if minimal if statement. I'm going to be honest I don't completely understand every the code is doing other than that it's trying to restore the window configuration somehow by going to a live buffer. I think in my case it's assuming that I have ranger-cleanup-eagerly set to t (which I don't, it's nil) and it's trying to do something with the live buffer. Since I have ranger-cleanup-on-disable set to t perhaps it should not do this yet. Below I put a comment where I added a line to stop the switching buffer. However I'm not 100% sure whether this is a good thing to do (ie pull request potential) or will break something. So when you can please let me know.

(if minimal
      (when (and prev-buffer
                 ranger-cleanup-eagerly ;; line that I added
                 (buffer-live-p prev-buffer))
        (switch-to-buffer prev-buffer)
        (goto-char prev-point))
    (when (and config
               (window-configuration-p config))
      (set-window-configuration config)
      (r--aremove ranger-f-alist (window-frame))))