Fuco1 / dired-hacks

Collection of useful dired additions
GNU General Public License v3.0
873 stars 77 forks source link

Don't put point on the header after dired-subtree is collapes; issue … #175

Closed amno1 closed 3 years ago

amno1 commented 3 years ago

Issue #170: dired-subtree-toggle places point at dired-header which is slightly inconvenient. We wish point to remain on the file name when directory is collapsed after dired-subtree-toggle has removed subdirectory from the tree. It is just a small hack to put line back at first file name after collapsing very first line.

Fuco1 commented 3 years ago

If you changed the if to when how does this work as a toggle now? If the tree is not expanded, it will never expand.

There's also a typo in the first function, probably unintentional.

amno1 commented 3 years ago

Indeed :-). I am sorry I was just too fast when I wrote that; here is one I use for myself which works:

   ;; fixes the case of the first line in dired when the cursor jumps 
   ;; to the header in dired rather then to the first file in buffer
   (defun dired-subtree-toggle ()
     "Insert subtree at point or remove it if it was not present."
     (interactive)
     (if (dired-subtree--is-expanded-p)
         (progn
           (dired-next-line 1)
           (dired-subtree-remove)
           (when (bobp)
             (dired-next-line 1)))
       (save-excursion (dired-subtree-insert))))

Do you want a PR or you will fix it yourself directly?

Fuco1 commented 3 years ago

Can you explain a bit more the behaviour you are seeing?

When I put point at a directory and execute dired-subtree-toggle it expands it and when I call it again it collapses, the point always sits at the directory and never moves.

What do you mean by "header" in this context?

amno1 commented 3 years ago

Matus Goljer notifications@github.com writes:

Can you explain a bit more the behaviour you are seeing?

When I put point at a directory and execute dired-subtree-toggle it expands it and when I call it again it collapses, the point always sits at the directory and never moves. Not when the cursor is at the very first file in Dired. At least not on mine computer. On all other lines it works as you describe it.

What do you mean by "header" in this context? The headerline. Dires shows the headerline and it puts the name of the directory in it.

Hope above answers the first question too!

Fuco1 commented 3 years ago

Not when the cursor is at the very first file in Dired. At least not on mine computer. On all other lines it works as you describe it.

I cannot reproduce this, for me even on the first line it stays on the file name.

amno1 commented 3 years ago

Matus Goljer notifications@github.com writes:

Not when the cursor is at the very first file in Dired. At least not on mine computer. On all other lines it works as you describe it.

I cannot reproduce this, for me even on the first line it stays on the file name.

Ok, I can't tell why, but for me it does not. Maybe it is something with Dired settings and ls switches that causes it the different behaviour? But for the little hack ensures the cursor stays on the first filename.

Fuco1 commented 3 years ago

I used the newer version from the comment, it should be harmless for when everything works correctly so it's OK to include it. Thanks!