[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treeview f0c0711070 04/25: Insering/removing nodes; treevi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treeview f0c0711070 04/25: Insering/removing nodes; treeview-after-node-expanded-function and treeview-after-node-folded-function |
Date: |
Sat, 10 Sep 2022 17:59:37 -0400 (EDT) |
branch: elpa/treeview
commit f0c0711070284f38f9008912feb4f3d3bbdc0a3c
Author: Tilman Rassy <tilman.rassy@googlemail.com>
Commit: Tilman Rassy <tilman.rassy@googlemail.com>
Insering/removing nodes; treeview-after-node-expanded-function and
treeview-after-node-folded-function
---
treeview.el | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 88 insertions(+), 10 deletions(-)
diff --git a/treeview.el b/treeview.el
index d41aeab7f3..d3010b0613 100644
--- a/treeview.el
+++ b/treeview.el
@@ -202,7 +202,7 @@ This is the case if, and only if, NODE's state is
`folded-unread'."
(defun treeview-node-folded-p (node)
"Return non-nil if NODE is folded.
-This is the case is and only if NODES's state is `folded-unred' or
`folded-read'."
+This is the case if and only if NODES's state is `folded-unread' or
`folded-read'."
(memq (treeview-get-node-state node) '(folded-unread folded-read)))
(defun treeview-node-expanded-p (node)
@@ -273,6 +273,13 @@ Default implementation of functions that provide optional
data, e.g.,
`treeview-get-control-face-function'. The argument _NODE is ignored."
nil)
+(defun treeview-do-nothing (_node)
+ "Do nothing.
+Default implementation of functions that may be used to perform additional
+actions on certain occasions, e.g., `treeview-after-node-expanded-function'.
+Always returns t."
+ t)
+
(defun treeview--not-nil-or-empty-string-p (str)
"Return non-nil if STR is neither nil nor the empty string."
(and str (not (string-equal str ""))))
@@ -283,6 +290,14 @@ Called with one argument, the node. For example, if the
nodes represent
directories, this function could re-read the directory to update the children.
The function should not redisplay the node, this is done automatically.")
+(defvar treeview-after-node-expanded-function 'treeview-do-nothing
+ "Function to perform additional actions after a node has been expanded.
+Called with one argument, the node.")
+
+(defvar treeview-after-node-folded-function 'treeview-do-nothing
+ "Function to perform additional actions after a node has been expanded.
+Called with one argument, the node.")
+
(make-variable-buffer-local 'treeview-update-node-children-function)
(defvar treeview-get-indent-function nil
@@ -705,6 +720,51 @@ The first one does the rendering, the latter one fixes the
(treeview-set-node-end-after-display node)
(setq buffer-read-only read-only-p) ))
+(defun treeview-insert-node-after (node anchor)
+ "Insert NODE after ANCHOR.
+ANCHOR must be a cons cell of the list of children of a node. NODE is inserted
+after this cons cell. NODE is also displayed if the parent is expanded."
+ (let* ( (read-only-p buffer-read-only)
+ (anchor-node (car anchor))
+ (parent (treeview-get-node-parent anchor-node))
+ (new-cons (cons node nil)) )
+ (setcdr new-cons (cdr anchor))
+ (setcdr anchor new-cons)
+ (treeview-set-node-parent node parent)
+ (when (treeview-node-expanded-p parent)
+ (setq buffer-read-only nil)
+ (goto-char (treeview-get-node-prop anchor-node 'end))
+ (end-of-line)
+ (newline)
+ (treeview-display-node-internal node nil)
+ (treeview-set-node-end-after-display node)
+ (setq buffer-read-only read-only-p))))
+
+(defun treeview-add-child-at-front (parent node)
+ "Insert NODE at the beginning of the children of PARENT.
+Thus, NODE becomes the new first child of PARENT. NODE is also displayed if
+PARENT is expanded.."
+ (let ( (read-only-p buffer-read-only)
+ (children (treeview-get-node-children parent)) )
+ (setq children (cons node children))
+ (treeview-set-node-parent node parent)
+ (treeview-set-node-children parent children)
+ (when (treeview-node-expanded-p parent)
+ (setq buffer-read-only nil)
+ (goto-char (treeview-get-node-prop parent 'start))
+ (end-of-line)
+ (newline)
+ (treeview-display-node-internal node nil)
+ (treeview-set-node-end-after-display node)
+ (setq buffer-read-only read-only-p))))
+
+(defun treeview-add-child (parent node compare-function)
+ (let ( (cursor (treeview-get-node-children parent)) anchor )
+ (while (and cursor (funcall compare-function node (car cursor)))
+ (setq anchor cursor
+ cursor (cdr cursor)))
+ (if anchor (treeview-insert-node-after node anchor)
(treeview-add-child-at-front parent node))))
+
(defun treeview--recursivlely-remove-overlays (node)
"Remove all overlays of NODE and its descendents."
(let ( (overlay-prop-keys '(indent-overlay control-overlay icon-overlay
label-overlay node-line-overlay)) )
@@ -720,45 +780,63 @@ The first one does the rendering, the latter one fixes the
(treeview--recursivlely-remove-overlays (car children))
(setq children (cdr children)) ))) )
-(defun treeview-erase-node (node)
- "Remove NODE and all its descendents from the display in the buffer.
+(defun treeview-undisplay-node (node &optional leave-no-gap)
+ "Remove NODE and all its descendents from the display in the buffer. If
+LEAVE-NO-GAP is non-nil, the node is removed without leaving a gap between the
+previuos and following nodes. Otherwise, an empty line remains.
The 'start' and 'end' properties of NODE are set to nil. Except this, the
internal representation of the tree is not altered. Neither NODE or its
descendents are removed from the children of their respective parents.
-The main purpose of this function is to implement the
-`treeview-redisplay-node' function."
+The main purpose of this function is to implement the functions
+`treeview-redisplay-node' and `treeview-remove-node'."
(let* ( (read-only-p buffer-read-only)
(start (treeview-get-node-prop node 'start))
(end (treeview-get-node-prop node 'end)) )
(treeview--recursivlely-remove-overlays node)
(setq buffer-read-only nil)
+ (when leave-no-gap
+ ;; Move end position to end of previous line (if any) to remove node
completely
+ (save-excursion
+ (goto-char start)
+ (when (equal (forward-line -1) 0)
+ (end-of-line)
+ (setq start (point)))))
(delete-region start end)
(treeview-set-node-prop node 'start nil)
(treeview-set-node-prop node 'end nil)
(setq buffer-read-only read-only-p)))
+(defun treeview-remove-node (node)
+ "Remove NODE from the tree.
+NODE is also erased from the display."
+ (let ( (parent (treeview-get-node-parent node) ) )
+ (if parent (delq node (treeview-get-node-children parent)))
+ (treeview-undisplay-node node t)))
+
(defun treeview-redisplay-node (node)
"Redisplay NODE.
-NODE is erased by `treeview-erase-node' and displayed again by
+NODE is erased by `treeview-undisplay-node' and displayed again by
`treeview-display-node'. This function can be used to update the display of a
node after it has changed."
(let ( (start-marker (treeview-get-node-prop node 'start)) )
- (treeview-erase-node node)
+ (treeview-undisplay-node node)
(goto-char start-marker)
(treeview-display-node node)))
(defun treeview-expand-node (node)
"Expands NODE."
(treeview-set-node-state node 'expanded)
- (funcall treeview-update-node-children-function node))
+ (funcall treeview-update-node-children-function node)
+ (funcall treeview-after-node-expanded-function node))
(defun treeview-fold-node (node)
"Folds NODE."
(treeview-set-node-state node 'folded-read)
- (funcall treeview-update-node-children-function node))
+ (funcall treeview-update-node-children-function node)
+ (funcall treeview-after-node-folded-function node))
(defun treeview-update-node (node)
"Update NODE.
@@ -767,7 +845,7 @@ If NODE is not folded, the following is done: First, the
function calls
`treeview-update-node-children-function' for NODE. Then, the function
calls itself for all children of NODE.
-If NODE is not folded, does nothing."
+If NODE is folded, does nothing."
(unless (treeview-node-folded-p node)
(funcall treeview-update-node-children-function node)
(let ( (children (treeview-get-node-children node)) )
- [nongnu] elpa/treeview 3130757444 05/25: Added new function treeview-call-for-node-at-point, (continued)
- [nongnu] elpa/treeview 3130757444 05/25: Added new function treeview-call-for-node-at-point, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 0044b119e7 11/25: Updated documentation, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 86d6734aef 15/25: Renamed function treeview-display-node-internal to treeview-render-node, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview ad9c094d89 23/25: Implemented selection of files and highlighting of nodes, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 0681739fdd 01/25: Initial commit, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 0d66ef2322 22/25: Made treeview-after-node-expanded-function and treeview-after-node-folded-function buffer-local, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 00a4ab92bd 19/25: Changed http to https in link to GNU licenses, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview e601230367 20/25: Removed needless intern statements, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 07ea52cd7f 16/25: Added package dependency on emacs 24.4, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 8382de4bdd 18/25: Sharp-quoted function name, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview f0c0711070 04/25: Insering/removing nodes; treeview-after-node-expanded-function and treeview-after-node-folded-function,
ELPA Syncer <=
- [nongnu] elpa/treeview 5dff23aac0 09/25: New functions for navigation; misc. improvements, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 3038ebf96e 08/25: Fixed bug when removing first child, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 34ecd7a320 24/25: Fixed issues detected by flycheck; updated documentation, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview a82bc8c5d1 17/25: Removed needless progn around body of while, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 4a341b05bc 14/25: Bugfix for updating hidden nodes, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 7fc5f30552 03/25: Initial commit of treeview.el, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 270cfbd5bd 06/25: Using 'let' to set buffer-read-only temporarily to t, ELPA Syncer, 2022/09/10
- [nongnu] elpa/treeview 0bdd3187c7 07/25: Reworked treeview-put so it can insert images, ELPA Syncer, 2022/09/10