1 ;;; ztree.el --- Text mode directory tree
3 ;; Copyright (C) 2013 Alexey Veretennikov
5 ;; Author: Alexey Veretennikov <alexey dot veretennikov at gmail dot com>
9 ;; URL: https://github.com/fourier/ztree
10 ;; Compatibility: GNU Emacs GNU Emacs 24.x
12 ;; This file is NOT part of GNU Emacs.
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License
16 ;; as published by the Free Software Foundation; either version 2
17 ;; of the License, or (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
29 ;; Add the following to your .emacs file:
31 ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path)
34 ;; Call the ztree interactive function:
36 ;; Open/close directories with double-click, Enter or Space keys
41 ;; 1) Add some file-handling and marking abilities
42 ;; 2) Extract tree code as as separate package
58 (defconst ztree-hidden-files-regexp "^\\."
59 "Hidden files regexp. By default all filest starting with dot '.',
64 ;; File bindings to the directory tree control
67 (defun ztree-insert-buffer-header ()
68 (insert "Directory tree")
70 (insert "==============")
73 (defun printable-string (string)
74 "Strip newline character from file names, like 'Icon\n'"
75 (replace-regexp-in-string "\n" "" string))
77 (defun file-short-name (file)
78 "Base file/directory name. Taken from
79 http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
80 (printable-string (file-name-nondirectory (directory-file-name file))))
84 "Creates an interactive buffer with the directory tree of the path given"
85 (interactive "DDirectory: ")
86 (when (and (file-exists-p path) (file-directory-p path))
87 (let ((buf-name (concat "*Directory " path " tree*")))
89 (expand-file-name (substitute-in-file-name path))
90 (list ztree-hidden-files-regexp)
91 'ztree-insert-buffer-header
95 '(lambda (x) (directory-files x 'full))))))
99 ;;; ztree.el ends here