1 ;;; ztree-dir.el --- Text mode directory tree
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 ;; Author: Alexey Veretennikov <alexey dot veretennikov at gmail dot com>
9 ;; Keywords: files tools
10 ;; URL: https://github.com/fourier/ztree
11 ;; Compatibility: GNU Emacs 24.x
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;; Add the following to your .emacs file:
32 ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path)
33 ;; (require 'ztree-dir)
35 ;; Call the ztree interactive function:
37 ;; Open/close directories with double-click, Enter or Space keys
42 ;; 1) Add some file-handling and marking abilities
53 (defconst ztree-hidden-files-regexp "^\\."
55 By default all filest starting with dot '.', including . and ..")
62 (defface ztreep-header-face
63 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
64 (((background dark)) (:height 1.2 :foreground "lightblue" :weight bold))
65 (t :height 1.2 :foreground "darkblue" :weight bold))
66 "*Face used for the header in Ztree buffer."
67 :group 'Ztree :group 'font-lock-highlighting-faces)
68 (defvar ztreep-header-face 'ztreep-header-face)
72 ;; File bindings to the directory tree control
75 (defun ztree-insert-buffer-header ()
76 "Insert the header to the ztree buffer."
77 (let ((start (point)))
78 (insert "Directory tree")
80 (insert "==============")
81 (set-text-properties start (point) '(face ztreep-header-face)))
84 (defun ztree-file-not-hidden (filename)
85 "Determines if the file with FILENAME should be visible."
86 (not (string-match ztree-hidden-files-regexp
87 (file-short-name filename))))
89 (defun ztree-find-file (node hard)
90 "Find the file at NODE.
92 If HARD is non-nil, the file is opened in another window.
93 Otherwise, the ztree window is used to find the file."
94 (when (and (stringp node) (file-readable-p node))
96 (save-selected-window (find-file-other-window node))
100 (defun ztree-dir (path)
101 "Create an interactive buffer with the directory tree of the PATH given."
102 (interactive "DDirectory: ")
103 (when (and (file-exists-p path) (file-directory-p path))
104 (let ((buf-name (concat "*Directory " path " tree*")))
106 (expand-file-name (substitute-in-file-name path))
107 'ztree-file-not-hidden
108 'ztree-insert-buffer-header
112 '(lambda (x) (directory-files x 'full))
114 'ztree-find-file)))) ; action
118 ;;; ztree-dir.el ends here