Closed amno1 closed 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.
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?
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?
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!
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.
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.
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!
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.