Skip to content

Commit

Permalink
Add auto scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
s-kostyaev committed Dec 19, 2023
1 parent 5d3e37c commit d089d66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Version 0.4.2
- Add auto scrolling. Disabled by default.
* Version 0.4.1
- Fix adding and completing code. Do it inline instead of end of buffer.
* Version 0.4.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ documentation](https://elpa.gnu.org/packages/llm.html)
- `ellama-spinner-type`: Spinner type for ellama. Default type is
`progress-bar`.
- `ellama-ollama-binary`: Path to ollama binary.
- `ellama-auto-scroll`: If enabled ellama buffer will scroll
automatically during generation. Disabled by default.

## Acknowledgments

Expand Down
29 changes: 22 additions & 7 deletions ellama.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
;; Package-Requires: ((emacs "28.1") (llm "0.6.0") (spinner "1.7.4"))
;; Version: 0.4.1
;; Version: 0.4.2
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023

Expand Down Expand Up @@ -100,6 +100,11 @@
:type 'string
:group 'tools)

(defcustom ellama-auto-scroll nil
"If enabled ellama buffer will scroll automatically during generation."
:type 'boolean
:group 'tools)

(defvar-local ellama--chat-prompt nil)

(defvar-local ellama--change-group nil)
Expand Down Expand Up @@ -255,8 +260,8 @@ In BUFFER at POINT will be inserted result between PREFIX and SUFFIX."
(get-buffer-create ellama-buffer)
(with-current-buffer ellama-buffer
(funcall ellama-buffer-mode)))
(display-buffer ellama-buffer)
(with-current-buffer ellama-buffer
(display-buffer ellama-buffer)
(if ellama--chat-prompt
(llm-chat-prompt-append-response
ellama--chat-prompt prompt)
Expand All @@ -268,6 +273,7 @@ In BUFFER at POINT will be inserted result between PREFIX and SUFFIX."
(let* ((start (make-marker))
(end (make-marker))
(point (point-max))
(window (selected-window))
(insert-text
(lambda (text)
;; Erase and insert the new text between the marker cons.
Expand All @@ -276,13 +282,22 @@ In BUFFER at POINT will be inserted result between PREFIX and SUFFIX."
(goto-char start)
(delete-region start end)
(insert text)
(fill-region start (point)))))))
(fill-region start (point)))
(when ellama-auto-scroll
(select-window (get-window-with-predicate
(lambda (_)
(eq (current-buffer)
(get-buffer ellama-buffer))))
t)
(goto-char (point-max))
(recenter -1)
(select-window window))))))
(setq ellama--change-group (prepare-change-group))
(activate-change-group ellama--change-group)
(set-marker start point)
(set-marker end point)
(set-marker-insertion-type start nil)
(set-marker-insertion-type end t)
(set-marker start point)
(set-marker end point)
(set-marker-insertion-type start nil)
(set-marker-insertion-type end t)
(spinner-start ellama-spinner-type)
(llm-chat-streaming ellama-provider
ellama--chat-prompt
Expand Down

0 comments on commit d089d66

Please sign in to comment.