mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 16:14:21 +00:00
Improve logic to create vs reuse window for khoj side pane logic
Khoj side pane occupies a vertically split bottom right side pane. If the bottom right window is not a vertical split, create a new vertical split pane for khoj, otherwise reuse the existing window
This commit is contained in:
parent
055e5e8d26
commit
e15dc23bbe
1 changed files with 25 additions and 10 deletions
|
@ -736,20 +736,27 @@ Render results in BUFFER-NAME using search results, CONTENT-TYPE and (optional)
|
||||||
(defun khoj--open-side-pane (buffer-name)
|
(defun khoj--open-side-pane (buffer-name)
|
||||||
"Open Khoj BUFFER-NAME in right side pane."
|
"Open Khoj BUFFER-NAME in right side pane."
|
||||||
(if (get-buffer-window-list buffer-name)
|
(if (get-buffer-window-list buffer-name)
|
||||||
; if window is already open, switch to it
|
;; if window is already open, switch to it
|
||||||
(progn
|
(progn
|
||||||
(select-window (get-buffer-window buffer-name))
|
(select-window (get-buffer-window buffer-name))
|
||||||
(switch-to-buffer buffer-name))
|
(switch-to-buffer buffer-name))
|
||||||
;; else if window is not open, open it as a right-side window pane
|
;; else if window is not open, open it as a right-side window pane
|
||||||
|
(let ((bottomright-window (some-window (lambda (window) (and (window-at-side-p window 'right) (window-at-side-p window 'bottom))))))
|
||||||
(progn
|
(progn
|
||||||
;; Select the right-most window
|
;; Select the right-most window
|
||||||
(select-window (some-window (lambda (window) (window-at-side-p window 'right))))
|
(select-window bottomright-window)
|
||||||
;; Split the window to the right and resize it to take up 1/3 of the frame width
|
;; if bottom-right window is not a vertical pane, split it vertically, else use the existing bottom-right vertical window
|
||||||
(let ((new-window (split-window-right)))
|
(let ((khoj-window (if (window-at-side-p bottomright-window 'left)
|
||||||
(set-window-buffer new-window buffer-name)
|
(split-window-right)
|
||||||
(window-resize new-window
|
bottomright-window)))
|
||||||
|
;; Set the buffer in the khoj window
|
||||||
|
(set-window-buffer khoj-window buffer-name)
|
||||||
|
;; Switch to the khoj window
|
||||||
|
(select-window khoj-window)
|
||||||
|
;; Resize the window to 1/3 of the frame width
|
||||||
|
(window-resize khoj-window
|
||||||
(- (truncate (* 0.33 (frame-width))) (window-width))
|
(- (truncate (* 0.33 (frame-width))) (window-width))
|
||||||
t)))))
|
t))))))
|
||||||
|
|
||||||
(defun khoj--load-chat-session (buffer-name &optional session-id)
|
(defun khoj--load-chat-session (buffer-name &optional session-id)
|
||||||
"Load Khoj Chat conversation history into BUFFER-NAME."
|
"Load Khoj Chat conversation history into BUFFER-NAME."
|
||||||
|
@ -781,6 +788,7 @@ Render results in BUFFER-NAME using search results, CONTENT-TYPE and (optional)
|
||||||
|
|
||||||
;; create khoj chat shortcut keybindings
|
;; create khoj chat shortcut keybindings
|
||||||
(use-local-map (copy-keymap org-mode-map))
|
(use-local-map (copy-keymap org-mode-map))
|
||||||
|
(local-set-key (kbd "q") #'khoj--close)
|
||||||
(local-set-key (kbd "m") #'khoj--chat)
|
(local-set-key (kbd "m") #'khoj--chat)
|
||||||
(local-set-key (kbd "C-x m") #'khoj--chat)
|
(local-set-key (kbd "C-x m") #'khoj--chat)
|
||||||
|
|
||||||
|
@ -788,6 +796,13 @@ Render results in BUFFER-NAME using search results, CONTENT-TYPE and (optional)
|
||||||
(visual-line-mode)
|
(visual-line-mode)
|
||||||
(read-only-mode t)))))
|
(read-only-mode t)))))
|
||||||
|
|
||||||
|
(defun khoj--close ()
|
||||||
|
"Kill Khoj buffer and window"
|
||||||
|
(interactive)
|
||||||
|
(progn
|
||||||
|
(kill-buffer (current-buffer))
|
||||||
|
(delete-window)))
|
||||||
|
|
||||||
(defun khoj--add-hover-text-to-footnote-refs (start-pos)
|
(defun khoj--add-hover-text-to-footnote-refs (start-pos)
|
||||||
"Show footnote defs on mouse hover on footnote refs from START-POS."
|
"Show footnote defs on mouse hover on footnote refs from START-POS."
|
||||||
(org-with-wide-buffer
|
(org-with-wide-buffer
|
||||||
|
|
Loading…
Add table
Reference in a new issue