Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undo on error #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ellama.el
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,11 @@
(funcall donecb text)
(setq ellama--current-request nil)
(ellama-request-mode -1)))
(lambda (_ msg)
(lambda (&rest args)
(with-current-buffer buffer
(cancel-change-group ellama--change-group)
(spinner-stop)
(funcall errcb msg)
(funcall errcb args)
(setq ellama--current-request nil)
(ellama-request-mode -1)))))))))

Expand Down Expand Up @@ -1281,16 +1281,18 @@
(end (if (region-active-p)
(region-end)
(point-max)))
(text (buffer-substring-no-properties beg end)))
(text (buffer-substring-no-properties beg end))
(buf (current-buffer)))
(kill-region beg end)
(ellama-stream
(format
ellama-change-prompt-template
change text)
:point beg)))
:point beg :on-error (lambda (&rest _)
(undo)))))

;;;###autoload

Check failure on line 1294 in ellama.el

View workflow job for this annotation

GitHub Actions / test-melpa (28.1, false, true, melpa, ellama.el)

Unused lexical variable `buf'

Check failure on line 1294 in ellama.el

View workflow job for this annotation

GitHub Actions / test-melpa (28.2, false, true, melpa, ellama.el)

Unused lexical variable `buf'
(defun ellama-improve-grammar ()

Check failure on line 1295 in ellama.el

View workflow job for this annotation

GitHub Actions / test-melpa (29.1, false, true, melpa, ellama.el)

Unused lexical variable `buf'

Check failure on line 1295 in ellama.el

View workflow job for this annotation

GitHub Actions / test-melpa (29.2, false, true, melpa, ellama.el)

Unused lexical variable `buf'

Check failure on line 1295 in ellama.el

View workflow job for this annotation

GitHub Actions / test-melpa (29.3, false, true, melpa, ellama.el)

Unused lexical variable `buf'
"Enhance the grammar and spelling in the currently selected region or buffer."
(interactive)
(ellama-change ellama-improve-grammar-prompt-template))
Expand Down
18 changes: 18 additions & 0 deletions tests/test-ellama.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
(require 'cl-lib)
(require 'ellama)
(require 'ert)
(require 'llm-ollama)

(ert-deftest test-ellama--code-filter ()
(should (equal "" (ellama--code-filter "")))
Expand Down Expand Up @@ -106,6 +107,23 @@
(let ((element (ellama-context-element-text :content "123")))
(should (string-match "123" (ellama-context-element-extract element)))))

(ert-deftest test-ellama-connection-error-undo ()
(with-temp-buffer
(buffer-enable-undo)
(funcall-interactively 'insert "test test")
(message "%s" buffer-undo-list)
;; (let ((ellama-provider (make-llm-ollama
;; :chat-model "1" :embedding-model "2" :port 3)))
;; (funcall-interactively 'ellama-improve-conciseness))
;; (sleep-for 3)
(message "'%s'" (buffer-substring-no-properties (point-min) (point-max)))
;; (funcall-interactively 'undo)
(undo)
(message "'%s'" (buffer-substring-no-properties (point-min) (point-max)))
(sleep-for 1)
(should (string= "test test"
(buffer-substring-no-properties (point-min) (point-max))))))

(provide 'test-ellama)

;;; test-ellama.el ends here
Loading