Hi Peter,

MATLAB's use of ' char for strings is a bit tricky, because it has many
meanings, such as:
  *  'this is a string'
  * 'in a string '' first quote is escape for second quote'
  * this is a transpose'

I'm not sure when the electric pair mode does it's thing, but if it tries
to pair up a ' when you type it, but then later the matlab-mode scanner
re-attributes it as punctuation (because it is transpose) or escape
(because it is doubled up) I can imagine some confusion.

As such, matlab-mode has special support for paren-mode.  I might recommend
turning off electric-pair-mode in matlab-mode, and turning on paren-mode
instead.  I know it isn't the same, but as I scan through elec-pair.el, I
don't see much opportunity for matlab-mode to customize it for the special
syntax features.

It may be possible that setting `electric-pair-string-bound-function' to
'point-at-eol' in MATLAB buffers might help, since strings can't extend
past one line, but I suspect the real problem is in the timing of the
insert action since elec-pair uses edit hooks, and matlab fixes the syntax
during a syntax-ppss call (ie - during font lock, or navigation keypress)

Maybe someone else on the list knows other ways to customize elec-pair can
offer a suggestion.   cc-mode does similar stuff with syntax-propertize,
and must have some fixes for elec-pair.

Eric

On Sat, Apr 23, 2022 at 3:33 PM Peter Mao <peter....@gmail.com> wrote:

> note: I formatted this email in markdown for readability (let me know if
> there's a better way).
>
> I use **electric-pair-mode**.  If you don't you can turn it on locally with
> ```
> (electric-pair-local-mode t)
> ```
> to see what the issue is.
>
> Briefly, with **electric-pair-mode** on (locally or globally), If I type
> the characters `(abc)def`, I get the same output.  The characters that pair
> are the ones in the syntax table (use `describe-syntax' to see it) that are
> of type "open", "close", or "string".
>
> In **matlab-mode**, the pairs (), [], {} (all "open"/"close" type) work
> fine, as does the "string" type delimiter " (aka, double-quote, #x22, ?")
> because it is listed in the variable `electric-pair-pairs`.  The only one
> that does NOT work is the "string" type delimiter ' (aka, single-quote,
> #x27, ?').  So with the `(abc)def` example above, with #x27, I get:
> ```
> 'abc'def'
> ```
> Note the single-quote at the end of the output string after the `f`.
>
> With some exploration of other modes, I have found that **perl-mode** also
> uses #x27 as a string delimiter in its syntax table, but it gives the
> correct output with my test input string.
>
> I will look into this, but if someone else with more experience coding
> syntax handling gets to it before me, that would be wonderful.
>
> thanks,
>
> Peter
> _______________________________________________
> Matlab-emacs-discuss mailing list
> Matlab-emacs-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
>
_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss

Reply via email to