This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ztree-protocol.el
99 lines (75 loc) · 2.83 KB
/
ztree-protocol.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;; ztree-protocol.el --- generic protocol for ztree-view -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Free Software Foundation, Inc.
;;
;; Author: Alexey Veretennikov <[email protected]>
;;
;; Created: 2021-02-12
;;
;; Keywords: files tools
;; URL: https://github.com/fourier/ztree
;; Compatibility: GNU Emacs 24.x
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;; Generic protocol for ztree-view
;;; Code:
(eval-when-compile (require 'cl-lib))
;;; Node protocol
;;; Obligatory to implement
(cl-defgeneric ztree-node-visible-p (node)
"Return T if the NODE shall be visible.")
(cl-defgeneric ztree-node-short-name (node)
"Return the short name for a node.")
(cl-defgeneric ztree-node-expandable-p (node)
"Return T if the node is expandable.")
(cl-defgeneric ztree-node-equal (node1 node2)
"Equality function for NODE1 and NODE2.
Return T if nodes are equal")
(cl-defgeneric ztree-node-children (node)
"Return a list of NODE children")
;;; Optional to implement
(cl-defgeneric ztree-node-side (node)
"Determine the side of the NODE.")
(cl-defgeneric ztree-node-face (node)
"Return a face to write a NODE in")
(cl-defgeneric ztree-node-action (node)
"Perform an action when the Return is pressed on a NODE.")
(cl-defgeneric ztree-node-left-short-name (node)
"Return the left short name for a node in 2-sided tree.")
(cl-defgeneric ztree-node-right-short-name (node)
"Return the right short name for a node in 2-sided tree.")
;;; Default implentations of optional methods
(cl-defmethod ztree-node-side ((node t))
(ignore node)
:left)
(cl-defmethod ztree-node-face ((node t))
"Return a face to write a NODE in"
(ignore node))
(cl-defmethod ztree-node-action ((node t) hard)
"Perform an action when the Return is pressed on a NODE.
Argument HARD specifies if the Return was pressed (t) or
Space (nil)"
(ignore node)
(ignore hard))
(cl-defmethod ztree-node-left-short-name ((node t))
"Return the left short name for a node in 2-sided tree."
(ztree-node-short-name node))
(cl-defmethod ztree-node-right-short-name ((node t))
"Return the right short name for a node in 2-sided tree."
(ztree-node-short-name node))
(provide 'ztree-protocol)
;;; ztree-protocol.el ends here