auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] fix delete-property handling


From: Artem Yurchenko
Subject: Re: [PATCH] fix delete-property handling
Date: Wed, 10 Apr 2024 23:52:34 -0400
User-agent: Zoho Mail

Hi, Ikumi,

>On the other hand, I'm afraid another incompatibility, due to refactoring
>of the electric logic of `TeX-insert-dollar', can be bad. Suppose that
>`TeX-electric-math' is "$...$" or "\(...\)" and
>`TeX-refuse-unmatched-dollar' is t. Then the current `TeX-insert-dollar'
>refuses to insert anything if the point is in math-mode which doesn't
>begin with "$" nor "$$".
>However, after your patch is applied, it just shows ordinary electric
>behavior; it inserts pair of "$...$" or "\(...\)".
>I'm not sure how this feature is important; maybe very few users concern
>about it. But I ask you to try to keep the compatibility first. If it is
>extremely difficult, let's discuss what to do.

It is not extremely difficult to keep that feature, and I have already
written a patch to do it. However, if we apply it when electricity is on,
this option seems somewhat misleadingly named and documented and
doesn't make sense IMO.

First, the name (and the doc) say that the option controls the insert
of a /dollar/ sign. Thus, if the TeX-electric-math is not a dollar, then
technically, this option shouldn't apply? That seems somewhat
inconsistent, because the reasoning behind the option is the same for
any math delimiter: «nested» math mode is invalid.

Now, suppose that the user sets TeX-electric-math to dollars. Then,
that option is not going to be applicable in many cases, as the user
is likely using «$» and «$$» as math delimiters. There are however
other environments, «equation», «align» etc where this option
works. There are also environments where this option breaks, which is
why this behaviour was made optional in the first place.

Suppose that the user sets TeX-electric-math to non-nil, and not
dollars. Then, this option is not going to be applicable at all, as
the dollar key never inserts a dollar. In fact, the very name
«unmatched-dollar» no longer makes sense, because we are automatically
inserting two matching delimiters which are not dollars.

So, the options I see are:

1. Extend semantics of TeX-refuse-unmatched-dollar to other
delimiters, change the documentation, possibly change the name, create
the deprecated alias with the old name.

2. Keep semantics and docs of TeX-refuse-unmatched-dollar, but confine
to when electricity is off.

I'm fine with anything and open to other suggestions.

