fourier / ztree

Directory tree comparison mode for Emacs
http://www.emacswiki.org/emacs/ZtreeDiff
GNU General Public License v3.0
239 stars 21 forks source link

Feature request: open ztree-dir at point #58

Closed rchar01 closed 6 years ago

rchar01 commented 6 years ago

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 hitting q. 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 pressing q we will use kill-buffer to exit).

What do you think about it?

fourier commented 6 years ago

Why the widen/narrow is not enough for this?

rchar01 commented 6 years ago

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.

fourier commented 6 years ago

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.

rchar01 commented 6 years ago

An article on the wiki is a good idea. I did not know that it is easy to define it in the user configuration.

fourier commented 6 years ago

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.

rchar01 commented 6 years ago

Thanks for the advice. The example you posted doesn't work.

fourier commented 6 years ago

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

rchar01 commented 6 years ago

I have used the code in the wrong way, sorry for my complaints. Thanks for the explanation.

fourier commented 6 years ago

Shall I close this issue? Will you do your wrappers for yourself then?

fourier commented 6 years ago

Also the wiki on Github shall be available for edit, so you can place your solutions there.

rchar01 commented 6 years ago

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.

fourier commented 6 years ago

Ok I've added my idea to the wiki, so I'm closing this issue.