syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.67k stars 4.89k forks source link

Reason and workaround for string-edit-mode errors #15648

Closed gerd-moellmann closed 8 months ago

gerd-moellmann commented 2 years ago

Emacs version 29.0.50 spacemacs ba33309327e278a5fe7c12e095ed3a314523484f

'C-h k k' gives an error "void variable string-edit-mode"

The reason for this is that plain Emacs contains a string-edit-mode derived from text-mode. It has the function string-edit-mode, but not a variable of that name.

In spacemacs, minor-mode-alist ends up containing an entry (string-edit-mode . ...)'. Since the variable is not defined, this results in an error.

(The string-edit package on github defines a minor mode named 'string-edit-mode' and thus a variable. The package does not get loaded by spacemacs. BTW, it's not the best of all ideas to overwrite standard functions, so maybe spacemacs shouldn't try to support that package in the first place, which I think it does. Whatever.)

Locally, I've defined the variable, and the error is of course gone:

(defun dotspacemacs/user-init () (defvar string-edit-mode nil) ...

lebensterben commented 2 years ago

Please follow issue template for bug report.

thanhvg commented 2 years ago

@gerd-moellmann what version of string-edit-mode you are using? The latest one updated last June should have a fix for emacs 28 and there is a change of mine to modify the mode map only after the package is loaded. https://github.com/syl20bnr/spacemacs/pull/15625

I'm no longer living on the bleeding edge emacs so I can't check with emacs 29. We had a similar issue with restart-emacs package's name taken by upstream emacs 29. And @smile13241324 had a nice fix for it https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bspacemacs/spacemacs-navigation/packages.el#L370

If the new string-edit-mode in emacs 29 works for you then you can toggle it at https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bspacemacs/spacemacs-editing/packages.el#L44 :toggle (< emacs-major-version 29)

gerd-moellmann commented 2 years ago

I think this is a misunderstanding, sorry for not being clear enough:

The problem is that something in Spacemacs adds string-edit-mode to minor-mode-alist, but the string-edit package is never loaded.

In .emacs.d:

    $ find . -name "*string-edit+"
    ./eln-cache/29_0_50-9eea7e77/string-edit-94526701-cb1e119c.eln
    ./.cache/quelpa/melpa/recipes/string-edit

That's about what I can say.

Thanks.

smile13241324 commented 2 years ago

Interesting 🤔, project time is a bit rare for me right now though so I can't promis to be able to have a look at this myself.

I'll add the help wanted label lets see if someone finds the time.

emacs18 commented 1 year ago

I think the problem is that the string-edit-mode was renamed as string-edit-at-point-mode via https://github.com/magnars/string-edit.el/commit/4a25dc7168b4df62b9f83bf273dee92bb2ae39a6

My guess is that this was done in part due to the fact that string-edit-mode is now part of emacs 29. However this function is not autoloaded in emacs 29.

Thus it appears that we can resolve the problem in one of two ways.

I suspect that the second option won't be viable since it may work only for emacs 29 and later.

emacs18 commented 1 year ago

As I suspected the name change was to avoid conflict with built-in functions in emacs 29. See https://github.com/magnars/string-edit.el/issues/19 for details.

I tried the following patch, but it does not work in all cases, because spacemacs seems to use variable named string-edit-at-point-mode first prior to using function named string-edit-at-point-mode. Only the function is autoloaded. I don't now how to autoload variable. Any suggestions on how to resolve this problem?

An easy way to see the problem is to start emacs, hit C-h k followed by any key sequence such as C-x C-f. Error pops up saying that the variable is not defined. Manually loading string-edit-at-point.el at this point resolves the problem.

diff --git a/layers/+spacemacs/spacemacs-editing/packages.el b/layers/+spacemacs/spacemacs-editing/packages.el
index 38c163beb..ecdf39452 100644
--- a/layers/+spacemacs/spacemacs-editing/packages.el
+++ b/layers/+spacemacs/spacemacs-editing/packages.el
@@ -510,9 +510,11 @@
 (defun spacemacs-editing/init-string-edit ()
   (use-package string-edit
     :init
-    (spacemacs/set-leader-keys "xe" 'string-edit-at-point)
+    (progn
+      (spacemacs/set-leader-keys "xe" 'string-edit-at-point)
+      (autoload 'string-edit-at-point-mode "string-edit-at-point"))
     :config
-    (spacemacs/set-leader-keys-for-minor-mode 'string-edit-mode
+    (spacemacs/set-leader-keys-for-minor-mode 'string-edit-at-point-mode
       "," 'string-edit-conclude
       "c" 'string-edit-conclude
       "a" 'string-edit-abort
abellmann commented 1 year ago

My workaround for this issue in my dotspacemacs/additional-packages

     ;; workaround for renamed string-edit package (renamed from string-edit to string-edit-at-point leading to
     ;; issues in spacemacs, that expects string-edit. the commit is  the last before the rename of the package)
     ;; should be removed after the spacemacs issue is resolved (see https://github.com/syl20bnr/spacemacs/issues/15648)
     (string-edit :location (recipe :fetcher github :repo "magnars/string-edit.el" :commit "d7c4b9db6c4987b5c022a9858e6302a4c53aff5f"))
AFirooz commented 1 year ago

(defvar string-edit-mode nil)

I'm new to emacs and spacemacs, I keep getting this message each time I run spacemacs:

Found 2 new package(s) to install...
--> refreshing package archive: nongnu... [3/3]
--> installing package: string-edit@spacemacs-editing... [1/2]
Package string-edit is unavailable. Is the package name misspelled?
--> installing package: evil-ediff@spacemacs-evil... [2/2]
Package evil-ediff is unavailable. Is the package name misspelled?

I added your line in my dotspacemacs file but the error message didn't change. Not sure if this is related or not.

practicalli-johnny commented 1 year ago

Update: Recipes no longer required after #15815 and #15803 pull requests were merged. Thanks everyone.

@Ali-Firoozabadi A temporary fix for Emacs 28 (or earlier) would be to add package recipes to dotspacemacs-additional-packages key in the Spacemacs configuration, SPC f e d.

NOTE: this is not an official fix. hopefully packages and package use is updated in Spacemacs itself and these recipes should then be removed.

dotspacemacs-additional-packages '((evil-ediff
                                    :location
                                    (recipe :fetcher github
                                    :repo "emacs-evil/evil-ediff"
                                    :commit "50d26cb0654fca8f8fd7227410e5cbf0b8f681cf"))
                                   (string-edit
                                    :location
                                    (recipe :fetcher github
                                     :repo "magnars/string-edit.el"
                                     :commit "d7c4b9db6c4987b5c022a9858e6302a4c53aff5f")))
smile13241324 commented 1 year ago

I have merged a couple of fixes of which at least one was updating the related packages. I would really be cool if one of you could pull the latest version and post an update for this issue.

sunlin7 commented 1 year ago

The #15815 and mreged PR #15803 should resolved this issue.

emacs18 commented 1 year ago

C-h k k now works after starting vanilla spacemacs with vim mode selected.

practicalli-johnny commented 1 year ago

Deleted the packages I added via recipes and pulled the latest commits from the Spacemacs repository. The string-edit-at-point package was installed and no warning about the evil-ediff package.

Thank you for the swift updates and making all our Spacemacs journeys easier.

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!