[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3260487 25/92: Preparing for the double tree drawing
From: |
Alexey Veretennikov |
Subject: |
[elpa] master 3260487 25/92: Preparing for the double tree drawing |
Date: |
Thu, 11 Jun 2015 19:47:57 +0000 |
branch: master
commit 32604875c91adeeda1859eefcc35e261746b01e3
Author: Alexey Veretennikov <address@hidden>
Commit: Alexey Veretennikov <address@hidden>
Preparing for the double tree drawing
---
ztree-diff-model.el | 6 ++-
ztree-view.el | 102 +++++++++++++++++++++++++++++---------------------
ztree.el | 11 +-----
3 files changed, 64 insertions(+), 55 deletions(-)
diff --git a/ztree-diff-model.el b/ztree-diff-model.el
index 0a1bbb4..f7b1114 100644
--- a/ztree-diff-model.el
+++ b/ztree-diff-model.el
@@ -1,5 +1,7 @@
;; Diff model
+(require 'ztree-util)
+
;; different = {nil, 'new, 'diff}
(defun ztree-diff-model-create-node (left-full-path right-full-path short-name
children different)
(let (node)
@@ -25,7 +27,7 @@
(plist-get node 'different))
(defun ztree-diff-model-is-directory (node)
- (let ((left (plist-get node 'left))
+ (let ((left (plist-get node 'left))
(right (plist-get node 'right)))
(if left
(file-directory-p left)
@@ -33,7 +35,7 @@
(defun ztree-diff-model-side (node)
(let ((left (plist-get node 'left))
- (rigth (plist-get node 'right)))
+ (right (plist-get node 'right)))
(if (and left right) 'both
(if left 'left 'right))))
diff --git a/ztree-view.el b/ztree-view.el
index 07a5312..629ead6 100644
--- a/ztree-view.el
+++ b/ztree-view.el
@@ -46,6 +46,8 @@
;;
;;; Code:
+(require 'ztree-util)
+
;;
;; Globals
;;
@@ -110,7 +112,7 @@ for example if the node is a directory")
If not defined(by default) - using single screen tree, otherwise
the buffer is split to 2 trees")
(make-variable-buffer-local 'ztree-node-side-fun)
-
+
;;
;; Major mode definitions
@@ -172,19 +174,6 @@ the buffer is split to 2 trees")
(define-derived-mode ztree-mode special-mode "Ztree"
"A major mode for displaying the directory tree in text mode.")
-(defun ztree-find (where which)
- "find element of the list `where` matching predicate `which`"
- (catch 'found
- (dolist (elt where)
- (when (funcall which elt)
- (throw 'found elt)))
- nil))
-
-(defun ztree-filter (condp lst)
- "Filter out elements of the list `lst` not satisfying predicate `condp`.
-Taken from http://www.emacswiki.org/emacs/ElispCookbook#toc39"
- (delq nil
- (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
(defun ztree-find-node-in-line (line)
"Search through the array of node-line pairs and return the
@@ -343,55 +332,82 @@ apparently shall not be visible"
(defun ztree-insert-node-contents (path)
;; insert node contents with initial depth 0
+ ;; ztree-insert-node-contents-1 return the tree of line
+ ;; numbers to determine who is parent line of the
+ ;; particular line. This tree is used to draw the
+ ;; graph
(let ((tree (ztree-insert-node-contents-1 path 0))
+ ;; number of 'rows' in tree is last line minus start line
(num-of-items (- (line-number-at-pos (point)) ztree-start-line)))
+ ;; create a parents array to store parents of lines
(setq ztree-parent-lines-array (make-vector num-of-items 0))
+ ;; set the root node in lines array
(ztree-set-parent-for-line ztree-start-line ztree-start-line)
+ ;; fill the parent arrray
(ztree-fill-parent-array tree)
+ ;; and draw the tree, having the parent array in place
(ztree-draw-tree tree 0)))
(defun ztree-insert-node-contents-1 (node depth)
(let* ((expanded (ztree-is-expanded-node node))
+ ;; insert node entry with defined depth
(root-line (ztree-insert-entry node depth expanded))
+ ;; children list is the list of lines which are children
+ ;; of the root line
(children nil))
- (when expanded
+ (when expanded ;; if expanded we need to add all subnodes
(let* ((contents (ztree-get-splitted-node-contens node))
- (nodes (car contents))
- (leafs (cdr contents)))
- (dolist (node nodes)
+ ;; contents is the list of 2 elements:
+ (nodes (car contents)) ; expandable entries - nodes
+ (leafs (cdr contents))) ; leafs - which doesn't have subleafs
+ ;; iterate through all expandable entries to insert them first
+ (dolist (node nodes)
(let ((short-node-name (funcall ztree-node-short-name-fun node)))
+ ;; if it is not in the filter list
(unless (ztree-node-is-in-filter-list short-node-name)
+ ;; insert node on the next depth level
+ ;; and push the returning result (in form (root children))
+ ;; to the children list
(push (ztree-insert-node-contents-1 node (1+ depth))
children))))
+ ;; now iterate through all the leafs
(dolist (leaf leafs)
(let ((short-leaf-name (funcall ztree-node-short-name-fun leaf)))
+ ;; if not in filter list
(when (not (ztree-node-is-in-filter-list short-leaf-name))
+ ;; insert the leaf and add it to children
(push (ztree-insert-entry leaf (1+ depth) nil)
children))))))
+ ;; result value is the list - head is the root line,
+ ;; rest are children
(cons root-line children)))
(defun ztree-insert-entry (node depth expanded)
(let ((line (line-number-at-pos))
- (expandable (funcall ztree-node-is-expandable-fun node)))
- (ztree-insert-single-entry node depth expandable expanded 0)
- ;; (ztree-insert-single-entry node depth expandable expanded 40)
+ (expandable (funcall ztree-node-is-expandable-fun node))
+ (short-name (funcall ztree-node-short-name-fun node)))
+ (if ztree-node-side-fun ; 2-sided tree
+ (let ((right-short-name short-name)
+ (side (funcall ztree-node-side-fun node)))
+ (when (eq side 'left) (setq right-short-name ""))
+ (when (eq side 'right) (setq short-name ""))
+ (ztree-insert-single-entry short-name depth expandable expanded 0)
+ (ztree-insert-single-entry right-short-name depth expandable
expanded 40))
+ (ztree-insert-single-entry short-name depth expandable expanded 0))
(push (cons node line) ztree-node-to-line-list)
(newline)
line))
- ;; (if (not ztree-node-side-fun)
- ;; ztree-insert-single-entry (node depth expanded 0))
-(defun ztree-insert-single-entry (node depth expandable expanded offset)
- (let ((short-name (funcall ztree-node-short-name-fun node))
- (node-sign #'(lambda (exp)
+(defun ztree-insert-single-entry (short-name depth expandable expanded offset)
+ (let ((node-sign #'(lambda (exp)
(insert "[" (if exp "-" "+") "]")
(set-text-properties (- (point) 3)
(point)
'(face ztreep-expand-sign-face)))))
(move-to-column offset t)
- ;;(kill-line)
+ (delete-region (point) (line-end-position))
(when (> depth 0)
(dotimes (i depth)
(insert " ")
@@ -417,9 +433,9 @@ apparently shall not be visible"
(setq ztree-node-to-line-list nil)
(toggle-read-only)
(erase-buffer)
- (let ((start (point)))
- (funcall ztree-tree-header-fun)
- (set-text-properties start (point) '(face ztreep-header-face)))
+ (let ((start (point)))
+ (funcall ztree-tree-header-fun)
+ (set-text-properties start (point) '(face ztreep-header-face)))
(setq ztree-start-line (line-number-at-pos (point)))
(ztree-insert-node-contents ztree-start-node)
(scroll-to-line (if line line ztree-start-line))
@@ -438,19 +454,19 @@ apparently shall not be visible"
&optional node-side-fun
)
(let ((buf (get-buffer-create buffer-name)))
- (switch-to-buffer buf)
- (ztree-mode)
- ;; configure ztree to work with directories
- (setq ztree-start-node start-node)
- (setq ztree-expanded-nodes-list (list ztree-start-node))
- (setq ztree-filter-list filter-list)
- (setq ztree-tree-header-fun header-fun)
- (setq ztree-node-short-name-fun short-name-fun)
- (setq ztree-node-is-expandable-fun expandable-p)
- (setq ztree-node-equal-fun equal-fun)
- (setq ztree-node-contents-fun children-fun)
- (setq ztree-node-side-fun node-side-fun)
- (ztree-refresh-buffer)))
+ (switch-to-buffer buf)
+ (ztree-mode)
+ ;; configure ztree to work with directories
+ (setq ztree-start-node start-node)
+ (setq ztree-expanded-nodes-list (list ztree-start-node))
+ (setq ztree-filter-list filter-list)
+ (setq ztree-tree-header-fun header-fun)
+ (setq ztree-node-short-name-fun short-name-fun)
+ (setq ztree-node-is-expandable-fun expandable-p)
+ (setq ztree-node-equal-fun equal-fun)
+ (setq ztree-node-contents-fun children-fun)
+ (setq ztree-node-side-fun node-side-fun)
+ (ztree-refresh-buffer)))
(provide 'ztree-view)
diff --git a/ztree.el b/ztree.el
index 2973ba6..b1ae489 100644
--- a/ztree.el
+++ b/ztree.el
@@ -49,6 +49,7 @@
;;
;;; Code:
+(require 'ztree-util)
(require 'ztree-view)
;;
@@ -70,16 +71,6 @@ including . and ..")
(insert "==============")
(newline))
-(defun printable-string (string)
- "Strip newline character from file names, like 'Icon\n'"
- (replace-regexp-in-string "\n" "" string))
-
-(defun file-short-name (file)
- "Base file/directory name. Taken from
- http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
- (printable-string (file-name-nondirectory (directory-file-name file))))
-
-
(defun ztree (path)
"Creates an interactive buffer with the directory tree of the path given"
(interactive "DDirectory: ")
- [elpa] master 5bbcfcf 18/92: Started diff model, (continued)
- [elpa] master 5bbcfcf 18/92: Started diff model, Alexey Veretennikov, 2015/06/11
- [elpa] master b1de530 16/92: Isolated tree 'control' from the directory model, Alexey Veretennikov, 2015/06/11
- [elpa] master 7eb950e 22/92: Updated readme, Alexey Veretennikov, 2015/06/11
- [elpa] master 1279a61 28/92: Added face argument for ztree-draw-char and set face for vertical line in 2 trees mode, Alexey Veretennikov, 2015/06/11
- [elpa] master 120ffcb 15/92: Preparing to isolate ztree from directories api, Alexey Veretennikov, 2015/06/11
- [elpa] master 41d4c09 23/92: Fixed model issue when all files in added subtree looks like directories, Alexey Veretennikov, 2015/06/11
- [elpa] master 2f888c5 26/92: Added util file, Alexey Veretennikov, 2015/06/11
- [elpa] master 41ab149 29/92: Added sorting to the tree, Alexey Veretennikov, 2015/06/11
- [elpa] master d0e255e 20/92: Implemented difftree model, Alexey Veretennikov, 2015/06/11
- [elpa] master a39e8c6 24/92: Started preparation for 2 column tree, Alexey Veretennikov, 2015/06/11
- [elpa] master 3260487 25/92: Preparing for the double tree drawing,
Alexey Veretennikov <=
- [elpa] master 8685235 27/92: Added support for 2 trees, Alexey Veretennikov, 2015/06/11
- [elpa] master 28fa370 33/92: Reimplemented search for node by line using hash table, Alexey Veretennikov, 2015/06/11
- [elpa] master 413cff4 30/92: Drawing trees only to visible items, Alexey Veretennikov, 2015/06/11
- [elpa] master 161b1b3 35/92: Added messages, Alexey Veretennikov, 2015/06/11
- [elpa] master 9b91d44 31/92: Implemented colors support for different files, Alexey Veretennikov, 2015/06/11
- [elpa] master 44743c1 37/92: Added progress indication to the diff model, Alexey Veretennikov, 2015/06/11
- [elpa] master 99a0cf7 36/92: Started work for identifying parents in nodes, Alexey Veretennikov, 2015/06/11
- [elpa] master 291a115 32/92: Header is now customizable, Alexey Veretennikov, 2015/06/11
- [elpa] master f9620df 34/92: Added action on modified files, Alexey Veretennikov, 2015/06/11
- [elpa] master 900c8fa 38/92: Refactored using defrecord macro, Alexey Veretennikov, 2015/06/11