Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.8k stars 193 forks source link

Symbol definition void sp--syntax-class-to-char #1204

Closed practicalli-johnny closed 2 months ago

practicalli-johnny commented 2 months ago

Expected behavior

Should be able to slurp code, e.g. slurp a collection into an expression

Before

(map inc |) [1 2 3]

after

(map inc [1 2 3]) 

Slurp works with smartparens-20231024.1804

Actual behavior

Code is not slurped and error in message buffer

sp-get-buffer-char-syntax: Symbol’s function definition is void: sp--syntax-class-to-char

Steps to reproduce the problem

Update to smartparens-20240410.1709 package from melpa

Tested in latest Spacemacs develop branch and all latest packages downloaded as of 11 April 2024

Using smartparens-20231024.1804 does not experience this issue (last version used).

Backtraces if necessary (M-x toggle-debug-on-error)

Environment & version information

In recent enough smartparens you can call M-x sp-describe-system to generate this report. Please fill manually what we could not detect automatically. Edit the output as you see fit to protect your privacy.

zyxir commented 2 months ago

Same here. I looked into the source code and didn't find where sp--syntax-class-to-char is defined.

jahson commented 2 months ago

https://github.com/Fuco1/smartparens/blob/2fc945643f7d23d1aee78b8c8c09ecaeb35f30ee/smartparens.el#L1862

Fuco1 commented 2 months ago

Is that wrong syntax? Ups, I'll look into it.

jahson commented 2 months ago

Is that wrong syntax? Ups, I'll look into it.

I'm not sure if it is wrong syntax, just pointed to the code for @zyxir. For me it fails for other command:

Debugger entered--Lisp error: (void-function sp--syntax-class-to-char)
  sp--syntax-class-to-char(0)
  sp-get-buffer-char-syntax(1284)
  sp-syntax-after()
  sp-skip-forward-to-symbol(t nil t)
  sp-get-thing()
  sp-forward-sexp()
  sp-region-ok-p(1284 1309)
  evil-cp-region-ok-p(1284 1309)
  evil-cp-delete(1284 1309 line nil nil)
  funcall-interactively(evil-cp-delete 1284 1309 line nil nil)
  command-execute(evil-cp-delete)

It is working right after update and installation of new version, but stopped working as soon as I've restarted Emacs.

PS. The same happens on my Linux machine.

fujiisat commented 2 months ago

Maybe (defalias 'sp--syntax-class-to-char 'syntax-class-to-char) is evaluated only on compile time in smartparens.el. Use eval-and-compile instad of eval-when-compile.

fpotargent commented 2 months ago

Not really wrong syntax but the problem is the separate function namespace of (emacs) lisp. A quick fix is

(defalias 'sp--syntax-class-to-char #'syntax-class-to-char)

Quoting using #' references the syntax-class-to-char symbol in the function namespace.

Note: the documentation of syntax-class-to-char (in emacs 29.2) says the function was probably introduced in emacs 28.1 or before. So it may be more robust to check if the function exists or not instead of relying on the version. Something like

(eval-when-compile
  (unless (fboundp 'syntax-class-to-char)
    (defun syntax-class-to-char (syntax)
       ...)

This defines the function when it doesn't exists, so the defalias or other changes are not necessary.

zyxir commented 2 months ago

I'm not sure if it is wrong syntax, just pointed to the code for @zyxir.

Thanks bro. I don't know if it is the right place to complain, but Smartparens lacking a stable branch or a stable tag is a bit troublesome for me sometimes. The last versioned tag (1.11.0), which was updated in 2017, and is available in Melpa-stable and Nongu-ELPA, is a little outdated for me. The temporary solution for me now is to always pin Smartparens at a specific commit, like Doom Emacs does.

Fuco1 commented 2 months ago

@zyxir agreed, I need to start producing some stable releases again, sorry about that.

@fpotargent Excellent points, I will include your solution in a patch, will be out in 2 hours

zyxir commented 2 months ago

@zyxir agreed, I need to start producing some stable releases again, sorry about that.

It's just a very minor inconvenience. Smartparens is overall a great package that has saved countless time for me and other users. Thank you for your great work!

Fuco1 commented 2 months ago

I merged a patch by @juergenhoetzel, that should fix the issue.

practicalli-johnny commented 2 months ago

Thank you @Fuco1 for the quick resolution. SmartParens is working very well again.

Thank you for all the work you put into this project, it is greatly appreciated.