]> code.delx.au - gnu-emacs-elpa/blob - packages/ztree/ztree-view.el
multishell - merge code tidying, still on 1.0.8.
[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)
330 comp)
331 (sort (ztree-filter
332 #'(lambda (f) (not (funcall ztree-node-is-expandable-fun f)))
333 nodes)
334 comp))))
335
336
337 (defun ztree-draw-char (c x y &optional face)
338 "Draw char C at the position (1-based) (X Y).
339 Optional argument FACE face to use to draw a character."
340 (save-excursion
341 (scroll-to-line y)
342 (beginning-of-line)
343 (goto-char (+ x (-(point) 1)))
344 (delete-char 1)
345 (insert-char c 1)
346 (put-text-property (1- (point)) (point) 'face (if face face 'ztreep-arrow-face))))
347
348 (defun ztree-draw-vertical-line (y1 y2 x &optional face)
349 "Draw a vertical line of '|' characters from Y1 row to Y2 in X column.
350 Optional argument FACE face to draw line with."
351 (let ((count (abs (- y1 y2))))
352 (if (> y1 y2)
353 (progn
354 (dotimes (y count)
355 (ztree-draw-char ?\| x (+ y2 y) face))
356 (ztree-draw-char ?\| x (+ y2 count) face))
357 (progn
358 (dotimes (y count)
359 (ztree-draw-char ?\| x (+ y1 y) face))
360 (ztree-draw-char ?\| x (+ y1 count) face)))))
361
362 (defun ztree-draw-vertical-rounded-line (y1 y2 x &optional face)
363 "Draw a vertical line of '|' characters finishing with '`' character.
364 Draws the line from Y1 row to Y2 in X column.
365 Optional argument FACE facet to draw the line with."
366 (let ((count (abs (- y1 y2))))
367 (if (> y1 y2)
368 (progn
369 (dotimes (y count)
370 (ztree-draw-char ?\| x (+ y2 y) face))
371 (ztree-draw-char ?\` x (+ y2 count) face))
372 (progn
373 (dotimes (y count)
374 (ztree-draw-char ?\| x (+ y1 y) face))
375 (ztree-draw-char ?\` x (+ y1 count) face)))))
376
377
378 (defun ztree-draw-horizontal-line (x1 x2 y)
379 "Draw the horizontal line from column X1 to X2 in the row Y."
380 (if (> x1 x2)
381 (dotimes (x (1+ (- x1 x2)))
382 (ztree-draw-char ?\- (+ x2 x) y))
383 (dotimes (x (1+ (- x2 x1)))
384 (ztree-draw-char ?\- (+ x1 x) y))))
385
386
387 (defun ztree-draw-tree (tree depth start-offset)
388 "Draw the TREE of lines with parents.
389 Argument DEPTH current depth.
390 Argument START-OFFSET column to start drawing from."
391 (if (atom tree)
392 nil
393 (let* ((root (car tree))
394 (children (cdr tree))
395 (offset (+ start-offset (* depth 4)))
396 (line-start (+ 3 offset))
397 (line-end-leaf (+ 7 offset))
398 (line-end-node (+ 4 offset))
399 ;; determine if the line is visible. It is always the case
400 ;; for 1-sided trees; however for 2 sided trees
401 ;; it depends on which side is the actual element
402 ;; and which tree (left with offset 0 or right with offset > 0
403 ;; we are drawing
404 (visible #'(lambda (line) ()
405 (if (not ztree-node-side-fun) t
406 (let ((side
407 (gethash line ztree-line-tree-properties)))
408 (cond ((eq side 'left) (= start-offset 0))
409 ((eq side 'right) (> start-offset 0))
410 (t t)))))))
411 (when children
412 ;; draw the line to the last child
413 ;; since we push'd children to the list, it's the first visible line
414 ;; from the children list
415 (let ((last-child (ztree-find children
416 #'(lambda (x)
417 (funcall visible (ztree-car-atom x)))))
418 (x-offset (+ 2 offset)))
419 (when last-child
420 (ztree-draw-vertical-rounded-line (1+ root)
421 (ztree-car-atom last-child)
422 x-offset)))
423 ;; draw recursively
424 (dolist (child children)
425 (ztree-draw-tree child (1+ depth) start-offset)
426 (let ((end (if (listp child) line-end-node line-end-leaf)))
427 (when (funcall visible (ztree-car-atom child))
428 (ztree-draw-horizontal-line line-start
429 end
430 (ztree-car-atom child)))))))))
431
432 (defun ztree-fill-parent-array (tree)
433 "Set the root lines array.
434 Argument TREE nodes tree to create an array of lines from."
435 (let ((root (car tree))
436 (children (cdr tree)))
437 (dolist (child children)
438 (ztree-set-parent-for-line (ztree-car-atom child) root)
439 (when (listp child)
440 (ztree-fill-parent-array child)))))
441
442
443 (defun ztree-insert-node-contents (path)
444 "Insert node contents with initial depth 0.
445 `ztree-insert-node-contents-1' return the tree of line
446 numbers to determine who is parent line of the
447 particular line. This tree is used to draw the
448 graph.
449 Argument PATH start node."
450 (let ((tree (ztree-insert-node-contents-1 path 0))
451 ;; number of 'rows' in tree is last line minus start line
452 (num-of-items (- (line-number-at-pos (point)) ztree-start-line)))
453 ;; create a parents array to store parents of lines
454 ;; parents array used for navigation with the BS
455 (setq ztree-parent-lines-array (make-vector num-of-items 0))
456 ;; set the root node in lines parents array
457 (ztree-set-parent-for-line ztree-start-line ztree-start-line)
458 ;; fill the parent arrray from the tree
459 (ztree-fill-parent-array tree)
460 ;; draw the tree starting with depth 0 and offset 0
461 (ztree-draw-tree tree 0 0)
462 ;; for the 2-sided tree we need to draw the vertical line
463 ;; and an additional tree
464 (if ztree-node-side-fun ; 2-sided tree
465 (let ((width (window-width)))
466 ;; draw the vertical line in the middle of the window
467 (ztree-draw-vertical-line ztree-start-line
468 (1- (+ num-of-items ztree-start-line))
469 (/ width 2)
470 'vertical-border)
471 (ztree-draw-tree tree 0 (1+ (/ width 2)))))))
472
473
474 (defun ztree-insert-node-contents-1 (node depth)
475 "Recursively insert contents of the NODE with current DEPTH."
476 (let* ((expanded (ztree-is-expanded-node node))
477 ;; insert node entry with defined depth
478 (root-line (ztree-insert-entry node depth expanded))
479 ;; children list is the list of lines which are children
480 ;; of the root line
481 (children nil))
482 (when expanded ;; if expanded we need to add all subnodes
483 (let* ((contents (ztree-get-splitted-node-contens node))
484 ;; contents is the list of 2 elements:
485 (nodes (car contents)) ; expandable entries - nodes
486 (leafs (cdr contents))) ; leafs - which doesn't have subleafs
487 ;; iterate through all expandable entries to insert them first
488 (dolist (node nodes)
489 ;; if it is not in the filter list
490 (when (funcall ztree-node-showp-fun node)
491 ;; insert node on the next depth level
492 ;; and push the returning result (in form (root children))
493 ;; to the children list
494 (push (ztree-insert-node-contents-1 node (1+ depth))
495 children)))
496 ;; now iterate through all the leafs
497 (dolist (leaf leafs)
498 ;; if not in filter list
499 (when (funcall ztree-node-showp-fun leaf)
500 ;; insert the leaf and add it to children
501 (push (ztree-insert-entry leaf (1+ depth) nil)
502 children)))))
503 ;; result value is the list - head is the root line,
504 ;; rest are children
505 (cons root-line children)))
506
507 (defun ztree-insert-entry (node depth expanded)
508 "Inselt the NODE to the current line with specified DEPTH and EXPANDED state."
509 (let ((line (line-number-at-pos))
510 (expandable (funcall ztree-node-is-expandable-fun node))
511 (short-name (funcall ztree-node-short-name-fun node)))
512 (if ztree-node-side-fun ; 2-sided tree
513 (let ((right-short-name (funcall ztree-node-short-name-fun node t))
514 (side (funcall ztree-node-side-fun node))
515 (width (window-width)))
516 (when (eq side 'left) (setq right-short-name ""))
517 (when (eq side 'right) (setq short-name ""))
518 (ztree-insert-single-entry short-name depth
519 expandable expanded 0
520 (when ztree-node-face-fun
521 (funcall ztree-node-face-fun node)))
522 (ztree-insert-single-entry right-short-name depth
523 expandable expanded (1+ (/ width 2))
524 (when ztree-node-face-fun
525 (funcall ztree-node-face-fun node)))
526 (puthash line side ztree-line-tree-properties))
527 (ztree-insert-single-entry short-name depth expandable expanded 0))
528 (puthash line node ztree-line-to-node-table)
529 (insert "\n")
530 line))
531
532 (defun ztree-insert-single-entry (short-name depth
533 expandable expanded
534 offset
535 &optional face)
536 "Writes a SHORT-NAME in a proper position with the type given.
537 Writes a string with given DEPTH, prefixed with [ ] if EXPANDABLE
538 and [-] or [+] depending on if it is EXPANDED from the specified OFFSET.
539 Optional argument FACE face to write text with."
540 (let ((node-sign #'(lambda (exp)
541 (insert "[" (if exp "-" "+") "]")
542 (set-text-properties (- (point) 3)
543 (point)
544 '(face ztreep-expand-sign-face)))))
545 (move-to-column offset t)
546 (delete-region (point) (line-end-position))
547 (when (> depth 0)
548 (dotimes (_ depth)
549 (insert " ")
550 (insert-char ?\s 3))) ; insert 3 spaces
551 (when (> (length short-name) 0)
552 (if expandable
553 (progn
554 (funcall node-sign expanded) ; for expandable nodes insert "[+/-]"
555 (insert " ")
556 (put-text-property 0 (length short-name)
557 'face (if face face 'ztreep-node-face) short-name)
558 (insert short-name))
559 (progn
560 (insert " ")
561 (put-text-property 0 (length short-name)
562 'face (if face face 'ztreep-leaf-face) short-name)
563 (insert short-name))))))
564
565 (defun ztree-jump-side ()
566 "Jump to another side for 2-sided trees."
567 (interactive)
568 (when ztree-node-side-fun ; 2-sided tree
569 (let ((center (/ (window-width) 2)))
570 (cond ((< (current-column) center)
571 (move-to-column (1+ center)))
572 ((> (current-column) center)
573 (move-to-column 1))
574 (t nil)))))
575
576
577
578 (defun ztree-refresh-buffer (&optional line)
579 "Refresh the buffer.
580 Optional argument LINE scroll to the line given."
581 (interactive)
582 (when (and (equal major-mode 'ztree-mode)
583 (boundp 'ztree-start-node))
584 (setq ztree-line-to-node-table (make-hash-table))
585 ;; create a hash table of node properties for line
586 ;; used in 2-side tree mode
587 (when ztree-node-side-fun
588 (setq ztree-line-tree-properties (make-hash-table)))
589 (let ((inhibit-read-only t))
590 (erase-buffer)
591 (funcall ztree-tree-header-fun)
592 (setq ztree-start-line (line-number-at-pos (point)))
593 (ztree-insert-node-contents ztree-start-node))
594 (scroll-to-line (if line line ztree-start-line))))
595
596
597 (defun ztree-view (
598 buffer-name
599 start-node
600 filter-fun
601 header-fun
602 short-name-fun
603 expandable-p
604 equal-fun
605 children-fun
606 face-fun
607 action-fun
608 &optional node-side-fun
609 )
610 "Create a ztree view buffer configured with parameters given.
611 Argument BUFFER-NAME Name of the buffer created.
612 Argument START-NODE Starting node - the root of the tree.
613 Argument FILTER-FUN Function which will define if the node should not be
614 visible.
615 Argument HEADER-FUN Function which inserts the header into the buffer
616 before drawing the tree.
617 Argument SHORT-NAME-FUN Function which return the short name for a node given.
618 Argument EXPANDABLE-P Function to determine if the node is expandable.
619 Argument EQUAL-FUN An equality function for nodes.
620 Argument CHILDREN-FUN Function to get children from the node.
621 Argument FACE-FUN Function to determine face of the node.
622 Argument ACTION-FUN an action to perform when the Return is pressed.
623 Optional argument NODE-SIDE-FUN Determines the side of the node."
624 (let ((buf (get-buffer-create buffer-name)))
625 (switch-to-buffer buf)
626 (ztree-mode)
627 ;; configure ztree-view
628 (setq ztree-start-node start-node)
629 (setq ztree-expanded-nodes-list (list ztree-start-node))
630 (setq ztree-node-showp-fun filter-fun)
631 (setq ztree-tree-header-fun header-fun)
632 (setq ztree-node-short-name-fun short-name-fun)
633 (setq ztree-node-is-expandable-fun expandable-p)
634 (setq ztree-node-equal-fun equal-fun)
635 (setq ztree-node-contents-fun children-fun)
636 (setq ztree-node-face-fun face-fun)
637 (setq ztree-node-action-fun action-fun)
638 (setq ztree-node-side-fun node-side-fun)
639 (ztree-refresh-buffer)))
640
641
642 (provide 'ztree-view)
643 ;;; ztree-view.el ends here