branch: master commit 3867ed3b1cfd55cc5ae337d97b3c6c9eef892be2 Author: Alexey Veretennikov <alexey.veretenni...@gmail.com> Commit: Alexey Veretennikov <alexey.veretenni...@gmail.com>
Implemented support for hiding matched(equal) files --- ztree-diff.el | 42 +++++++++++++++++++++++++++++++++++------- ztree-view.el | 43 ++++++++++++++++++------------------------- ztree.el | 6 +++++- 3 files changed, 58 insertions(+), 33 deletions(-) diff --git a/ztree-diff.el b/ztree-diff.el index ebc93d4..5b3f957 100644 --- a/ztree-diff.el +++ b/ztree-diff.el @@ -68,10 +68,17 @@ including . and ..") (defvar ztreep-diff-model-normal-face 'ztreep-diff-model-normal-face) -(defvar ztreediff-dirs-pair nil +(defvar ztree-diff-filter-list nil + "List of regexp file names to filter out") +(make-variable-buffer-local 'ztree-diff-filter-list) + +(defvar ztree-diff-dirs-pair nil "Pair of the directories stored. Used to perform the full rescan") -(make-variable-buffer-local 'ztrediff-dirs-par) +(make-variable-buffer-local 'ztree-diff-dirs-pair) +(defvar ztree-diff-show-equal-files t + "Show or not equal files/directories on both sides") +(make-variable-buffer-local 'ztree-diff-show-equal-files) ;;;###autoload (define-minor-mode ztreediff-mode @@ -83,6 +90,7 @@ including . and ..") ;; The minor mode keymap `( (,(kbd "C") . ztree-diff-copy) + (,(kbd "h") . ztree-diff-toggle-show-equal-files) ([f5] . ztree-diff-full-rescan))) @@ -111,9 +119,9 @@ including . and ..") (defun ztree-diff-full-rescan () (interactive) - (when (and ztreediff-dirs-pair + (when (and ztree-diff-dirs-pair (yes-or-no-p (format "Force full rescan?"))) - (ztree-diff (car ztreediff-dirs-pair) (cdr ztreediff-dirs-pair)))) + (ztree-diff (car ztree-diff-dirs-pair) (cdr ztree-diff-dirs-pair)))) (defun ztree-diff-node-action (node) @@ -122,7 +130,8 @@ including . and ..") (when (and left right) (if (not (ztree-diff-node-different node)) (message (concat "Files " - (ztree-diff-node-short-name node) + (substring-no-properties + (ztree-diff-node-short-name node)) " on left and right side are identical")) (ediff left right))))) @@ -225,16 +234,35 @@ including . and ..") source-path destination-path copy-to-right)))))))) + + +(defun ztree-node-is-in-filter-list (node) + "Determine if the node is in filter list (and therefore +apparently shall not be visible" + (ztree-find ztree-diff-filter-list #'(lambda (rx) (string-match rx node)))) + + +(defun ztree-node-is-visible (node) + (and (not (ztree-node-is-in-filter-list (ztree-diff-node-short-name node))) + (or ztree-diff-show-equal-files + (ztree-diff-node-different node)))) + +(defun ztree-diff-toggle-show-equal-files () + (interactive) + (setq ztree-diff-show-equal-files (not ztree-diff-show-equal-files)) + (ztree-refresh-buffer)) + (defun ztree-diff (dir1 dir2) "Creates an interactive buffer with the directory tree of the path given" (interactive "DLeft directory \nDRight directory ") (let* ((difference (ztree-diff-model-create dir1 dir2)) (buf-name (concat "*" (ztree-diff-node-short-name difference) "*"))) - (setq ztreediff-dirs-pair (cons dir1 dir2)) + (setq ztree-diff-dirs-pair (cons dir1 dir2)) + (setq ztree-diff-filter-list (list ztree-diff-hidden-files-regexp)) (ztree-view buf-name difference - (list ztree-diff-hidden-files-regexp) + 'ztree-node-is-visible 'ztree-diff-insert-buffer-header 'ztree-diff-node-short-name 'ztree-diff-node-is-directory diff --git a/ztree-view.el b/ztree-view.el index 6e6cfce..e7fdadd 100644 --- a/ztree-view.el +++ b/ztree-view.el @@ -65,10 +65,6 @@ and the line.") (make-variable-buffer-local 'ztree-line-to-node-table) -(defvar ztree-filter-list nil - "List of regexp for node names to filter out") -(make-variable-buffer-local 'ztree-filter-list) - (defvar ztree-start-line nil "Index of the start line - the root") (make-variable-buffer-local 'ztree-start-line) @@ -127,6 +123,10 @@ the buffer is split to 2 trees") "Function called when Enter/Space pressed on the node") (make-variable-buffer-local 'ztree-node-action-fun) +(defvar ztree-node-showp-fun nil + "Function called to decide if the node should be visible") +(make-variable-buffer-local 'ztree-node-showp-fun) + ;; ;; Major mode definitions @@ -282,11 +282,6 @@ list of leafs" nodes) comp)))) -(defun ztree-node-is-in-filter-list (node) - "Determine if the node is in filter list (and therefore -apparently shall not be visible" - (ztree-find ztree-filter-list #'(lambda (rx) (string-match rx node)))) - (defun ztree-draw-char (c x y &optional face) "Draw char c at the position (1-based) (x y)" (save-excursion @@ -409,22 +404,20 @@ apparently shall not be visible" (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)))) + ;; if it is not in the filter list + (when (funcall ztree-node-showp-fun node) + ;; 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)))))) + ;; if not in filter list + (when (funcall ztree-node-showp-fun leaf) + ;; 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))) @@ -515,7 +508,7 @@ apparently shall not be visible" (defun ztree-view ( buffer-name start-node - filter-list + filter-fun header-fun short-name-fun expandable-p @@ -531,7 +524,7 @@ apparently shall not be visible" ;; configure ztree-view (setq ztree-start-node start-node) (setq ztree-expanded-nodes-list (list ztree-start-node)) - (setq ztree-filter-list filter-list) + (setq ztree-node-showp-fun filter-fun) (setq ztree-tree-header-fun header-fun) (setq ztree-node-short-name-fun short-name-fun) (setq ztree-node-is-expandable-fun expandable-p) diff --git a/ztree.el b/ztree.el index 26f2ab2..8d0a1df 100644 --- a/ztree.el +++ b/ztree.el @@ -86,6 +86,10 @@ including . and ..") (set-text-properties start (point) '(face ztreep-header-face))) (newline)) +(defun ztree-file-not-hidden (filename) + (not (string-match ztree-hidden-files-regexp + (file-short-name filename)))) + (defun ztree (path) "Creates an interactive buffer with the directory tree of the path given" (interactive "DDirectory: ") @@ -93,7 +97,7 @@ including . and ..") (let ((buf-name (concat "*Directory " path " tree*"))) (ztree-view buf-name (expand-file-name (substitute-in-file-name path)) - (list ztree-hidden-files-regexp) + 'ztree-file-not-hidden 'ztree-insert-buffer-header 'file-short-name 'file-directory-p