]> code.delx.au - gnu-emacs-elpa/blob - ztree.el
Split view and models - for directory tree and for diff tree
[gnu-emacs-elpa] / ztree.el
1 ;;; ztree.el --- Text mode directory tree
2
3 ;; Copyright (C) 2013 Alexey Veretennikov
4 ;;
5 ;; Author: Alexey Veretennikov <alexey dot veretennikov at gmail dot com>
6 ;; Created: 2013-11-1l
7 ;; Version: 1.0.0
8 ;; Keywords: files
9 ;; URL: https://github.com/fourier/ztree
10 ;; Compatibility: GNU Emacs GNU Emacs 24.x
11 ;;
12 ;; This file is NOT part of GNU Emacs.
13 ;;
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.
18 ;;
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.
23 ;;
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/>.
26 ;;
27 ;;; Commentary:
28 ;;
29 ;; Add the following to your .emacs file:
30 ;;
31 ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path)
32 ;; (require 'ztree)
33 ;;
34 ;; Call the ztree interactive function:
35 ;; M-x ztree
36 ;; Open/close directories with double-click, Enter or Space keys
37 ;;
38 ;;; Issues:
39 ;;
40 ;;; TODO:
41 ;; 1) Add some file-handling and marking abilities
42 ;; 2) Extract tree code as as separate package
43 ;;
44 ;;
45 ;;; Change Log:
46 ;;
47 ;; 2013-11-10 (1.0.0)
48 ;; Initial Release.
49 ;;
50 ;;; Code:
51
52 (require 'ztree-view)
53
54 ;;
55 ;; Constants
56 ;;
57
58 (defconst ztree-hidden-files-regexp "^\\."
59 "Hidden files regexp. By default all filest starting with dot '.',
60 including . and ..")
61
62
63 ;;
64 ;; File bindings to the directory tree control
65 ;;
66
67 (defun ztree-insert-buffer-header ()
68 (insert "Directory tree")
69 (newline)
70 (insert "==============")
71 (newline))
72
73 (defun printable-string (string)
74 "Strip newline character from file names, like 'Icon\n'"
75 (replace-regexp-in-string "\n" "" string))
76
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))))
81
82
83 (defun ztree (path)
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*")))
88 (ztree-view buf-name
89 (expand-file-name (substitute-in-file-name path))
90 (list ztree-hidden-files-regexp)
91 'ztree-insert-buffer-header
92 'file-short-name
93 'file-directory-p
94 'string-equal
95 '(lambda (x) (directory-files x 'full))))))
96
97
98 (provide 'ztree)
99 ;;; ztree.el ends here