3
3
; ; Author: Bob Weiner
4
4
; ;
5
5
; ; Orig-Date: 19-Nov-17
6
- ; ; Last-Mod: 20-Jan -24 at 20:20:00 by Mats Lidell
6
+ ; ; Last-Mod: 10-Nov -24 at 17:27:30 by Bob Weiner
7
7
; ;
8
8
; ; SPDX-License-Identifier: GPL-3.0-or-later
9
9
; ;
26
26
27
27
(or (require 'treemacs nil t )
28
28
(and (package-installed-p 'treemacs )
29
- (package-activate 'treemacs )))
29
+ (package-activate 'treemacs ))
30
+ (hypb:require-package 'treemacs ))
30
31
31
32
(defvar treemacs-version )
32
33
39
40
(declare-function treemacs " ext:treemacs" )
40
41
(declare-function treemacs-current-button " ext:treemacs-core-utils" )
41
42
(declare-function treemacs-current-visibility " ext:treemacs-scope" )
42
- (declare-function treemacs-get-local-buffer " ext:treemacs-scope" )
43
+ (declare-function treemacs-get-local-window " ext:treemacs-scope" )
43
44
(declare-function treemacs-is-treemacs-window? " ext:treemacs-core-utils" )
44
- (declare-function treemacs-node-buffer-and-position " etx :treemacs-mouse-interface" )
45
- (declare-function treemacs-quit " ext:treemacs-core-utils " )
45
+ (declare-function treemacs-node-buffer-and-position " ext :treemacs-mouse-interface" )
46
+ (declare-function treemacs-quit " ext:treemacs-interface " )
46
47
(declare-function treemacs-toggle-node " ext:treemacs-interface" )
47
48
(defvar aw-ignored-buffers )
48
49
68
69
(unless (fboundp 'treemacs-quit )
69
70
(fset 'treemacs-quit #'bury-buffer ))
70
71
72
+ ;;;### autoload
73
+ (defun smart-treemacs-edit (&optional dir )
74
+ " Use `treemacs' to edit optional DIR or the `default-directory' ."
75
+ (let ((default-directory (if (stringp dir) dir default-directory)))
76
+ (cond ((fboundp #'treemacs-add-and-display-current-project-exclusively )
77
+ (treemacs-add-and-display-current-project-exclusively))
78
+ ; ; Older obsoleted function
79
+ ((fboundp #'treemacs-display-current-project-exclusively )
80
+ (treemacs-display-current-project-exclusively))
81
+ (t (treemacs)))))
82
+
83
+ (defun smart-treemacs-quit (&optional arg )
84
+ " Quit treemacs visible in current frame with `bury-buffer' .
85
+ With a prefix ARG call `treemacs-kill-buffer' instead."
86
+ (interactive " P" )
87
+ (when (eq (treemacs-current-visibility) 'visible )
88
+ (with-selected-window (treemacs-get-local-window)
89
+ (treemacs-quit arg))))
90
+
71
91
;;;### autoload
72
92
(defun smart-treemacs ()
73
93
" Use a single key or mouse key to manipulate directory entries.
@@ -77,37 +97,28 @@ caller has already checked that the key was pressed in an appropriate buffer
77
97
and has moved the cursor there.
78
98
79
99
If key is pressed:
80
- (1) on an entry icon, the treemacs TAB command is run to expand and
81
- collapse the entry;
82
- (2) elsewhere within an entry line, the item is displayed for editing,
83
- normally in another window;
84
- (3) at the end of an entry line: invoke `action-key-eol-function' ,
85
- typically to scroll up proportionally, if an Action Key press; invoke
86
- `assist-key-eol-function' , typically to scroll down proportionally,
87
- if an Asisst Key press;
88
- (4) on the first line of the buffer (other than the end of line),
89
- Dired is run on the current directory of this Treemacs;
90
- (5) at the end of the first or last line of the buffer,
91
- this Treemacs invocation is quit."
100
+ (1) on or to the left of an entry icon, run the treemacs TAB command
101
+ to expand or collapse the entry;
102
+ (2) elsewhere within an entry line, display the item, which may be a
103
+ directory, for editing, normally in another window;
104
+ (3) at the end of an entry line: if an Action Key press, invoke
105
+ `action-key-eol-function' , typically to scroll up proportionally;
106
+ if an Asisst Key press, invoke `assist-key-eol-function' , typically
107
+ to scroll down proportionally;
108
+ (4) at the end of the first or last line of the buffer, quit this
109
+ Treemacs invocation."
92
110
93
111
(interactive )
94
- (cond ((first-line-p)
95
- (if (eolp )
96
- (treemacs-quit)
97
- (hact 'link-to-directory default-directory)))
98
- ((and (last-line-p) (eolp ))
99
- (treemacs-quit))
112
+ (cond ((and (eolp ) (or (first-line-p) (last-line-p)))
113
+ (hact 'smart-treemacs-quit ))
100
114
((eolp )
101
- (funcall (if assist-flag assist-key-eol-function action-key-eol-function)))
102
- (t (let ((over-icon (and (treemacs-current-button)
103
- (= (point ) (- (button-start (treemacs-current-button)) 2 ))))
104
- (result (treemacs-node-buffer-and-position)))
105
- (if (and (not over-icon) result (or (bufferp result) (listp result)))
106
- (if (listp result)
107
- (hact 'link-to-buffer-tmp (seq-elt result 0 ) (seq-elt result 1 ))
108
- ; ; (bufferp result)
109
- (hact 'link-to-buffer-tmp result))
110
- (treemacs-toggle-node current-prefix-arg))))))
115
+ (hact 'funcall (if assist-flag assist-key-eol-function action-key-eol-function)))
116
+ (t (if (and (treemacs-current-button)
117
+ (= (point ) (- (button-start (treemacs-current-button)) 2 )))
118
+ ; ; Before or on the entry's icon
119
+ (hact 'treemacs-TAB-action current-prefix-arg)
120
+ ; ; On the entry, handles dirs, files and tag entries
121
+ (hact 'treemacs-RET-action current-prefix-arg)))))
111
122
112
123
;;;### autoload
113
124
(defun smart-treemacs-modeline ()
@@ -123,21 +134,23 @@ Suitable for use as a value of `action-key-modeline-buffer-id-function'."
123
134
; ; Clicked on Treemacs buffer id
124
135
((if action-key-depress-window
125
136
(treemacs-is-treemacs-window? action-key-depress-window)
126
- (string-match " Treemacs " (format-mode-line mode-line-format)))
137
+ (hact ' string-match " Treemacs " (format-mode-line mode-line-format)))
127
138
; ; Quit/hide treemacs.
128
- (treemacs-quit))
139
+ (hact ' treemacs-quit ))
129
140
; ;
130
141
; ; Treemacs is visible and displaying the same dir as
131
142
; ; the default dir of the clicked on modeline.
132
143
((and (eq (treemacs-current-visibility) 'visible )
133
144
(string-equal (expand-file-name default-directory)
134
- (with-current-buffer (treemacs-get-local-buffer)
135
- default-directory)))
145
+ (with-selected-window (treemacs-get-local-window)
146
+ (save-excursion
147
+ (goto-char (point-min ))
148
+ default-directory))))
136
149
; ; Quit/hide treemacs.
137
- (treemacs-quit))
150
+ (hact 'smart- treemacs-quit ))
138
151
; ;
139
152
; ; Otherwise, invoke treemacs on the default dir of the clicked on modeline.
140
- (t (treemacs))))
153
+ (t (hact 'smart- treemacs-edit ))))
141
154
142
155
(provide 'hui-treemacs )
143
156
; ;; hui-treemacs.el ends here
0 commit comments