Skip to content

Commit

Permalink
Display current context in transient menu
Browse files Browse the repository at this point in the history
Refactored `ellama-manage-context` function to separate concerns by introducing
a new helper function `ellama-update-context-buffer`. Updated the transient
prefix command to refresh the context buffer content before displaying it. This
ensures that the displayed context is always up-to-date.
  • Loading branch information
s-kostyaev committed Feb 22, 2025
1 parent 7e0b688 commit d007a0f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions ellama.el
Original file line number Diff line number Diff line change
Expand Up @@ -1212,10 +1212,8 @@ If EPHEMERAL non nil new session will not be associated with any file."
:keymap ellama-context-mode-map
:group 'ellama)

;;;###autoload
(defun ellama-manage-context ()
"Manage the global context."
(interactive)
(defun ellama-update-context-buffer ()
"Update ellama context buffer."
(let* ((buf (get-buffer-create ellama-context-buffer))
(inhibit-read-only t))
(with-current-buffer buf
Expand All @@ -1226,11 +1224,17 @@ If EPHEMERAL non nil new session will not be associated with any file."
(insert (ellama-context-element-display el))
(put-text-property (pos-bol) (pos-eol) 'context-element el)
(insert "\n"))
(goto-char (point-min))
(display-buffer
buf
(when ellama-manage-context-display-action-function
`((ignore . (,ellama-manage-context-display-action-function))))))))
(goto-char (point-min)))))

;;;###autoload
(defun ellama-manage-context ()
"Manage the global context."
(interactive)
(ellama-update-context-buffer)
(display-buffer
ellama-context-buffer
(when ellama-manage-context-display-action-function
`((ignore . (,ellama-manage-context-display-action-function))))))

(defvar-keymap ellama-preview-context-mode-map
:doc "Local keymap for Ellama preview context mode buffers."
Expand Down Expand Up @@ -3072,6 +3076,11 @@ Call CALLBACK on result list of strings. ARGS contains keys for fine control.
(transient-define-prefix ellama-transient-context-menu ()
"Context Commands."
[["Context Commands"
:description (lambda ()
(ellama-update-context-buffer)
(format "Current context:
%s" (with-current-buffer ellama-context-buffer
(buffer-substring (point-min) (point-max)))))
("b" "Add Buffer" ellama-context-add-buffer)
("d" "Add Directory" ellama-context-add-directory)
("f" "Add File" ellama-context-add-file)
Expand Down

0 comments on commit d007a0f

Please sign in to comment.