]> code.delx.au - gnu-emacs-elpa/blob - packages/ztree/ztree-view.el
Merge commit '078f88ecb797b6cf2cd597417402274dd82402ce' from diff-hl
[gnu-emacs-elpa] / packages / ztree / ztree-view.el
1 ;;; ztree-view.el --- Text mode tree view (buffer) -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Alexey Veretennikov <alexey dot veretennikov at gmail dot com>
6 ;;
7 ;; Created: 2013-11-1l
8 ;;
9 ;; Keywords: files tools
10 ;; URL: https://github.com/fourier/ztree
11 ;; Compatibility: GNU Emacs 24.x
12 ;;
13 ;; This file is part of GNU Emacs.
14 ;;
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.
19 ;;
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.
24 ;;
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/>.
27 ;;
28 ;;; Commentary:
29 ;;
30 ;; Add the following to your .emacs file:
31 ;;
32 ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path)
33 ;; (require 'ztree-view)
34 ;;
35 ;; Call the ztree interactive function:
36 ;; Use the following function: ztree-view
37 ;;
38 ;;; Issues:
39 ;;
40 ;;; TODO:
41 ;;
42 ;;
43 ;;; Code:
44
45 (require 'ztree-util)
46
47 ;;
48 ;; Globals
49 ;;
50
51 (defvar ztree-expanded-nodes-list nil
52 "A list of Expanded nodes (i.e. directories) entries.")
53 (make-variable-buffer-local 'ztree-expanded-nodes-list)
54
55 (defvar ztree-start-node nil
56 "Start node(i.e. directory) for the window.")
57 (make-variable-buffer-local 'ztree-start-node)
58
59 (defvar ztree-line-to-node-table nil
60 "List of tuples with full node(i.e. file/directory name and the line.")
61 (make-variable-buffer-local 'ztree-line-to-node-table)
62
63 (defvar ztree-start-line nil
64 "Index of the start line - the root.")
65 (make-variable-buffer-local 'ztree-start-line)
66
67 (defvar ztree-parent-lines-array nil
68 "Array of parent lines.
69 The ith value of the array is the parent line for line i.
70 If ith value is i - it is the root line")
71 (make-variable-buffer-local 'ztree-parent-lines-array)
72
73 (defvar ztree-count-subsequent-bs nil
74 "Counter for the subsequest BS keys (to identify double BS).
75 Used in order to not to use cl package and `lexical-let'")
76 (make-variable-buffer-local 'ztree-count-subsequent-bs)
77
78 (defvar ztree-line-tree-properties nil
79 "Hash with key - line number, value - property ('left, 'right, 'both).
80 Used for 2-side trees, to determine if the node exists on left or right
81 or both sides")
82 (make-variable-buffer-local 'ztree-line-tree-properties)
83
84 (defvar ztree-tree-header-fun nil
85 "Function inserting the header into the tree buffer.
86 MUST inster newline at the end!")
87 (make-variable-buffer-local 'ztree-tree-header-fun)
88
89 (defvar ztree-node-short-name-fun nil
90 "Function which creates a pretty-printable short string from the node.")
91 (make-variable-buffer-local 'ztree-node-short-name-fun)
92
93 (defvar ztree-node-is-expandable-fun nil
94 "Function which determines if the node is expandable.
95 For example if the node is a directory")
96 (make-variable-buffer-local 'ztree-node-is-expandable-fun)
97
98 (defvar ztree-node-equal-fun nil
99 "Function which determines if the 2 nodes are equal.")
100 (make-variable-buffer-local 'ztree-node-equal-fun)
101
102 (defvar ztree-node-contents-fun nil
103 "Function returning list of node contents.")
104 (make-variable-buffer-local 'ztree-node-contents-fun)
105
106 (defvar ztree-node-side-fun nil
107 "Function returning position of the node: 'left, 'right or 'both.
108 If not defined(by default) - using single screen tree, otherwise
109 the buffer is split to 2 trees")
110 (make-variable-buffer-local 'ztree-node-side-fun)
111
112 (defvar ztree-node-face-fun nil
113 "Function returning face for the node.")
114 (make-variable-buffer-local 'ztree-node-face-fun)
115
116 (defvar ztree-node-action-fun nil
117 "Function called when Enter/Space pressed on the node.")
118 (make-variable-buffer-local 'ztree-node-action-fun)
119
120 (defvar ztree-node-showp-fun nil
121 "Function called to decide if the node should be visible.")
122 (make-variable-buffer-local 'ztree-node-showp-fun)
123
124
125 ;;
126 ;; Major mode definitions
127 ;;
128
129 (defvar ztree-mode-map
130 (let ((map (make-sparse-keymap)))
131 (define-key map (kbd "\r") 'ztree-perform-action)
132 (define-key map (kbd "SPC") 'ztree-perform-soft-action)
133 (define-key map [double-mouse-1] 'ztree-perform-action)
134 (define-key map (kbd "TAB") 'ztree-jump-side)
135 (define-key map (kbd "g") 'ztree-refresh-buffer)
136 (define-key map (kbd "x") 'ztree-toggle-expand-subtree)
137 (if window-system
138 (define-key map (kbd "<backspace>") 'ztree-move-up-in-tree)
139 (define-key map "\177" 'ztree-move-up-in-tree))
140 map)
141 "Keymap for `ztree-mode'.")
142
143
144 (defface ztreep-node-face
145 '((((background dark)) (:foreground "#ffffff"))
146 (((type nil)) (:inherit 'font-lock-function-name-face))
147 (t (:foreground "Blue")))
148 "*Face used for expandable entries(directories etc) in Ztree buffer."
149 :group 'Ztree :group 'font-lock-highlighting-faces)
150 (defvar ztreep-node-face 'ztreep-node-face)
151
152 (defface ztreep-leaf-face
153 '((((background dark)) (:foreground "cyan1"))
154 (((type nil)) (:inherit 'font-lock-variable-name-face))
155 (t (:foreground "darkblue")))
156 "*Face used for not expandable nodes(leafs, i.e. files) in Ztree buffer."
157 :group 'Ztree :group 'font-lock-highlighting-faces)
158 (defvar ztreep-leaf-face 'ztreep-leaf-face)
159
160 (defface ztreep-arrow-face
161 '((((background dark)) (:foreground "#7f7f7f"))
162 (t (:foreground "#8d8d8d")))
163 "*Face used for arrows in Ztree buffer."
164 :group 'Ztree :group 'font-lock-highlighting-faces)
165 (defvar ztreep-arrow-face 'ztreep-arrow-face)
166
167 (defface ztreep-expand-sign-face
168 '((((background dark)) (:foreground "#7f7fff"))
169 (t (:foreground "#8d8d8d")))
170 "*Face used for expand sign [+] in Ztree buffer."
171 :group 'Ztree :group 'font-lock-highlighting-faces)
172 (defvar ztreep-expand-sign-face 'ztreep-expand-sign-face)
173
174
175 ;;;###autoload
176 (define-derived-mode ztree-mode special-mode "Ztree"
177 "A major mode for displaying the directory tree in text mode."
178 ;; only spaces
179 (setq indent-tabs-mode nil))
180
181 (defun ztree-find-node-in-line (line)
182 "Return the node for the LINE specified.
183 Search through the array of node-line pairs."
184 (gethash line ztree-line-to-node-table))
185
186 (defun ztree-find-node-at-point ()
187 "Find the node at point.
188 Returns cons pair (node, side) for the current point
189 or nil if there is no node"
190 (let ((center (/ (window-width) 2))
191 (node (ztree-find-node-in-line (line-number-at-pos))))
192 (when node
193 (cons node (if (> (current-column) center) 'right 'left)))))
194
195
196 (defun ztree-is-expanded-node (node)
197 "Find if the NODE is in the list of expanded nodes."
198 (ztree-find ztree-expanded-nodes-list
199 #'(lambda (x) (funcall ztree-node-equal-fun x node))))
200
201
202 (defun ztree-set-parent-for-line (line parent)
203 "For given LINE set the PARENT in the global array."
204 (aset ztree-parent-lines-array (- line ztree-start-line) parent))
205
206 (defun ztree-get-parent-for-line (line)
207 "For given LINE return a parent."
208 (when (and (>= line ztree-start-line)
209 (< line (+ (length ztree-parent-lines-array) ztree-start-line)))
210 (aref ztree-parent-lines-array (- line ztree-start-line))))
211
212 (defun scroll-to-line (line)
213 "Recommended way to set the cursor to specified LINE."
214 (goto-char (point-min))
215 (forward-line (1- line)))
216
217
218 (defun ztree-do-toggle-expand-subtree-iter (node state)
219 "Iteration in expanding subtree.
220 Argument NODE current node.
221 Argument STATE node state."
222 (when (funcall ztree-node-is-expandable-fun node)
223 (let ((children (funcall ztree-node-contents-fun node)))
224 (ztree-do-toggle-expand-state node state)
225 (dolist (child children)
226 (ztree-do-toggle-expand-subtree-iter child state)))))
227
228
229 (defun ztree-do-toggle-expand-subtree ()
230 "Implements the subtree expand."
231 (let* ((line (line-number-at-pos))
232 (node (ztree-find-node-in-line line))
233 ;; save the current window start position
234 (current-pos (window-start)))
235 ;; only for expandable nodes
236 (when (funcall ztree-node-is-expandable-fun node)
237 ;; get the current expand state and invert it
238 (let ((do-expand (not (ztree-is-expanded-node node))))
239 (ztree-do-toggle-expand-subtree-iter node do-expand))
240 ;; refresh buffer and scroll back to the saved line
241 (ztree-refresh-buffer line)
242 ;; restore window start position
243 (set-window-start (selected-window) current-pos))))
244
245
246 (defun ztree-do-perform-action (hard)
247 "Toggle expand/collapsed state for nodes or perform an action.
248 HARD specifies (t or nil) if the hard action, binded on RET,
249 should be performed on node."
250 (let* ((line (line-number-at-pos))
251 (node (ztree-find-node-in-line line)))
252 (when node
253 (if (funcall ztree-node-is-expandable-fun node)
254 ;; only for expandable nodes
255 (ztree-toggle-expand-state node)
256 ;; perform action
257 (when ztree-node-action-fun
258 (funcall ztree-node-action-fun node hard)))
259 ;; save the current window start position
260 (let ((current-pos (window-start)))
261 ;; refresh buffer and scroll back to the saved line
262 (ztree-refresh-buffer line)
263 ;; restore window start position
264 (set-window-start (selected-window) current-pos)))))
265
266
267 (defun ztree-perform-action ()
268 "Toggle expand/collapsed state for nodes or perform the action.
269 Performs the hard action, binded on RET, on node."
270 (interactive)
271 (ztree-do-perform-action t))
272
273 (defun ztree-perform-soft-action ()
274 "Toggle expand/collapsed state for nodes or perform the action.
275 Performs the soft action, binded on Space, on node."
276 (interactive)
277 (ztree-do-perform-action nil))
278
279
280 (defun ztree-toggle-expand-subtree()
281 "Toggle Expanded/Collapsed state on all nodes of the subtree"
282 (interactive)
283 (ztree-do-toggle-expand-subtree))
284
285 (defun ztree-do-toggle-expand-state (node do-expand)
286 "Set the expanded state of the NODE to DO-EXPAND."
287 (if (not do-expand)
288 (setq ztree-expanded-nodes-list
289 (ztree-filter
290 #'(lambda (x) (not (funcall ztree-node-equal-fun node x)))
291 ztree-expanded-nodes-list))
292 (push node ztree-expanded-nodes-list)))
293
294
295 (defun ztree-toggle-expand-state (node)
296 "Toggle expanded/collapsed state for NODE."
297 (ztree-do-toggle-expand-state node (not (ztree-is-expanded-node node))))
298
299
300 (defun ztree-move-up-in-tree ()
301 "Action on Backspace key.
302 Jump to the line of a parent node. If previous key was Backspace
303 then close the node."
304 (interactive)
305 (when ztree-parent-lines-array
306 (let* ((line (line-number-at-pos (point)))
307 (parent (ztree-get-parent-for-line line)))
308 (when parent
309 (if (and (equal last-command 'ztree-move-up-in-tree)
310 (not ztree-count-subsequent-bs))
311 (let ((node (ztree-find-node-in-line line)))
312 (when (ztree-is-expanded-node node)
313 (ztree-toggle-expand-state node))
314 (setq ztree-count-subsequent-bs t)
315 (ztree-refresh-buffer line))
316 (progn (setq ztree-count-subsequent-bs nil)
317 (scroll-to-line parent)))))))
318
319
320 (defun ztree-get-splitted-node-contens (node)
321 "Return pair of 2 elements: list of expandable nodes and list of leafs.
322 Argument NODE node which contents will be returned."
323 (let ((nodes (funcall ztree-node-contents-fun node))
324 (comp #'(lambda (x y)
325 (string< (funcall ztree-node-short-name-fun x)
326 (funcall ztree-node-short-name-fun y)))))
327 (cons (sort (ztree-filter
328 #'(lambda (f) (funcall ztree-node-is-expandable-fun f))
329 nodes) comp)
330 (sort (ztree-filter
331 #'(lambda (f) (not (funcall ztree-node-is-expandable-fun f)))
332 nodes) comp))))
333
334
335 (defun ztree-draw-char (c x y &optional face)
336 "Draw char C at the position (1-based) (X Y).
337 Optional argument FACE face to use to draw a character."
338 (save-excursion
339 (scroll-to-line y)
340 (beginning-of-line)
341 (goto-char (+ x (-(point) 1)))
342 (delete-char 1)
343 (insert-char c 1)
344 (put-text-property (1- (point)) (point) 'face (if face face 'ztreep-arrow-face))))
345
346 (defun ztree-draw-vertical-line (y1 y2 x &optional face)
347 "Draw a vertical line of '|' characters from Y1 row to Y2 in X column.
348 Optional argument FACE face to draw line with."
349 (let ((count (abs (- y1 y2))))
350 (if (> y1 y2)
351 (progn
352 (dotimes (y count)
353 (ztree-draw-char ?\| x (+ y2 y) face))
354 (ztree-draw-char ?\| x (+ y2 count) face))
355 (progn
356 (dotimes (y count)
357 (ztree-draw-char ?\| x (+ y1 y) face))
358 (ztree-draw-char ?\| x (+ y1 count) face)))))
359
360 (defun ztree-draw-vertical-rounded-line (y1 y2 x &optional face)
361 "Draw a vertical line of '|' characters finishing with '`' character.
362 Draws the line from Y1 row to Y2 in X column.
363 Optional argument FACE facet to draw the line with."
364 (let ((count (abs (- y1 y2))))
365 (if (> y1 y2)
366 (progn
367 (dotimes (y count)
368 (ztree-draw-char ?\| x (+ y2 y) face))
369 (ztree-draw-char ?\` x (+ y2 count) face))
370 (progn
371 (dotimes (y count)
372 (ztree-draw-char ?\| x (+ y1 y) face))
373 (ztree-draw-char ?\` x (+ y1 count) face)))))
374
375
376 (defun ztree-draw-horizontal-line (x1 x2 y)
377 "Draw the horizontal line from column X1 to X2 in the row Y."
378 (if (> x1 x2)
379 (dotimes (x (1+ (- x1 x2)))
380 (ztree-draw-char ?\- (+ x2 x) y))
381 (dotimes (x (1+ (- x2 x1)))
382 (ztree-draw-char ?\- (+ x1 x) y))))
383
384
385 (defun ztree-draw-tree (tree depth start-offset)
386 "Draw the TREE of lines with parents.
387 Argument DEPTH current depth.
388 Argument START-OFFSET column to start drawing from."
389 (if (atom tree)
390 nil
391 (let* ((root (car tree))
392 (children (cdr tree))
393 (offset (+ start-offset (* depth 4)))
394 (line-start (+ 3 offset))
395 (line-end-leaf (+ 7 offset))
396 (line-end-node (+ 4 offset))
397 ;; determine if the line is visible. It is always the case
398 ;; for 1-sided trees; however for 2 sided trees
399 ;; it depends on which side is the actual element
400 ;; and which tree (left with offset 0 or right with offset > 0
401 ;; we are drawing
402 (visible #'(lambda (line) ()
403 (if (not ztree-node-side-fun) t
404 (let ((side
405 (gethash line ztree-line-tree-properties)))
406 (cond ((eq side 'left) (= start-offset 0))
407 ((eq side 'right) (> start-offset 0))
408 (t t)))))))
409 (when children
410 ;; draw the line to the last child
411 ;; since we push'd children to the list, it's the first visible line
412 ;; from the children list
413 (let ((last-child (ztree-find children
414 #'(lambda (x)
415 (funcall visible (ztree-car-atom x)))))
416 (x-offset (+ 2 offset)))
417 (when last-child
418 (ztree-draw-vertical-rounded-line (1+ root)
419 (ztree-car-atom last-child)
420 x-offset)))
421 ;; draw recursively
422 (dolist (child children)
423 (ztree-draw-tree child (1+ depth) start-offset)
424 (let ((end (if (listp child) line-end-node line-end-leaf)))
425 (when (funcall visible (ztree-car-atom child))
426 (ztree-draw-horizontal-line line-start
427 end
428 (ztree-car-atom child)))))))))
429
430 (defun ztree-fill-parent-array (tree)
431 "Set the root lines array.
432 Argument TREE nodes tree to create an array of lines from."
433 (let ((root (car tree))
434 (children (cdr tree)))
435 (dolist (child children)
436 (ztree-set-parent-for-line (ztree-car-atom child) root)
437 (when (listp child)
438 (ztree-fill-parent-array child)))))
439
440
441 (defun ztree-insert-node-contents (path)
442 "Insert node contents with initial depth 0.
443 `ztree-insert-node-contents-1' return the tree of line
444 numbers to determine who is parent line of the
445 particular line. This tree is used to draw the
446 graph.
447 Argument PATH start node."
448 (let ((tree (ztree-insert-node-contents-1 path 0))
449 ;; number of 'rows' in tree is last line minus start line
450 (num-of-items (- (line-number-at-pos (point)) ztree-start-line)))
451 ;; create a parents array to store parents of lines
452 ;; parents array used for navigation with the BS
453 (setq ztree-parent-lines-array (make-vector num-of-items 0))
454 ;; set the root node in lines parents array
455 (ztree-set-parent-for-line ztree-start-line ztree-start-line)
456 ;; fill the parent arrray from the tree
457 (ztree-fill-parent-array tree)
458 ;; draw the tree starting with depth 0 and offset 0
459 (ztree-draw-tree tree 0 0)
460 ;; for the 2-sided tree we need to draw the vertical line
461 ;; and an additional tree
462 (if ztree-node-side-fun ; 2-sided tree
463 (let ((width (window-width)))
464 ;; draw the vertical line in the middle of the window
465 (ztree-draw-vertical-line ztree-start-line
466 (1- (+ num-of-items ztree-start-line))
467 (/ width 2)
468 'vertical-border)
469 (ztree-draw-tree tree 0 (1+ (/ width 2)))))))
470
471
472 (defun ztree-insert-node-contents-1 (node depth)
473 "Recursively insert contents of the NODE with current DEPTH."
474 (let* ((expanded (ztree-is-expanded-node node))
475 ;; insert node entry with defined depth
476 (root-line (ztree-insert-entry node depth expanded))
477 ;; children list is the list of lines which are children
478 ;; of the root line
479 (children nil))
480 (when expanded ;; if expanded we need to add all subnodes
481 (let* ((contents (ztree-get-splitted-node-contens node))
482 ;; contents is the list of 2 elements:
483 (nodes (car contents)) ; expandable entries - nodes
484 (leafs (cdr contents))) ; leafs - which doesn't have subleafs
485 ;; iterate through all expandable entries to insert them first
486 (dolist (node nodes)
487 ;; if it is not in the filter list
488 (when (funcall ztree-node-showp-fun node)
489 ;; insert node on the next depth level
490 ;; and push the returning result (in form (root children))
491 ;; to the children list
492 (push (ztree-insert-node-contents-1 node (1+ depth))
493 children)))
494 ;; now iterate through all the leafs
495 (dolist (leaf leafs)
496 ;; if not in filter list
497 (when (funcall ztree-node-showp-fun leaf)
498 ;; insert the leaf and add it to children
499 (push (ztree-insert-entry leaf (1+ depth) nil)
500 children)))))
501 ;; result value is the list - head is the root line,
502 ;; rest are children
503 (cons root-line children)))
504
505 (defun ztree-insert-entry (node depth expanded)
506 "Inselt the NODE to the current line with specified DEPTH and EXPANDED state."
507 (let ((line (line-number-at-pos))
508 (expandable (funcall ztree-node-is-expandable-fun node))
509 (short-name (funcall ztree-node-short-name-fun node)))
510 (if ztree-node-side-fun ; 2-sided tree
511 (let ((right-short-name (funcall ztree-node-short-name-fun node t))
512 (side (funcall ztree-node-side-fun node))
513 (width (window-width)))
514 (when (eq side 'left) (setq right-short-name ""))
515 (when (eq side 'right) (setq short-name ""))
516 (ztree-insert-single-entry short-name depth
517 expandable expanded 0
518 (when ztree-node-face-fun
519 (funcall ztree-node-face-fun node)))
520 (ztree-insert-single-entry right-short-name depth
521 expandable expanded (1+ (/ width 2))
522 (when ztree-node-face-fun
523 (funcall ztree-node-face-fun node)))
524 (puthash line side ztree-line-tree-properties))
525 (ztree-insert-single-entry short-name depth expandable expanded 0))
526 (puthash line node ztree-line-to-node-table)
527 (insert "\n")
528 line))
529
530 (defun ztree-insert-single-entry (short-name depth
531 expandable expanded
532 offset
533 &optional face)
534 "Writes a SHORT-NAME in a proper position with the type given.
535 Writes a string with given DEPTH, prefixed with [ ] if EXPANDABLE
536 and [-] or [+] depending on if it is EXPANDED from the specified OFFSET.
537 Optional argument FACE face to write text with."
538 (let ((node-sign #'(lambda (exp)
539 (insert "[" (if exp "-" "+") "]")
540 (set-text-properties (- (point) 3)
541 (point)
542 '(face ztreep-expand-sign-face)))))
543 (move-to-column offset t)
544 (delete-region (point) (line-end-position))
545 (when (> depth 0)
546 (dotimes (i depth)
547 (insert " ")
548 (insert-char ?\s 3))) ; insert 3 spaces
549 (when (> (length short-name) 0)
550 (if expandable
551 (progn
552 (funcall node-sign expanded) ; for expandable nodes insert "[+/-]"
553 (insert " ")
554 (put-text-property 0 (length short-name)
555 'face (if face face 'ztreep-node-face) short-name)
556 (insert short-name))
557 (progn
558 (insert " ")
559 (put-text-property 0 (length short-name)
560 'face (if face face 'ztreep-leaf-face) short-name)
561 (insert short-name))))))
562
563 (defun ztree-jump-side ()
564 "Jump to another side for 2-sided trees."
565 (interactive)
566 (when ztree-node-side-fun ; 2-sided tree
567 (let ((center (/ (window-width) 2)))
568 (cond ((< (current-column) center)
569 (move-to-column (1+ center)))
570 ((> (current-column) center)
571 (move-to-column 1))
572 (t nil)))))
573
574
575
576 (defun ztree-refresh-buffer (&optional line)
577 "Refresh the buffer.
578 Optional argument LINE scroll to the line given."
579 (interactive)
580 (when (and (equal major-mode 'ztree-mode)
581 (boundp 'ztree-start-node))
582 (setq ztree-line-to-node-table (make-hash-table))
583 ;; create a hash table of node properties for line
584 ;; used in 2-side tree mode
585 (when ztree-node-side-fun
586 (setq ztree-line-tree-properties (make-hash-table)))
587 (toggle-read-only)
588 (erase-buffer)
589 (funcall ztree-tree-header-fun)
590 (setq ztree-start-line (line-number-at-pos (point)))
591 (ztree-insert-node-contents ztree-start-node)
592 (scroll-to-line (if line line ztree-start-line))
593 (toggle-read-only)))
594
595
596 (defun ztree-view (
597 buffer-name
598 start-node
599 filter-fun
600 header-fun
601 short-name-fun
602 expandable-p
603 equal-fun
604 children-fun
605 face-fun
606 action-fun
607 &optional node-side-fun
608 )
609 "Create a ztree view buffer configured with parameters given.
610 Argument BUFFER-NAME Name of the buffer created.
611 Argument START-NODE Starting node - the root of the tree.
612 Argument FILTER-FUN Function which will define if the node should not be
613 visible.
614 Argument HEADER-FUN Function which inserts the header into the buffer
615 before drawing the tree.
616 Argument SHORT-NAME-FUN Function which return the short name for a node given.
617 Argument EXPANDABLE-P Function to determine if the node is expandable.
618 Argument EQUAL-FUN An equality function for nodes.
619 Argument CHILDREN-FUN Function to get children from the node.
620 Argument FACE-FUN Function to determine face of the node.
621 Argument ACTION-FUN an action to perform when the Return is pressed.
622 Optional argument NODE-SIDE-FUN Determines the side of the node."
623 (let ((buf (get-buffer-create buffer-name)))
624 (switch-to-buffer buf)
625 (ztree-mode)
626 ;; configure ztree-view
627 (setq ztree-start-node start-node)
628 (setq ztree-expanded-nodes-list (list ztree-start-node))
629 (setq ztree-node-showp-fun filter-fun)
630 (setq ztree-tree-header-fun header-fun)
631 (setq ztree-node-short-name-fun short-name-fun)
632 (setq ztree-node-is-expandable-fun expandable-p)
633 (setq ztree-node-equal-fun equal-fun)
634 (setq ztree-node-contents-fun children-fun)
635 (setq ztree-node-face-fun face-fun)
636 (setq ztree-node-action-fun action-fun)
637 (setq ztree-node-side-fun node-side-fun)
638 (ztree-refresh-buffer)))
639
640
641 (provide 'ztree-view)
642 ;;; ztree-view.el ends here