Skip to content

Commit a3244fe

Browse files
committed
Add cquery-tree-next-sibling and cquery-tree-press-and-horizontal-split
1 parent 8f8b157 commit a3244fe

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

cquery-tree.el

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
(defvar-local cquery-tree--cur-client nil
9292
"Buffer tree client.")
9393

94-
(defvar-local cquery-tree--calling t
94+
(defvar-local cquery-tree-calling t
9595
"When non-nil, visit the node when the selected line changes.")
9696

9797
(defun cquery-tree--read-node (data &optional parent)
@@ -254,15 +254,17 @@
254254
(defun cquery-tree-toggle-calling ()
255255
"Toggle `cquery-tree-calling'."
256256
(interactive)
257-
(when (setq cquery-tree--calling (not cquery-tree--calling))
257+
(when (setq cquery-tree-calling (not cquery-tree-calling))
258258
(cquery-tree-press)))
259259

260-
(defun cquery-tree-press ()
260+
(defun cquery-tree-press (&optional split-fn)
261261
"Jump to the location."
262262
(interactive)
263263
(-when-let* ((workspace lsp--cur-workspace)
264264
(node (cquery-tree--node-at-point)))
265265
(with-selected-window cquery-tree--origin-win
266+
(when split-fn
267+
(funcall split-fn))
266268
(find-file (car (cquery-tree-node-location node)))
267269
;; TODO Extract lsp-ui-peek.el lsp-ui-peek--goto-xref
268270
(unless lsp--cur-workspace
@@ -280,18 +282,46 @@
280282
(cquery-tree-press)
281283
(select-window cquery-tree--origin-win))
282284

285+
(defun cquery-tree-press-and-horizontal-split ()
286+
"Split window horizontally and jump to the location."
287+
(interactive)
288+
(cquery-tree-press #'split-window-horizontally)
289+
(select-window cquery-tree--origin-win))
290+
291+
(defun cquery-tree-press-and-vertical-split ()
292+
"Split window vertically and jump to the location."
293+
(interactive)
294+
(cquery-tree-press #'split-window-vertically)
295+
(select-window cquery-tree--origin-win))
296+
283297
(defun cquery-tree-next-line (&optional arg)
284298
(interactive "p")
285299
(forward-line arg)
286-
(when cquery-tree--calling
300+
(when cquery-tree-calling
287301
(cquery-tree-press)))
288302

289303
(defun cquery-tree-prev-line (&optional arg)
290304
(interactive "p")
291305
(forward-line (- arg))
292-
(when cquery-tree--calling
306+
(when cquery-tree-calling
293307
(cquery-tree-press)))
294308

309+
(defun cquery-tree-next-sibling (&optional arg)
310+
(interactive "p")
311+
(when-let* ((depth (cquery-tree--depth-at-point)))
312+
(while (and (forward-line 1)
313+
(< depth (or (cquery-tree--depth-at-point) 0))))
314+
(when cquery-tree-calling
315+
(cquery-tree-press))))
316+
317+
(defun cquery-tree-prev-sibling (&optional arg)
318+
(interactive "p")
319+
(when-let* ((depth (cquery-tree--depth-at-point)))
320+
(while (and (forward-line -1)
321+
(< depth (or (cquery-tree--depth-at-point) 0))))
322+
(when cquery-tree-calling
323+
(cquery-tree-press))))
324+
295325
(defun cquery-tree-expand-or-set-root ()
296326
"If the node at point is unexpanded expand it, otherwise set it as root"
297327
(interactive)
@@ -332,7 +362,12 @@
332362
(define-key map (kbd "h") 'cquery-tree-collapse-or-select-parent)
333363
(define-key map (kbd "j") 'cquery-tree-next-line)
334364
(define-key map (kbd "k") 'cquery-tree-prev-line)
365+
(define-key map (kbd "J") 'cquery-tree-next-sibling)
366+
(define-key map (kbd "K") 'cquery-tree-prev-sibling)
335367
(define-key map (kbd "l") 'cquery-tree-expand-or-set-root)
368+
(define-key map (kbd "oh") 'cquery-tree-press-and-horizontal-split)
369+
(define-key map (kbd "ov") 'cquery-tree-press-and-vertical-split)
370+
(define-key map (kbd "oo") 'cquery-tree-press-and-switch)
336371
(define-key map (kbd "q") 'cquery-tree-quit)
337372
(define-key map (kbd "Q") 'quit-window)
338373
(define-key map (kbd "RET") 'cquery-tree-press-and-switch)

0 commit comments

Comments
 (0)