Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
Alexey Veretennikov edited this page Apr 8, 2018 · 4 revisions

Welcome to the ztree wiki!

Here is located the user functions/tricks/workarounds which are not the part of official ztree package.

Tips & Tricks

User configuration using use-package

Based on use-package page: https://github.com/jwiegley/use-package

Binding to primary commands within ztree modules

(use-package ztree
  :bind (("<f8>"   . ztree-dir)
         ("C-<f8>" . ztree-diff)))

Binding within local keymaps

  • Only for ztree-dir module.
(use-package ztree-dir
  :bind (:map ztreedir-mode-map
              ("f" . ztree-dir-narrow-to-dir)
              ("b" . ztree-dir-widen-to-parent)))
  • For both ztree-dir and ztree-diff module
(use-package ztree-view
  :bind (:map ztree-mode-map
              ("n" . next-line)
              ("p" . previous-line)))

Binding a function

The ztree-toggle-show-number-of-children function will allow the user to turn on or off the number of directory entries. With this method, the function can be called by hitting / from both ztree-dir and ztree-diff module.

(use-package ztree-view
  :bind (:map ztree-mode-map
              ("n" . next-line)
              ("p" . previous-line)
              ("/" . ztree-toggle-show-number-of-children))
  :preface
  (defun ztree-toggle-show-number-of-children ()
    (interactive)
    (setf ztree-show-number-of-children
          (not ztree-show-number-of-children))
    (ztree-refresh-buffer)))

Open ztree-dir for current file

It is convenient sometimes to have a look at other files in the same directory as the current file is. It is convenient to bind this operation to some key, i.e. F9:

(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)