Re: The auto-completion behavior of parenthesis.

2023-07-30 Thread Hongyi Zhao
On Sun, Jul 30, 2023 at 3:40 PM Tassilo Horn  wrote:
>
> Hongyi Zhao  writes:
>
> > 1. You said:
> >
> > "emacs -Q" session resulted in built-in latex mode
> >
> > Yes. This is true in all my testings.
> >
> > After the above step 1, I observed the following behavior:
> >
> > 2. If AUCTeX hasn't installed by `package-install', after I installed
> > it by `package-install' and open a .tex file, then AUCTeX LaTeX mode
> > will be enabled automatically.
> >
> > 3. If AUCTeX has already installed by `package-install', after I
> > re-installed it by `package-reinstall' and open a .tex file, then
> > *still* AUCTeX LaTeX mode will be enabled automatically.
> >
> > 4. If AUCTeX has already installed by `package-install', and I open a
> > .tex file immediately without reinstall AUCTeX, then AUCTeX LaTeX mode
> > will *not* be enabled automatically and the built-in latex mode still
> > will be effective for the opened tex buffer.
>
> If the auctex ELPA package is already installed but you started with
> emacs -Q, you can simply do M-x package-initialize RET to activate all
> installed packages or, even better for debugging purposes, do
>
>   M-: (progn (package-initialize t) (package-activate 'auctex)) RET
>
> to only activate auctex and no other package.  Then you are running as
> if you had no site config, no personal config, and no package except
> auctex installed.

Very helpful! Thanks a lot for the tip. It does the trick.

> Bye,
> Tassilo

Regards,
Zhao



Re: The auto-completion behavior of parenthesis.

2023-07-30 Thread Tassilo Horn
Hongyi Zhao  writes:

> 1. You said:
>
> "emacs -Q" session resulted in built-in latex mode
>
> Yes. This is true in all my testings.
>
> After the above step 1, I observed the following behavior:
>
> 2. If AUCTeX hasn't installed by `package-install', after I installed
> it by `package-install' and open a .tex file, then AUCTeX LaTeX mode
> will be enabled automatically.
>
> 3. If AUCTeX has already installed by `package-install', after I
> re-installed it by `package-reinstall' and open a .tex file, then
> *still* AUCTeX LaTeX mode will be enabled automatically.
>
> 4. If AUCTeX has already installed by `package-install', and I open a
> .tex file immediately without reinstall AUCTeX, then AUCTeX LaTeX mode
> will *not* be enabled automatically and the built-in latex mode still
> will be effective for the opened tex buffer.

If the auctex ELPA package is already installed but you started with
emacs -Q, you can simply do M-x package-initialize RET to activate all
installed packages or, even better for debugging purposes, do

  M-: (progn (package-initialize t) (package-activate 'auctex)) RET

to only activate auctex and no other package.  Then you are running as
if you had no site config, no personal config, and no package except
auctex installed.

Bye,
Tassilo



Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Hongyi Zhao
On Sat, Jul 29, 2023 at 11:53 AM Ikumi Keita  wrote:
>
> Hi Hongyi,
>
> > Hongyi Zhao  writes:
> > On Sat, Jul 29, 2023 at 12:03 AM Ikumi Keita  wrote:
> >>
> >> > Hongyi Zhao  writes:
> >> > I see, due to auctex has already been installed, I must test it as 
> >> > follows:
> >>
> >> > emacs -Q
> >> > M-x package-reinstall RET auctex RET
> >>
> >> > Open a tex file, and `M-: (setq LaTeX-electric-left-right-brace t) RET'
> >>
> >> > Then test the problem discussed here.
> >>
> >> > See the attached screenshot for the results.
> >>
> >> What's wrong? It seems to me that it works as you expected. The round
> >> parens appear in pair in the screenshot.
>
> > You've said:
>
> > Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
> > built-in latex mode due to '-Q' option.
>
>
> > But I've confirmed that the buffer is really in AUCTeX latex mode, as
> > indicated by the AUCTeX menu bars and the following info given by `C-h
> > v major-mode RET`:
>
> Sorry, I still don't see your points. If I understand correctly,
> 1. Previously, "emacs -Q" session resulted in built-in latex mode and
>`LaTeX-electric-left-right-brace' wasn't effective. You typed "(" but
>emacs didn't complete it to "()".
> 2. Now you have enabled AUCTeX latex mode even in "emacs -Q" session and
>AUCTeX responds to `LaTeX-electric-left-right-brace'. You typed "("
>and got "()" as expected.
> Then what's wrong?

Let me comments and explains step-by-step:

1. You said:

"emacs -Q" session resulted in built-in latex mode

Yes. This is true in all my testings.

After the above step 1, I observed the following behavior:

2. If AUCTeX hasn't installed by `package-install', after I installed
it by `package-install' and open a .tex file, then AUCTeX LaTeX mode
will be enabled automatically.

3. If AUCTeX has already installed by `package-install', after I
re-installed it by `package-reinstall' and open a .tex file, then
*still* AUCTeX LaTeX mode will be enabled automatically.

4. If AUCTeX has already installed by `package-install', and I open a
.tex file immediately without reinstall AUCTeX, then AUCTeX LaTeX mode
will *not* be enabled automatically and the built-in latex mode still
will be effective for the opened tex buffer.


This is why it is necessary to test it using the following commands to
ensure that the latest version of AUCTeX is freshly installed for the
current Emacs session initiated by `emacs -Q'.

M-x package-refresh-contents RET
M-x package-reinstall RET auctex RET

> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine

Best,
Zhao



Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Ikumi Keita
Hi Hongyi,

> Hongyi Zhao  writes:
> On Sat, Jul 29, 2023 at 12:03 AM Ikumi Keita  wrote:
>> 
>> > Hongyi Zhao  writes:
>> > I see, due to auctex has already been installed, I must test it as follows:
>> 
>> > emacs -Q
>> > M-x package-reinstall RET auctex RET
>> 
>> > Open a tex file, and `M-: (setq LaTeX-electric-left-right-brace t) RET'
>> 
>> > Then test the problem discussed here.
>> 
>> > See the attached screenshot for the results.
>> 
>> What's wrong? It seems to me that it works as you expected. The round
>> parens appear in pair in the screenshot.

> You've said:

> Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
> built-in latex mode due to '-Q' option.


> But I've confirmed that the buffer is really in AUCTeX latex mode, as
> indicated by the AUCTeX menu bars and the following info given by `C-h
> v major-mode RET`:

Sorry, I still don't see your points. If I understand correctly,
1. Previously, "emacs -Q" session resulted in built-in latex mode and
   `LaTeX-electric-left-right-brace' wasn't effective. You typed "(" but
   emacs didn't complete it to "()".
2. Now you have enabled AUCTeX latex mode even in "emacs -Q" session and
   AUCTeX responds to `LaTeX-electric-left-right-brace'. You typed "("
   and got "()" as expected.
Then what's wrong?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Hongyi Zhao
On Sat, Jul 29, 2023 at 12:03 AM Ikumi Keita  wrote:
>
> > Hongyi Zhao  writes:
> > I see, due to auctex has already been installed, I must test it as follows:
>
> > emacs -Q
> > M-x package-reinstall RET auctex RET
>
> > Open a tex file, and `M-: (setq LaTeX-electric-left-right-brace t) RET'
>
> > Then test the problem discussed here.
>
> > See the attached screenshot for the results.
>
> What's wrong? It seems to me that it works as you expected. The round
> parens appear in pair in the screenshot.

You've said:

Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
built-in latex mode due to '-Q' option.


But I've confirmed that the buffer is really in AUCTeX latex mode, as
indicated by the AUCTeX menu bars and the following info given by `C-h
v major-mode RET`:

latex-mode is an autoloaded interactive byte-compiled Lisp function in
‘tex-mode.el’.

(latex-mode)

This function has :override advice: ‘TeX-latex-mode’.

This is an :override advice, which means that ‘latex-mode’ isn’t
run at all, and the documentation below may be irrelevant.

;;; Hit on ‘TeX-latex-mode’, I'll see the following:

TeX-latex-mode is an autoloaded interactive byte-compiled Lisp
function in ‘latex.el’.

(TeX-latex-mode)

Major mode in AUCTeX for editing LaTeX files.
See info under AUCTeX for full documentation.

> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine

Best,
Zhao



Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Ikumi Keita
> Hongyi Zhao  writes:
> I see, due to auctex has already been installed, I must test it as follows:

> emacs -Q
> M-x package-reinstall RET auctex RET

> Open a tex file, and `M-: (setq LaTeX-electric-left-right-brace t) RET'

> Then test the problem discussed here.

> See the attached screenshot for the results.

What's wrong? It seems to me that it works as you expected. The round
parens appear in pair in the screenshot.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Hongyi Zhao
On Fri, Jul 28, 2023 at 2:43 PM Ikumi Keita  wrote:
>
> Hi,
>
> > Hongyi Zhao  writes:
> > After starting with 'emacs -Q', I tried to do the above test with the
> > guidance here [1] to install auctex:
>
> > M-x package-install RET auctex RET
>
> > But I meet the following:
>
> > Install package: auctex RET
>
> > no match
>
> I think that your local elpa database wasn't updated when you tried it
> and emacs tries to install older version of AUCTeX, which no longer
> existed on the elpa server.
>
> >> Hongyi Zhao  writes:
>
> > Any then, I use a minimal tex file:
>
> > \documentclass{article}
> > \begin{document}
> > Hello world.
> > \end{document}
>
> > After opening the above file, eval the following setting:
>
> > M-: (setq LaTeX-electric-left-right-brace t) RET
>
> > Then, I observed the same effect as shown be you.
>
> Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
> built-in latex mode due to '-Q' option.

`C-h v major-mode RET' gives the following:

--- begin buffer ---
major-mode is a variable defined in ‘C source code’.

Its value is ‘latex-mode’
Original value was ‘fundamental-mode’
Local in buffer test.tex; global value is fundamental-mode

Symbol for current buffer’s major mode.
The default value (normally ‘fundamental-mode’) affects new buffers.
A value of nil means to use the current buffer’s major mode, provided
it is not marked as "special".

  Automatically becomes buffer-local when set.
  You can customize this variable.
  Probably introduced at or before Emacs version 29.1.

[back]
--- end buffer ---

See the attached screenshot for more details.

> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine

Best,
Zhao


Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Hongyi Zhao
On Fri, Jul 28, 2023 at 3:43 PM Hongyi Zhao  wrote:
>
> On Fri, Jul 28, 2023 at 2:43 PM Ikumi Keita  wrote:
> >
> > Hi,
> >
> > > Hongyi Zhao  writes:
> > > After starting with 'emacs -Q', I tried to do the above test with the
> > > guidance here [1] to install auctex:
> >
> > > M-x package-install RET auctex RET
> >
> > > But I meet the following:
> >
> > > Install package: auctex RET
> >
> > > no match
> >
> > I think that your local elpa database wasn't updated when you tried it
> > and emacs tries to install older version of AUCTeX, which no longer
> > existed on the elpa server.
>
> I tried with `M-x package-refresh-contents' but still meet the same problem.
>
> And I also tried with `M-x package-list-packages` and find that auctex
> already installed as shown in the attachment.
>
> > >> Hongyi Zhao  writes:
> >
> > > Any then, I use a minimal tex file:
> >
> > > \documentclass{article}
> > > \begin{document}
> > > Hello world.
> > > \end{document}
> >
> > > After opening the above file, eval the following setting:
> >
> > > M-: (setq LaTeX-electric-left-right-brace t) RET
> >
> > > Then, I observed the same effect as shown be you.
> >
> > Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
> > built-in latex mode due to '-Q' option.
>
> See the attached screenshot. But this time, all test fails.

I see, due to auctex has already been installed, I must test it as follows:

emacs -Q
M-x package-reinstall RET auctex RET

Open a tex file, and `M-: (setq LaTeX-electric-left-right-brace t) RET'

Then test the problem discussed here.

See the attached screenshot for the results.

> > Regards,
> > Ikumi Keita
> > #StandWithUkraine #StopWarInUkraine
>
> Best,
> Zhao


Re: The auto-completion behavior of parenthesis.

2023-07-28 Thread Ikumi Keita
Hi,

> Hongyi Zhao  writes:
> After starting with 'emacs -Q', I tried to do the above test with the
> guidance here [1] to install auctex:

> M-x package-install RET auctex RET

> But I meet the following:

> Install package: auctex RET

> no match

I think that your local elpa database wasn't updated when you tried it
and emacs tries to install older version of AUCTeX, which no longer
existed on the elpa server.

>> Hongyi Zhao  writes:

> Any then, I use a minimal tex file:

> \documentclass{article}
> \begin{document}
> Hello world.
> \end{document}

> After opening the above file, eval the following setting:

> M-: (setq LaTeX-electric-left-right-brace t) RET

> Then, I observed the same effect as shown be you.

Is that buffer in AUCTeX latex mode? I suspect that it's in emacs
built-in latex mode due to '-Q' option.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread Hongyi Zhao
On Fri, Jul 28, 2023 at 2:36 AM Arash Esbati  wrote:
>
> Hongyi Zhao  writes:
>
> > Very strange. I've enabled this option, as shown below:
> >
> > [ C-h v LaTeX-electric-left-right-brace RET ]
> > LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
> >
> > Its value is t
> > Original value was nil
> >
> > If non-nil, insert right brace with suitable macro after typing left brace.
> >
> >   You can customize this variable.
> >
> > [back]
> >
> > But I still cannot observe the corresponding completion of the
> > innermost `(' as shown in the attached screenshot.
>
> Again, I can only suggest that you try this starting with 'emacs -Q'.  I
> did this, activated AUCTeX for my installation, setq'ed
> `LaTeX-electric-left-right-brace' to t, opened a minimal .tex file, hit
> '{[(' and the result in the buffer looks like this:
>
>   {[(*)]}
>
> with * indicating the position of point.

After starting with 'emacs -Q', I tried to do the above test with the
guidance here [1] to install auctex:

M-x package-install RET auctex RET

But I meet the following:

Install package: auctex RET

no match

OTOH, the following method works as described here [2]:

1.2 Installing AUCTeX

The modern and strongly recommended way of installing AUCTeX is by
using the Emacs package manager integrated in Emacs 24 and greater
(ELPA). Simply do M-x list-packages , mark the auctex package for
installation with i, and hit x to execute the installation procedure.
That’s all.

Any then, I use a minimal tex file:

\documentclass{article}
\begin{document}
Hello world.
\end{document}

After opening the above file, eval the following setting:

M-: (setq LaTeX-electric-left-right-brace t) RET

Then, I observed the same effect as shown be you.

[1] https://elpa.gnu.org/packages/auctex.html
[2] https://www.gnu.org/software/auctex/manual/auctex.html#Installation

> Best, Arash

Regards,
Zhao



Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread Hongyi Zhao
On Fri, Jul 28, 2023 at 12:23 PM Hongyi Zhao  wrote:
>
> On Fri, Jul 28, 2023 at 2:36 AM Arash Esbati  wrote:
> >
> > Hongyi Zhao  writes:
> >
> > > Very strange. I've enabled this option, as shown below:
> > >
> > > [ C-h v LaTeX-electric-left-right-brace RET ]
> > > LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
> > >
> > > Its value is t
> > > Original value was nil
> > >
> > > If non-nil, insert right brace with suitable macro after typing left 
> > > brace.
> > >
> > >   You can customize this variable.
> > >
> > > [back]
> > >
> > > But I still cannot observe the corresponding completion of the
> > > innermost `(' as shown in the attached screenshot.
> >
> > Again, I can only suggest that you try this starting with 'emacs -Q'.  I
> > did this, activated AUCTeX for my installation, setq'ed
> > `LaTeX-electric-left-right-brace' to t, opened a minimal .tex file, hit
> > '{[(' and the result in the buffer looks like this:
> >
> >   {[(*)]}
> >
> > with * indicating the position of point.
>
> After starting with 'emacs -Q', I tried to do the above test with the
> guidance here [1] to install auctex:
>
> M-x package-install RET auctex RET
>
> But I meet the following:
>
> Install package: auctex RET
>
> no match
>
> OTOH, the following method works as described here [2]:
>
> 1.2 Installing AUCTeX
>
> The modern and strongly recommended way of installing AUCTeX is by
> using the Emacs package manager integrated in Emacs 24 and greater
> (ELPA). Simply do M-x list-packages , mark the auctex package for
> installation with i, and hit x to execute the installation procedure.
> That’s all.
>
> Any then, I use a minimal tex file:
>
> \documentclass{article}
> \begin{document}
> Hello world.
> \end{document}
>
> After opening the above file, eval the following setting:
>
> M-: (setq LaTeX-electric-left-right-brace t) RET
>
> Then, I observed the same effect as shown be you.

So, it is obvious that there must be some conflicts in my actual
configuration, which led to incorrect test results reported earlier.

> [1] https://elpa.gnu.org/packages/auctex.html
> [2] https://www.gnu.org/software/auctex/manual/auctex.html#Installation
>
> > Best, Arash
>
> Regards,
> Zhao



Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread Arash Esbati
Hongyi Zhao  writes:

> Very strange. I've enabled this option, as shown below:
>
> [ C-h v LaTeX-electric-left-right-brace RET ]
> LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
>
> Its value is t
> Original value was nil
>
> If non-nil, insert right brace with suitable macro after typing left brace.
>
>   You can customize this variable.
>
> [back]
>
> But I still cannot observe the corresponding completion of the
> innermost `(' as shown in the attached screenshot.

Again, I can only suggest that you try this starting with 'emacs -Q'.  I
did this, activated AUCTeX for my installation, setq'ed
`LaTeX-electric-left-right-brace' to t, opened a minimal .tex file, hit
'{[(' and the result in the buffer looks like this:

  {[(*)]}

with * indicating the position of point.

Best, Arash



Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread David Kastrup
Hongyi Zhao  writes:

> On Thu, Jul 27, 2023 at 10:05 PM Arash Esbati  wrote:
>>
>> Hongyi Zhao  writes:
>>
>> > In AUCTeX mode, I noticed that `{', and `[' can be completed
>> > automatically, while `(' doesn't. Any tips for this behavior?
>>
>> AUCTeX provides a variable called `LaTeX-electric-left-right-brace' for
>> this purpose which is initally disabled:
>>
>> ,[ C-h v LaTeX-electric-left-right-brace RET ]
>> | LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
>> |
>> | Its value is t
>> | Original value was nil
>> |
>> | If non-nil, insert right brace with suitable macro after typing left brace.
>> |
>> |   You can customize this variable.
>> |
>> `
>>
>> See also here[1] for more information.
>
> Very strange. I've enabled this option, as shown below:
>
> [ C-h v LaTeX-electric-left-right-brace RET ]
> LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
>
> Its value is t
> Original value was nil
>
> If non-nil, insert right brace with suitable macro after typing left brace.
>
>   You can customize this variable.
>
> [back]
>
> But I still cannot observe the corresponding completion of the
> innermost `(' as shown in the attached screenshot.

This is a terminology misunderstanding.

() parentheses
[] brackets
{} braces

You want completion for parentheses, not braces.  Parentheses are not
syntactic entities in LaTeX (pstricks notwithstanding).  You may want to
look at the generic key sequence:

M-( runs the command insert-parentheses (found in global-map), which
is an interactive byte-compiled Lisp function in ‘lisp.el’.

It is bound to M-(.

(insert-parentheses  ARG)

Enclose following ARG sexps in parentheses.
Leave point after open-paren.
A negative ARG encloses the preceding ARG sexps instead.
No argument is equivalent to zero: just insert ‘()’ and leave point between.
If ‘parens-require-spaces’ is non-nil, this command also inserts a space
before and after, depending on the surrounding characters.
If region is active, insert enclosing characters at region boundaries.

This command assumes point is not in a string or comment.

-- 
David Kastrup



Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread Hongyi Zhao
On Thu, Jul 27, 2023 at 10:05 PM Arash Esbati  wrote:
>
> Hongyi Zhao  writes:
>
> > In AUCTeX mode, I noticed that `{', and `[' can be completed
> > automatically, while `(' doesn't. Any tips for this behavior?
>
> AUCTeX provides a variable called `LaTeX-electric-left-right-brace' for
> this purpose which is initally disabled:
>
> ,[ C-h v LaTeX-electric-left-right-brace RET ]
> | LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
> |
> | Its value is t
> | Original value was nil
> |
> | If non-nil, insert right brace with suitable macro after typing left brace.
> |
> |   You can customize this variable.
> |
> `
>
> See also here[1] for more information.

Very strange. I've enabled this option, as shown below:

[ C-h v LaTeX-electric-left-right-brace RET ]
LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.

Its value is t
Original value was nil

If non-nil, insert right brace with suitable macro after typing left brace.

  You can customize this variable.

[back]

But I still cannot observe the corresponding completion of the
innermost `(' as shown in the attached screenshot.

>
> Best, Arash
>
> Footnotes:
> [1]  
> https://www.gnu.org/software/auctex/manual/auctex/Quotes.html#index-LaTeX_002delectric_002dleft_002dright_002dbrace

Regards,
Zhao


Re: The auto-completion behavior of parenthesis.

2023-07-27 Thread Arash Esbati
Hongyi Zhao  writes:

> In AUCTeX mode, I noticed that `{', and `[' can be completed
> automatically, while `(' doesn't. Any tips for this behavior?

AUCTeX provides a variable called `LaTeX-electric-left-right-brace' for
this purpose which is initally disabled:

,[ C-h v LaTeX-electric-left-right-brace RET ]
| LaTeX-electric-left-right-brace is a variable defined in ‘latex.el’.
| 
| Its value is t
| Original value was nil
| 
| If non-nil, insert right brace with suitable macro after typing left brace.
| 
|   You can customize this variable.
| 
`

See also here[1] for more information.

Best, Arash

Footnotes:
[1]  
https://www.gnu.org/software/auctex/manual/auctex/Quotes.html#index-LaTeX_002delectric_002dleft_002dright_002dbrace



The auto-completion behavior of parenthesis.

2023-07-22 Thread Hongyi Zhao
Hi here,

In AUCTeX mode, I noticed that `{', and `[' can be completed
automatically, while `(' doesn't. Any tips for this behavior?

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao 
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province