>> +(TeX--put-electric-delete-selection
>> + #'TeX-newline (lambda () nil))
>Is it right to inherit `delete-selection' property from
>`self-insert-command' for the command associated with RET key? I'm not
>familiar with delete selection mode, so I cannot tell.
>(By the way, (lambda () nil) can just be #'ignore .)

The rightest way would be to inherit the delete-selection of the
appropriate newline function chosen. At this moment, they all just t,
so to avoid complications I changed the delete-selection to just use
t.

>> +(defun TeX-insert-dollar-electric-p ()
>> + "Non-nil if `TeX-insert-dollar' should use the electric behaviour."
>This doc string looks like to explain a variable because it starts with
>"Non-nil if...". A doc string for a function should tell what this
>function does.
>
>> +(defun TeX-insert-dollar-electric-p ()
>> + "Non-nil if `TeX-insert-dollar' should use the electric behaviour."
>> + (and (not current-prefix-arg)
>> + (not (TeX-escaped-p))
>> + (not (TeX-verbatim-p))
>> + TeX-electric-math))
>It would be slightly efficient if it refers to `TeX-electric-math'
>before evaluation of `TeX-escaped-p' and `TeX-verbatim-p'.
>
>> +When ARG is given, insert a literal `$' ARG times. E.g., if you
>The elisp reference node "(elisp) Documentation Tips" directs not to use
>single quotes in the doc string in that way:
>,----
>| • In documentation strings, do not quote expressions that are not
>| Lisp symbols, as these expressions can stand for themselves. For
>| example, write ‘Return the list (NAME TYPE RANGE) ...’ instead of
>| ‘Return the list `(NAME TYPE RANGE)' ...’ or ‘Return the list
>| \\='(NAME TYPE RANGE) ...’.
>`----
>In addition, the same node discourages to use "e.g." in the doc string:
>,----
>| • Try to avoid using abbreviations such as “e.g.” (for “for
>| example”), “i.e.” (for “that is”), “no.” (for “number”), “cf.” (for
>| “compare”/“see also”) and “w.r.t.” (for “with respect to”) as much
>| as possible. It is almost always clearer and easier to read the
>| expanded version.(1)
>`----
>> +Otherwise, when in a verbatim or an escaped (with `\\')
>> +environment, insert one literal `$'.
>The term "environment" is ambiguous in this context because it's
>difficult to distinguish from "LaTeX environment". How about
>Otherwise, when in a verbatim construct or escaped with \"\\\",...
>instead?

Fixed.

>> +(TeX--put-electric-delete-selection
>> + #'TeX-insert-dollar TeX-insert-dollar-electric-p)
>The second argument must be quoted.

Oh no, I must have forgotten to eval when testing. Fixed.

I'm attaching a patch with fixes. I've also removed the deprecated
symbol warning, as it has been there since 2012.

The blinking probably should also be removed due to being very
inconsistent. Or fixed, if worth it.

Best,
Artem



---- On Wed, 10 Apr 2024 06:35:44 -0400 Ikumi Keita <ikumi@ikumi.que.jp> wrote ---

Hi Artem,

> This is my first time contributing and I expect to have made mistakes. I am willing to react to comments and fix any deficiencies.

Commentaries on the second patch follow.

I think the two incompatibilities discussed there are permissible:
(1) The special case where
> If [[`TeX-electric-math']] non-nil and point is inside math ...
(2) We've changed `C-u $' to insert four dollars as opposed to one.

They are reasonable and we can announce work arounds for them.

On the other hand, I'm afraid another incompatibility, due to refactoring
of the electric logic of `TeX-insert-dollar', can be bad. Suppose that
`TeX-electric-math' is "$...$" or "\(...\)" and
`TeX-refuse-unmatched-dollar' is t. Then the current `TeX-insert-dollar'
refuses to insert anything if the point is in math-mode which doesn't
begin with "$" nor "$$".
However, after your patch is applied, it just shows ordinary electric
behavior; it inserts pair of "$...$" or "\(...\)".
I'm not sure how this feature is important; maybe very few users concern
about it. But I ask you to try to keep the compatibility first. If it is
extremely difficult, let's discuss what to do.

> +(TeX--put-electric-delete-selection
> + #'TeX-newline (lambda () nil))
Is it right to inherit `delete-selection' property from
`self-insert-command' for the command associated with RET key? I'm not
familiar with delete selection mode, so I cannot tell.
(By the way, (lambda () nil) can just be #'ignore .)

> +(defun TeX-insert-dollar-electric-p ()
> + "Non-nil if `TeX-insert-dollar' should use the electric behaviour."
This doc string looks like to explain a variable because it starts with
"Non-nil if...". A doc string for a function should tell what this
function does.

> +(defun TeX-insert-dollar-electric-p ()
> + "Non-nil if `TeX-insert-dollar' should use the electric behaviour."
> + (and (not current-prefix-arg)
> + (not (TeX-escaped-p))
> + (not (TeX-verbatim-p))
> + TeX-electric-math))
It would be slightly efficient if it refers to `TeX-electric-math'
before evaluation of `TeX-escaped-p' and `TeX-verbatim-p'.

> +When ARG is given, insert a literal `$' ARG times. E.g., if you
The elisp reference node "(elisp) Documentation Tips" directs not to use
single quotes in the doc string in that way:
,----
| • In documentation strings, do not quote expressions that are not
| Lisp symbols, as these expressions can stand for themselves. For
| example, write ‘Return the list (NAME TYPE RANGE) ...’ instead of
| ‘Return the list `(NAME TYPE RANGE)' ...’ or ‘Return the list
| \\='(NAME TYPE RANGE) ...’.
`----
In addition, the same node discourages to use "e.g." in the doc string:
,----
| • Try to avoid using abbreviations such as “e.g.” (for “for
| example”), “i.e.” (for “that is”), “no.” (for “number”), “cf.” (for
| “compare”/“see also”) and “w.r.t.” (for “with respect to”) as much
| as possible. It is almost always clearer and easier to read the
| expanded version.(1)
`----

> +Otherwise, when in a verbatim or an escaped (with `\\')
> +environment, insert one literal `$'.
The term "environment" is ambiguous in this context because it's
difficult to distinguish from "LaTeX environment". How about
Otherwise, when in a verbatim construct or escaped with \"\\\",...
instead?

> +(TeX--put-electric-delete-selection
> + #'TeX-insert-dollar TeX-insert-dollar-electric-p)
The second argument must be quoted.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW


Attachment: 0004-fixup-amend-TeX-electric-commands-to-allow-alternati.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]