[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ztree d078daf 08/23: Issue #54: Added (optional) number
From: |
Stefan Monnier |
Subject: |
[elpa] externals/ztree d078daf 08/23: Issue #54: Added (optional) number of directory entries |
Date: |
Thu, 17 Dec 2020 23:17:03 -0500 (EST) |
branch: externals/ztree
commit d078dafa74f4e2a001f1aeecf718c0716779d77e
Author: Alexey Veretennikov <txm.fourier@gmail.com>
Commit: Alexey Veretennikov <txm.fourier@gmail.com>
Issue #54: Added (optional) number of directory entries
If the variable ztree-show-number-of-children is set to t,
write number of directory entries to the right of the
directory name. Turned off by default.
---
ztree-dir.el | 2 +-
ztree-view.el | 44 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/ztree-dir.el b/ztree-dir.el
index 20795d7..5421ef0 100644
--- a/ztree-dir.el
+++ b/ztree-dir.el
@@ -45,7 +45,7 @@
(require 'ztree-util)
(require 'ztree-view)
-(require 'cl-lib)
+(eval-when-compile (require 'cl-lib))
;;
;; Constants
diff --git a/ztree-view.el b/ztree-view.el
index 8cf0ced..2b0dc4d 100644
--- a/ztree-view.el
+++ b/ztree-view.el
@@ -51,6 +51,9 @@
(defvar ztree-draw-unicode-lines nil
"If set forces ztree to draw lines with unicode characters.")
+(defvar ztree-show-number-of-children nil
+ "If set forces ztree show number of child entries in the braces.")
+
(defvar-local ztree-expanded-nodes-list nil
"A list of Expanded nodes (i.e. directories) entries.")
@@ -158,6 +161,13 @@ the buffer is split to 2 trees")
:group 'Ztree :group 'font-lock-highlighting-faces)
(defvar ztreep-expand-sign-face 'ztreep-expand-sign-face)
+(defface ztreep-node-count-children-face
+ '((t (:inherit 'font-lock-comment-face :slant italic)))
+ "*Face used for count of number of child entries in Ztree buffer."
+ :group 'Ztree :group 'font-lock-highlighting-faces)
+(defvar ztreep-node-count-children-face 'ztreep-node-count-children-face)
+
+
;;;###autoload
(define-derived-mode ztree-mode special-mode "Ztree"
@@ -527,19 +537,39 @@ Argument PATH start node."
(if ztree-node-side-fun ; 2-sided tree
(let ((right-short-name (funcall ztree-node-short-name-fun node t))
(side (funcall ztree-node-side-fun node))
- (width (window-width)))
+ (width (window-width))
+ (count-children-left
+ (when ztree-show-number-of-children
+ (length (cl-remove-if (lambda (n)
+ (eql
+ (funcall ztree-node-side-fun n)
+ 'right))
+ (funcall ztree-node-contents-fun
node)))))
+ (count-children-right
+ (when ztree-show-number-of-children
+ (length (cl-remove-if (lambda (n)
+ (eql
+ (funcall ztree-node-side-fun n)
+ 'left))
+ (funcall ztree-node-contents-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
+ count-children-left
(when ztree-node-face-fun
(funcall ztree-node-face-fun node)))
(ztree-insert-single-entry right-short-name depth
expandable expanded (1+ (/ width 2))
+ count-children-right
(when ztree-node-face-fun
(funcall ztree-node-face-fun node)))
(puthash line side ztree-line-tree-properties))
- (ztree-insert-single-entry short-name depth expandable expanded 0))
+ (ztree-insert-single-entry short-name depth
+ expandable expanded
+ 0 (when expandable
+ (length
+ (funcall ztree-node-contents-fun
node)))))
(puthash line node ztree-line-to-node-table)
(insert "\n")
line))
@@ -547,10 +577,13 @@ Argument PATH start node."
(defun ztree-insert-single-entry (short-name depth
expandable expanded
offset
+ count-children
&optional face)
"Writes a SHORT-NAME in a proper position with the type given.
Writes a string with given DEPTH, prefixed with [ ] if EXPANDABLE
and [-] or [+] depending on if it is EXPANDED from the specified OFFSET.
+If `ztree-show-number-of-children' is set to t the COUNT-CHILDREN
+argument is used to present number of entries in the expandable item.
Optional argument FACE face to write text with."
(let ((node-sign #'(lambda (exp)
(let ((sign (concat "[" (if exp "-" "+") "]")))
@@ -577,7 +610,12 @@ Optional argument FACE face to write text with."
(funcall node-sign expanded)) ; for expandable nodes insert
"[+/-]"
;; indentation for leafs 4 spaces from the node name
(insert-char ?\s (- 4 (- (point) start-pos))))
- (insert (propertize short-name 'font-lock-face entry-face)))))
+ (insert (propertize short-name 'font-lock-face entry-face))
+ ;; optionally add number of children in braces
+ (when (and ztree-show-number-of-children expandable)
+ (let ((count-str (format " [%d]" count-children)))
+ (insert (propertize count-str 'font-lock-face
ztreep-node-count-children-face)))))))
+
- [elpa] externals/ztree febc2d0 06/23: Merge pull request #46 from Iurie/master, (continued)
- [elpa] externals/ztree febc2d0 06/23: Merge pull request #46 from Iurie/master, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 0e0a39d 09/23: Issue #56: Preserve line/column position on refresh, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 67a1d90 11/23: Issue #56: Dont preserve a cursor position on widen/narrow operations, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 369fd05 10/23: Issue #50: Show file permission differences, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 00d3318 12/23: Issue #59: Position curson on the beginning of the text, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 3273e1f 13/23: Issue #60: ztree-dir change Emacs default directory, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree a3e0442 14/23: Issue #59: Place cursor at the beginning of the text, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 2f62ba7 18/23: Issue #62: Cleared warnings, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 4879576 19/23: Issue #39: restore cursor position and window configuration, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree c54425a 21/23: Updated README for issue #65., Stefan Monnier, 2020/12/17
- [elpa] externals/ztree d078daf 08/23: Issue #54: Added (optional) number of directory entries,
Stefan Monnier <=
- [elpa] externals/ztree c5a1190 15/23: Issue #61: Error on unaccessible directory contents, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 0a5b25f 23/23: Merge pull request #68 from webzak/fix_ws_ignore, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 1ebb00c 07/23: Issue #52: Added 'd' hotkey for the ztree-dir to open dired., Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 30dbda7 16/23: Issue #62, #63, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 50412fa 20/23: Issue #65: added ztree-diff-additional-options variable, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 901c3e3 22/23: support -w for different file size, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 17f8f32 17/23: Update to issue #62, Stefan Monnier, 2020/12/17