hi Eric and John,

Thanks for your responses.  Eric -- did you mean `show-paren-mode`?  I
can't find any references to a `paren-mode` in melpa, elpa or emacs
(28.1).  I'll try it out if I can find it!

I'm on the latest matlab-emacs, which include the commit John mentions, but
the only way past the last single-quote is C-f or right-arrow.  In my
common usage of coding m scripts, I'm more often tweaking labels on plots
(and hence string) than transposing matrices.

I may add #x27 to `electric-pair-pairs` and see if that reduces my overall
"minor annoyance level."

Peter

On Mon, Apr 25, 2022 at 8:33 AM John Ciolfi <cio...@mathworks.com> wrote:

> There was a recent fix to the syntax class for the single quote,
> https://sourceforge.net/p/matlab-emacs/src/ci/a5e88cda8e0715f117f09e6101f39302387f2d6b/
>
> I'm not familiar with electric pair mode but tried it and it seems to work
> for the case you mentioned. Some downsides I noticed with it was (2) trying
> to transpose a variable, typing a single quote at end of variable results
> in two single quotes and you need to delete (C-d) the extra single quote.
> (2) If you try to escape a quote in a string, it adds an extra quote.
>
>
> John
> ------------------------------
> *From:* Eric Ludlam <ericlud...@gmail.com>
> *Sent:* Monday, April 25, 2022 10:11 AM
> *To:* Peter Mao <peter....@gmail.com>
> *Cc:* matlab-emacs-discuss <matlab-emacs-discuss@lists.sourceforge.net>
> *Subject:* Re: [Matlab-emacs-discuss] matlab-mode, electric-pair-mode and
> the single quote (')
>
> 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