branch: externals/ztree commit 1ebb00cea3f4d85422d733a51e989bdb237ae3eb Author: Alexey Veretennikov <txm.four...@gmail.com> Commit: Alexey Veretennikov <txm.four...@gmail.com>
Issue #52: Added 'd' hotkey for the ztree-dir to open dired. Now in ztree-dir mode hitting 'd' will open a dired for the directory the point is standing on; otherwise the dired will be open for the parent directory. --- README.md | 1 + ztree-dir.el | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc1907a..200843a 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ M-x ztree-dir * To toggle open/closed state of the subtree of the current directory, hit the `x` key. * To visit a file, press `Space` key. * To open file in other window, use `RET` key. +* To open `Dired` with the directory the point is currently on, use the `d` key. ### Customizations Set the `ztree-dir-move-focus` variable to `t` in order to move focus to the other window when the `RET` key is pressed; the default behavior is to keep focus in `ztree-dir` window. diff --git a/ztree-dir.el b/ztree-dir.el index dada7d0..20795d7 100644 --- a/ztree-dir.el +++ b/ztree-dir.el @@ -1,6 +1,6 @@ ;;; ztree-dir.el --- Text mode directory tree -*- lexical-binding: t; -*- -;; Copyright (C) 2013-2016 Free Software Foundation, Inc. +;; Copyright (C) 2013-2018 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov <alexey.veretenni...@gmail.com> ;; @@ -97,7 +97,8 @@ One could add own filters in the following way: `( (,(kbd "H") . ztree-dir-toggle-show-filtered-files) (,(kbd ">") . ztree-dir-narrow-to-dir) - (,(kbd "<") . ztree-dir-widen-to-parent))) + (,(kbd "<") . ztree-dir-widen-to-parent) + (,(kbd "d") . ztree-dir-open-dired-at-point))) @@ -180,6 +181,19 @@ up of the opened." (ztree-change-start-node parent)))) +(defun ztree-dir-open-dired-at-point () + "If the point is on a directory, open DIRED with this directory. +Otherwise open DIRED with the parent directory" + (interactive) + (let* ((line (line-number-at-pos)) + (node (ztree-find-node-in-line line)) + (parent (ztree-get-parent-for-line line))) + (cond ((and node (file-directory-p node)) + (dired node)) + (parent + (dired (ztree-find-node-in-line parent)))))) + + ;;;###autoload (defun ztree-dir (path) "Create an interactive buffer with the directory tree of the PATH given."