|
91 | 91 | (defvar-local cquery-tree--cur-client nil |
92 | 92 | "Buffer tree client.") |
93 | 93 |
|
94 | | -(defvar-local cquery-tree--calling t |
| 94 | +(defvar-local cquery-tree-calling t |
95 | 95 | "When non-nil, visit the node when the selected line changes.") |
96 | 96 |
|
97 | 97 | (defun cquery-tree--read-node (data &optional parent) |
|
254 | 254 | (defun cquery-tree-toggle-calling () |
255 | 255 | "Toggle `cquery-tree-calling'." |
256 | 256 | (interactive) |
257 | | - (when (setq cquery-tree--calling (not cquery-tree--calling)) |
| 257 | + (when (setq cquery-tree-calling (not cquery-tree-calling)) |
258 | 258 | (cquery-tree-press))) |
259 | 259 |
|
260 | | -(defun cquery-tree-press () |
| 260 | +(defun cquery-tree-press (&optional split-fn) |
261 | 261 | "Jump to the location." |
262 | 262 | (interactive) |
263 | 263 | (-when-let* ((workspace lsp--cur-workspace) |
264 | 264 | (node (cquery-tree--node-at-point))) |
265 | 265 | (with-selected-window cquery-tree--origin-win |
| 266 | + (when split-fn |
| 267 | + (funcall split-fn)) |
266 | 268 | (find-file (car (cquery-tree-node-location node))) |
267 | 269 | ;; TODO Extract lsp-ui-peek.el lsp-ui-peek--goto-xref |
268 | 270 | (unless lsp--cur-workspace |
|
280 | 282 | (cquery-tree-press) |
281 | 283 | (select-window cquery-tree--origin-win)) |
282 | 284 |
|
| 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 | + |
283 | 297 | (defun cquery-tree-next-line (&optional arg) |
284 | 298 | (interactive "p") |
285 | 299 | (forward-line arg) |
286 | | - (when cquery-tree--calling |
| 300 | + (when cquery-tree-calling |
287 | 301 | (cquery-tree-press))) |
288 | 302 |
|
289 | 303 | (defun cquery-tree-prev-line (&optional arg) |
290 | 304 | (interactive "p") |
291 | 305 | (forward-line (- arg)) |
292 | | - (when cquery-tree--calling |
| 306 | + (when cquery-tree-calling |
293 | 307 | (cquery-tree-press))) |
294 | 308 |
|
| 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 | + |
295 | 325 | (defun cquery-tree-expand-or-set-root () |
296 | 326 | "If the node at point is unexpanded expand it, otherwise set it as root" |
297 | 327 | (interactive) |
|
332 | 362 | (define-key map (kbd "h") 'cquery-tree-collapse-or-select-parent) |
333 | 363 | (define-key map (kbd "j") 'cquery-tree-next-line) |
334 | 364 | (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) |
335 | 367 | (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) |
336 | 371 | (define-key map (kbd "q") 'cquery-tree-quit) |
337 | 372 | (define-key map (kbd "Q") 'quit-window) |
338 | 373 | (define-key map (kbd "RET") 'cquery-tree-press-and-switch) |
|
0 commit comments