rksm / org-ai

Emacs as your personal AI assistant. Use LLMs such as ChatGPT or LLaMA for text generation or DALL-E and Stable Diffusion for image generation. Also supports speech input / output.
GNU General Public License v3.0
701 stars 56 forks source link

void-variable evil-org-ai-on-region #133

Closed tillydray closed 4 weeks ago

tillydray commented 1 month ago

I use Doom Emacs. I just updated to the latest org-ai and got this error when restarting emacs Error caused by user's config or system: .doom.d/config.el, (void-variable evil-org-ai-on-region). Relevant output is below.

GNU Emacs     v30.0.91         nil
Doom core     v3.0.0-pre       HEAD -> master c8a5e6ec1 2024-09-17 17:30:57 -0400
Doom modules  v24.10.0-pre     HEAD -> master c8a5e6ec1 2024-09-17 17:30:57 -0400
Output of `doom doctor` ``` x There was an unexpected runtime error Message: Symbol's value as variable is void Details: (evil-org-ai-on-region) Backtrace: (byte-code "\306\307\310\311\312\313%\210\314\300\315\316\317DD\320\32... (require org-ai-evil-integrations) (progn (require 'org-ai-evil-integrations)) (if (featurep 'evil) (progn (require 'org-ai-evil-integrations))) (load-with-code-conversion "/Users/jason/.emacs.d/.local/straight/buil... (org-ai-global-mode) (progn (add-hook 'org-mode-hook #'org-ai-mode) (org-ai-global-mode)) (condition-case err (progn (add-hook 'org-mode-hook #'org-ai-mode) (or... (progn (if (fboundp 'org-ai-mode) nil (autoload #'org-ai-mode "org-ai"... (condition-case err (progn (if (fboundp 'org-ai-mode) nil (autoload #'... (load-with-code-conversion "/Users/jason/.doom.d/config.el" "/Users/ja... (load "/Users/jason/.doom.d/config" t nomessage) GNU Emacs v30.0.91 nil Doom core v3.0.0-pre HEAD -> master c8a5e6ec1 2024-09-17 17:30:57 -0400 Doom modules v24.10.0-pre HEAD -> master c8a5e6ec1 2024-09-17 17:30:57 -0400 ```
Output of emacs --daemon="em2" --debug-init && emacsclient -nc -s "em2" ``` Debugger entered--Lisp error: (void-variable evil-org-ai-on-region) byte-code("\306\307\310\311\312\313%\210\314\300\315\316\317DD\320\321\322\312\307&\7\210\314\305\315\316\323DD\324\321\322\312\307&\7\210\325\326!\203e\0\327\10\301\"\210\330\11\304\n\13\"\331\332\310\211\333\334!\335\f\n\3#\262\1&\7\210\327\15\336\"\210\330\16\36\304\n\13\"\337\332\310\211\333\340!\341\f\n\3#\262\1&\7\210\342\343!\207" [org-ai-evil-cmd-ar evil-org-ai-on-region end question start org-ai-evil-cmd-cr custom-declare-group org-ai-evil nil "Customizable options for org-ai package Evil mode integrations." :group org-ai custom-declare-variable funcall function #f(compiled-function () #) ("/Users/jason/.emacs.d/.local/straight/build-30.0.91/org-ai/org-ai-evil-integrations.elc" . 86) :type string #f(compiled-function () #) ("/Users/jason/.emacs.d/.local/straight/build-30.0.91/org-ai/org-ai-evil-integrations.elc" . 152) featurep evil evil-ex-define-cmd evil-define-command "Ask a QUESTION with `org-ai-on-region` for the region from START to END." :move-point read-string "What do you want to know? " org-ai-on-region evil-org-ai-change-range "Ask a QUESTION with `org-ai-refactor-code` for the region from START to END." "How do you want to refactor the code? " org-ai-refactor-code provide org-ai-evil-integrations] 12) require(org-ai-evil-integrations) (progn (require 'org-ai-evil-integrations)) (if (featurep 'evil) (progn (require 'org-ai-evil-integrations))) load-with-code-conversion("/Users/jason/.emacs.d/.local/straight/build-30.0.91/org-ai/org-ai.el" "/Users/jason/.emacs.d/.local/straight/build-30.0.91/org-ai/org-ai.el" nil t) (org-ai-global-mode) load-with-code-conversion("/Users/jason/.doom.d/config.el" "/Users/jason/.doom.d/config.el" t t) load("/Users/jason/.doom.d/config" t nomessage) (condition-case e (load path noerror 'nomessage) ((debug doom-error) (signal (car e) (cdr e))) ((debug error) (setq path (locate-file path load-path (get-load-suffixes))) (if (not (and path (featurep 'doom))) (signal (car e) (cdr e)) (cl-loop for (err . dir) in (list (cons 'doom-cli-error (expand-file-name "cli" doom-core-dir)) (cons 'doom-core-error doom-core-dir) (cons 'doom-user-error doom-user-dir) (cons 'doom-profile-error doom-profile-dir) (cons 'doom-module-error doom-modules-dir)) if (file-in-directory-p path dir) do (signal err (list (file-relative-name path (expand-file-name "../" dir)) e)))))) doom-load("/Users/jason/.doom.d/config" t) byte-code("\306\307\310\311#\210\312\313\314\307#\210\306\315\316\317#\210\306\320\316\321#\210\322\323\320\"\210\322\324\320\"\210\322\325\326\"\210\322\327\326\"\210\306\330\316\331#\210\322\332\320\"\210\322\333\320\"\210\306\334\316\335#\210\306\336\316\337#\210\306\340\341\342\343\344%\210\345\340\346\347#\306\350\351\352#\210\306\353\351\354#\210\306\355\356\357#\210\306\360\356\361#\210\306\362\363\364#\210\306\365\363\366#\210\306\367\370\371\344$\210\306\372\373\374\344$\210\306\375\376\377\343\344%\210\306\201A\0\376\201B\0\343\344%\210\306\201C\0\376\201D\0\343\344%\210\306\201E\0\376\201F\0\343\344%\210\306\201G\0\376\201H\0\343\344%\210\306\201I\0\376\201J\0\344$\210\201K\0\201L\0!\204\336\0\201K\0\201M\0!\203n\4\10\30\201N\0\201O\0!\211\203\370\0\211@\201P\0\1!\266\2A\202\347\0\210\201Q\0\21\343\22\201R\0\201S\0\201T\0\"\210\201R\0\201U\0\201V\0\"\210\201R\0\201W\0\201X\0\"\210\201R\0\201Y\0\201Z\0\"\210\201R\0\201[\0\201\\\0\"\210\201R\0\201]\0\201^\0\"\210\201R\0\201_\0\201`\0\"\210\201R\0\201a\0\201b\0\"\210\201R\0\201c\0\201d\0\"\210\201R\0\201e\0\201f\0\"\210\201R\0\201g\0\201h\0\"\210\201R\0\201i\0\201j\0\"\210\13\201k\0\34\201l\0\201m\0\344\")\210\201n\0\34\201l\0\201o\0\15\201p\0\"\344\")\210\201q\0\201r\0!\210\201s\0\34\201l\0\201t\0\344\")\210\201q\0\201u\0!\210\201q\0\201v\0!\210\201w\0\34\201l\0\201x\0\344\")\210\201y\0\34\201l\0\201z\0\344\")\210\201{\0\34\201l\0\201|\0\344\")\210\201}\0\34\201l\0\201~\0\344\")\210\201\177\0\34\201l\0\201\200\0\344\")\210\201\201\0\34\201l\0\201\202\0\344\")\210\201\203\0\34\201l\0\201\204\0\344\")\210\201\205\0\34\201l\0\201\206\0\344\")\210\201\207\0\34\201l\0\201\210\0\344\")\210\201\211\0\34\201l\0\201\212\0\344\")\210\201\213\0\34\201l\0\201\214\0\344\")\210\201\215\0\34\201l\0\201\216\0\344\")\210\201\217\0\34\201l\0\201\220\0\344\")\210\201\221\0\34\201l\0\201\222\0\344\")\210\201\223\0\34\201l\0\201\224\0\344\")\210\201\225\0\34\201l\0\201\226\0\344\")\210\201\227\0\34\201l\0\201\230\0\344\")\210\201\231\0\34\201l\0\201\232\0\344\")\210\201\233\0\34\201l\0\201\234\0\344\")\210\201\235\0\34\201l\0\201\236\0\344\")\210\201\237\0\34\201l\0\201\240\0\344\")\210\201\241\0\34\201l\0\201\242\0\344\")\210\201\243\0\34\201l\0\201\244\0\344\")\210\201\245\0\34\201l\0\201\246\0\344\")\210\201\247\0\34\201l\0\201\250\0\344\")\210\201\251\0\34\201l\0\201\252\0\344\")\210\201\253\0\34\201l\0\201\254\0\344\")\210\201\255\0\34\201l\0\201\256\0\344\")\210\201\257\0\34\201l\0\201\260\0\344\")\210\201\261\0\34\201l\0\201\262\0\344\")\210\201\263\0\34\201l\0\201\264\0\344\")\210\201\265\0\34\201l\0\201\266\0\344\")\210\201\267\0\34\201l\0\201\270\0\344\")\210\201\271\0\34\201l\0\201\272\0\344\")\210\201\273\0\34\201l\0\201\274\0\344\")\210\201\275\0\34\201l\0\201\276\0\344\")\210\201\277\0\34\201l\0\201\300\0\344\")\210\201\301\0\34\201l\0\201\302\0\344\")\210\201\303\0\34\201l\0\201\304\0\344\")\210\201\305\0\34\201l\0\201\306\0\344\")\210\201\307\0\34\201l\0\201\310\0\344\")\210\201\311\0\34\201l\0\201\312\0\344\")\210\201\313\0\34\201l\0\201\314\0\344\")\210\201\315\0\34\201l\0\201\316\0\344\")\210\201\317\0\34\201l\0\201\320\0\344\")\210\201q\0\201\321\0!\210\201\322\0\34\201l\0\201o\0\16@\201\323\0\"\344\")\210\13\1=\203l\4\201l\0\13\201\324\0\"\210)\210\343\207" [doom-context doom-modules doom-disabled-packages custom-file doom-module-context doom-core-dir autoload auto-minor-mode-set "auto-minor-mode" ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1116754) advice-add set-auto-mode :after use-package-autoload-keymap "use-package-bind-key" ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1116980) use-package-normalize-binder ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117524) defalias use-package-normalize/:bind use-package-normalize/:bind* use-package-autoloads/:bind use-package-autoloads-mode use-package-autoloads/:bind* use-package-handler/:bind ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117554) use-package-normalize/:bind-keymap use-package-normalize/:bind-keymap* use-package-handler/:bind-keymap ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117616) use-package-handler/:bind-keymap* ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117676) use-package "use-package-core" ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117718) nil t function-put lisp-indent-function defun use-package-normalize/:delight "use-package-delight" ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1121218) use-package-handler/:delight ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1121279) use-package-normalize/:diminish "use-package-diminish" ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117524) use-package-handler/:diminish ("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" . 1117676) ...] 7) load("/Users/jason/.emacs.d/.local/etc/@/init.30.elc" noerror nomessage nosuffix) (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete (assoc init-file-name load-history) load-history))) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete (assoc init-file-name load-history) load-history)))) (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete (assoc init-file-name load-history) load-history)))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))) (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete (assoc init-file-name load-history) load-history)))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el")))) (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete (assoc init-file-name load-history) load-history)))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))) (condition-case error (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix) (setq load-history (delete ... load-history)))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while booting Doom Emacs:\n\n%s%s%s\n\nTo ensure normal operation, you should investigate and remove the\ncause of the error in your Doom config files. Start Emacs with\nthe `--debug-init' option to view a complete error backtrace." (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'(lambda (s) (prin1-to-string s t)) (cdr error) ", ")) :warning) (setq init-file-had-error t))) (let ((debug-on-error debug-on-error-initial)) (condition-case error (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir ...))) (setq user-init-file t) (if init-file-name (progn (load init-file-name ... ... ...) (setq load-history ...))) (if (eq user-init-file t) (progn (signal ... ...))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while booting Doom Emacs:\n\n%s%s%s\n\nTo ensure normal operation, you should investigate and remove the\ncause of the error in your Doom config files. Start Emacs with\nthe `--debug-init' option to view a complete error backtrace." (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'(lambda ... ...) (cdr error) ", ")) :warning) (setq init-file-had-error t))) (or (eq debug-on-error debug-on-error-initial) (progn (setq debug-on-error-should-be-set t) (setq debug-on-error-from-init-file debug-on-error)))) (let ((debug-on-error-from-init-file nil) (debug-on-error-should-be-set nil) (debug-on-error-initial (if (eq init-file-debug t) 'startup init-file-debug)) (inhibit-null-byte-detection t)) (let ((debug-on-error debug-on-error-initial)) (condition-case error (if init-file-user (progn (let ((init-file-name ...)) (setq user-init-file t) (if init-file-name (progn ... ...)) (if (eq user-init-file t) (progn ...)) (setq user-init-file (concat ... ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while booting Doom Emacs:\n\n%s%s%s\n\nTo ensure normal operation, you should investigate and remove the\ncause of the error in your Doom config files. Start Emacs with\nthe `--debug-init' option to view a complete error backtrace." (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'... (cdr error) ", ")) :warning) (setq init-file-had-error t))) (or (eq debug-on-error debug-on-error-initial) (progn (setq debug-on-error-should-be-set t) (setq debug-on-error-from-init-file debug-on-error)))) (if debug-on-error-should-be-set (progn (setq debug-on-error debug-on-error-from-init-file)))) startup--load-user-init-file@init-doom(#f(compiled-function () #) #f(compiled-function () #) t) apply(startup--load-user-init-file@init-doom (#f(compiled-function () #) #f(compiled-function () #) t)) startup--load-user-init-file(#f(compiled-function () #) #f(compiled-function () #) t) command-line() normal-top-level() Killing Emacs. Sayonara! Error: server did not start correctly ```

Related to https://github.com/rksm/org-ai/pull/127 and https://github.com/rksm/org-ai/issues/126

wolfangpauli commented 1 month ago

Same issue here:

doom doctor: GNU Emacs v29.3 nil Doom core v3.0.0-pre grafted, HEAD -> master, origin/master, origin/HEAD 8b9168de 2024-10-03 02:26:28 -0400 Doom modules v24.11.0-pre grafted, HEAD -> master, origin/master, origin/HEAD 8b9168de 2024-10-03 02:26:28 -0400

Pls., help

tillydray commented 1 month ago

@wolfangpauli

I didn't feel like troubleshooting the issue so if you just want Doom to work again, apply the below patch, or to do it manually

$ cd ~/.emacs.d/.local/straight/repos/org-ai
$ rm org-ai-evil-integrations.el

Then modify org-ai.el to remove these two lines

(when (featurep 'evil)
  (require 'org-ai-evil-integrations))

Next time you update doom it will ask you about these changes and prompt you to undo the changes, stash, or keep them, just fyi

Patch

diff --git a/org-ai-evil-integrations.el b/org-ai-evil-integrations.el
deleted file mode 100644
index daa988c..0000000
--- a/org-ai-evil-integrations.el
+++ /dev/null
@@ -1,36 +0,0 @@
-;;; org-ai-evil-integrations.el --- Evil mode integration for org-ai package -*- lexical-binding: t; -*-
-
-(defgroup org-ai-evil nil
-  "Customizable options for org-ai package Evil mode integrations."
-  :group 'org-ai)
-
-(defcustom org-ai-evil-cmd-ar "ar"
-  "Default Evil Ex command for querying a range in org-ai."
-  :type 'string
-  :group 'org-ai-evil)
-
-(defcustom org-ai-evil-cmd-cr "cr"
-  "Default Evil Ex command for refactoring a range in org-ai."
-  :type 'string
-  :group 'org-ai-evil)
-
-(when (featurep 'evil)
-  ;; Register custom commands with their customizable names
-  (evil-ex-define-cmd org-ai-evil-cmd-ar 'evil-org-ai-on-region)
-  (evil-define-command evil-org-ai-on-region (start end question)
-    "Ask a QUESTION with `org-ai-on-region` for the region from START to END."
-    :move-point nil
-    (interactive "<r><a>")
-    (let ((question (read-string "What do you want to know? ")))
-      (org-ai-on-region start end question)))
-
-  (evil-ex-define-cmd org-ai-evil-cmd-cr 'evil-org-ai-change-range)
-  (evil-define-command evil-org-ai-change-range (start end question)
-    "Ask a QUESTION with `org-ai-refactor-code` for the region from START to END."
-    :move-point nil
-    (interactive "<r><a>")
-    (let ((question (read-string "How do you want to refactor the code? ")))
-      (org-ai-refactor-code start end question))))
-
-(provide 'org-ai-evil-integrations)
-;;; org-ai-evil-integrations.el ends here
diff --git a/org-ai.el b/org-ai.el
index 9fc52e9..fb437c7 100644
--- a/org-ai.el
+++ b/org-ai.el
@@ -94,8 +94,6 @@
 (require 'org-ai-sd)
 (require 'org-ai-oobabooga)
 ;; Conditionally load Evil integrations if Evil is present
-(when (featurep 'evil)
-  (require 'org-ai-evil-integrations))

 ;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
wolfangpauli commented 1 month ago

Thanks a thousand times! It seems that org-ai has somehow affected my keymap for the evaluation of a #+begin_ai / #+end-Block from C-c C-c to blank-u C-c C-c It works perfectly and I can live with that.

rksm commented 1 month ago

My apologies, this seems to be a side effect of https://github.com/rksm/org-ai/pull/127. Reverting.

rksm commented 1 month ago

Not an evil user but this seems to be caused by this. Happy to accept fixes for a new version of #127.

tillydray commented 4 weeks ago

@rksm to get rid of the error we just need (require 'evil) at the top of the file. But when I do that and try to use o1-preview it seems to be stuck in an infinite loop and I have to force quit emacs. I'll report that as a separate issue

tillydray commented 4 weeks ago

Scratch that, things are working just fine now that I've updated to the latest version of org-ai v0.5.3