Closed rchar01 closed 6 years ago
Why the widen/narrow is not enough for this?
Using the wide/narrow function the user loses the ability to return to the previously set state of the directory subtree (open/closeed).
It's just an idea, I do not know if users really need this functionality, you can always open a new ztree-dir buffer.
However, I think it is more convenient for the user if ztree-dir would suggests the default directory when used, e.g. when we use ztree-dir from dired buffer, by default, ztree-dir will suggest the directory in which we are located. The default directory for creating a new ztee-dir buffer (from the existing ztree-dir) is "~ /", no difference in what directory we are. Unless we have previously opened the dired buffer, then it is different.
You can write a function which will provide the default directory to ztree-dir, and run ztree-dir via this function. Not sure I would need this function in basic functionality, rather on a wiki.
An article on the wiki is a good idea. I did not know that it is easy to define it in the user configuration.
You can write something like this for example to open ztree for the directory the current buffer belongs to:
(require 'subr-x)
(defun open-ztree-for-current-buffer ()
"Open ztree in the directory of the current buffer"
(interactive)
(when-let ((current-file (buffer-file-name (current-buffer)))
(dir (file-name-directory current-file)))
(ztree-dir dir)))
and bind it to some hotkey for the mode you are working in or globally. Or write your implementation to whatever suits your needs.
Thanks for the advice. The example you posted doesn't work.
Not sure how did you use it. I just right now put the following to the scratch buffer:
(require 'subr-x)
(defun open-ztree-for-current-buffer ()
"Open ztree in the directory of the current buffer"
(interactive)
(when-let ((current-file (buffer-file-name (current-buffer)))
(dir (file-name-directory current-file)))
(ztree-dir dir)))
(global-set-key [f9] 'open-ztree-for-current-buffer)
As I said this will do nothing when there is no file associated with the buffer, but you would have to just change when-let to if-let and do the "else" statement providing default directory to the ztree-dir
call
I have used the code in the wrong way, sorry for my complaints. Thanks for the explanation.
Shall I close this issue? Will you do your wrappers for yourself then?
Also the wiki on Github shall be available for edit, so you can place your solutions there.
If possible, please leave this thread open. I will try to write something to work the way I want. I will post the code here in case of problems.
Similar to the function: "open Dired with the directory the point is currently on".
I think it would be nice to have the option of opening a new ztree-dir buffer at the current cursor position in ztree-dir (e.g. by hitting "C-t"). Similar to opening a new dired buffer in dired (by hitting
RET
). The entire open / closed state of the directory subtree will remain unchanged, and it would be easy to return to it by hittingq
. And just like in dired, if we open the same directory again (ztree-dir at point) the state from the previous visit will be preserved (unless instead of pressingq
we will usekill-buffer
to exit).What do you think about it?