smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

how to make slurp/barf work with some math operators like = + - * / in auctex mode?

Open ghost opened this issue 9 years ago • 4 comments

Hello,

When doing slurp/barf sexp in the auctex mode, how can I make smartparens recognize some math operators like = + - * / in auctex mode?

For examples, given the text a{|}=b, where | indicates the cursor position, how can I make the slurp-sexp feature obtain a{=}b?

The current result that I can obtain is a{=b}.

ghost avatar Feb 01 '17 07:02 ghost

The simplest is to put space between = and b. Unfortunatelly, = has "symbol" syntax and so Emacs thinks that =b forms a "symbol" (a glorified word of sorts).

You can try to change the syntax classes around a bit, but usually major-mode authors set them to certain values and then rely on that when parsing expressions. Smartparens assumes "they" do the correct thing and so we don't try to override the syntax codes (unless in extreme circumstances).

You can also write a special hook and attach it to the slurp/barf actions and then adjust the outcome manually, but that is a bit more involved (it is described on the wiki).

I'm afraid this would be a wontfix from our side, but I'm happy to assist you if you chose to write your own solution.

Fuco1 avatar Feb 01 '17 10:02 Fuco1

Thanks for the prompt feedback. Writing a hook to check for the special cases will be great, I will try to write it in my spare time.

Btw, I'm trying to do a quick fix by modifying the syntax table of auctex to change the = symbol to be the punctuation symbol. Below is the code:

(dolist (symbol (list ?+ ?- ?= ?* ?/))
      (progn
        (modify-syntax-entry symbol "." tex-mode-syntax-table)
        (modify-syntax-entry symbol "." latex-mode-syntax-table)
        (modify-syntax-entry symbol "." LaTeX-mode-syntax-table)))

However, when doing slurp-sexp with this text a{|}=b, where | is the cursor position, smartparens exchanges the position of = and b. Here is the result that I observed: a{b}=

Is this a bug or an expected behaviour of smartparens?

ghost avatar Feb 01 '17 17:02 ghost

Oh yes... this is another funny thing with syntax. Because it is punctuation, it travels with the token. Imagine a , or ;, usually you want to move it forward if you extend code blocks or extend parens.

Check the sp-sexp-suffix setting. Something like (add-to-list 'sp-sexp-suffix (list 'latex-mode 'regexp "")) should work. (see smartparens-python.el for inspiration).

Fuco1 avatar Feb 01 '17 17:02 Fuco1

I tried your suggested solution but then the punctuation symbols are treated as normal symbols like described in my first post. Indeed, it's really complicated when playing with the syntax.

ghost avatar Feb 01 '17 17:02 ghost