GNU bug report logs -
#71777
29.4; sexp-at-point in latex-mode when sexp contains ";"
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 71777 in the body.
You can then email your comments to 71777 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Tue, 25 Jun 2024 20:41:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 25 Jun 2024 20:41:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
I have this string expression in latex-mode:
$K(U_1, V_1, x_1; t_2, x_2)$
If the pointer is located on the opened "(" and I run "forward-sexp" it
works and the
pointer goes after the closed ")".
But if, again, the pointer is located on the opened "(" and I evaluate
"(sexp-at-point)" it returns nil.
If I remove the ";" symbol from the expression it works and returns the
sexp-at-point:
$K(U_1, V_1, x_1 t_2, x_2)$
Is it a bug?
Best regards,
Gabriele
In GNU Emacs 29.4 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20,
cairo version 1.16.0) of 2024-06-24 built on lcy02-amd64-050
Repository revision: 176061eb965cf945e7627ce87bb16ec5a03f8a4d
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.6 LTS
Configured using:
'configure --prefix=/snap/emacs/current/usr --with-x-toolkit=gtk3
--without-xaw3d --with-modules --with-cairo
--with-native-compilation=aot --without-pgtk --with-xinput2
--with-tree-sitter --with-json
'CFLAGS=-isystem/build/emacs/parts/emacs/install/usr/include
-isystem/build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu
-isystem/build/emacs/stage/usr/include -O2'
'CPPFLAGS=-isystem/build/emacs/parts/emacs/install/usr/include
-isystem/build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu
-isystem/build/emacs/stage/usr/include'
'LDFLAGS=-L/build/emacs/parts/emacs/install/lib
-L/build/emacs/parts/emacs/install/usr/lib
-L/build/emacs/parts/emacs/install/lib/x86_64-linux-gnu
-L/build/emacs/parts/emacs/install/usr/lib/x86_64-linux-gnu
-L/build/emacs/stage/usr/lib''
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3
THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM XINPUT2 XPM
GTK3 ZLIB
Important settings:
value of $LANG: it_IT.UTF-8
locale-coding-system: utf-8-unix
Major mode: LaTeX
Minor modes in effect:
shell-dirtrack-mode: t
tooltip-mode: t
global-eldoc-mode: t
show-paren-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
line-number-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils tex-mode compile text-property-search
shell pcomplete comint ansi-osc ansi-color ring time-date cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)
Memory information:
((conses 16 94745 6994)
(symbols 48 8180 0)
(strings 32 23981 1842)
(string-bytes 1 748444)
(vectors 16 18526)
(vector-slots 8 362068 6080)
(floats 8 40 162)
(intervals 56 343 0)
(buffers 984 12))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Tue, 25 Jun 2024 21:55:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 71777 <at> debbugs.gnu.org (full text, mbox):
Gabriele Nicolardi <gabriele <at> medialab.sissa.it> writes:
> Hi,
>
> I have this string expression in latex-mode:
>
> $K(U_1, V_1, x_1; t_2, x_2)$
>
> If the pointer is located on the opened "(" and I run "forward-sexp"
> it works and the
> pointer goes after the closed ")".
>
> But if, again, the pointer is located on the opened "(" and I evaluate
> "(sexp-at-point)" it returns nil.
>
> If I remove the ";" symbol from the expression it works and returns
> the sexp-at-point:
>
> $K(U_1, V_1, x_1 t_2, x_2)$
>
> Is it a bug?
>
> Best regards,
>
> Gabriele
>
>
> In GNU Emacs 29.4 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20,
> cairo version 1.16.0) of 2024-06-24 built on lcy02-amd64-050
> Repository revision: 176061eb965cf945e7627ce87bb16ec5a03f8a4d
> Repository branch: master
> Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
> System Description: Ubuntu 20.04.6 LTS
>
> Important settings:
> value of $LANG: it_IT.UTF-8
> locale-coding-system: utf-8-unix
>
> Major mode: LaTeX
This suggests you are using the major mode from AUCTeX, rather than the
built-in latex-mode? Is this right?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Tue, 25 Jun 2024 22:52:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Il 25/06/24 23:52, Jeremy Bryant ha scritto:
>> Important settings:
>> value of $LANG: it_IT.UTF-8
>> locale-coding-system: utf-8-unix
>>
>> Major mode: LaTeX
> This suggests you are using the major mode from AUCTeX, rather than the
> built-in latex-mode? Is this right?
No, I'm using the built-in latex-mode. AUCTeX is not installed on my
machine.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 12:40:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 71777 <at> debbugs.gnu.org (full text, mbox):
> Date: Tue, 25 Jun 2024 19:53:59 +0200
> From: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
>
> I have this string expression in latex-mode:
>
> $K(U_1, V_1, x_1; t_2, x_2)$
>
> If the pointer is located on the opened "(" and I run "forward-sexp" it
> works and the
> pointer goes after the closed ")".
>
> But if, again, the pointer is located on the opened "(" and I evaluate
> "(sexp-at-point)" it returns nil.
>
> If I remove the ";" symbol from the expression it works and returns the
> sexp-at-point:
>
> $K(U_1, V_1, x_1 t_2, x_2)$
>
> Is it a bug?
I don't think it's a bug. forward-sexp moves across balanced
expressions, so it is not specific to Lisp. By contrast,
sexp-at-point is specific to Lisp and Lisp-like syntax, and so it uses
the buffer's syntax. Which is why ';' affects the result.
Adding Stefan in case he has comments for this.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 13:48:03 GMT)
Full text and
rfc822 format available.
Message #17 received at 71777 <at> debbugs.gnu.org (full text, mbox):
>> $K(U_1, V_1, x_1; t_2, x_2)$
>>
>> If the pointer is located on the opened "(" and I run "forward-sexp" it
>> works and the
>> pointer goes after the closed ")".
>>
>> But if, again, the pointer is located on the opened "(" and I evaluate
>> "(sexp-at-point)" it returns nil.
>>
>> If I remove the ";" symbol from the expression it works and returns the
>> sexp-at-point:
>>
>> $K(U_1, V_1, x_1 t_2, x_2)$
>>
>> Is it a bug?
>
> I don't think it's a bug. forward-sexp moves across balanced
> expressions, so it is not specific to Lisp. By contrast,
> sexp-at-point is specific to Lisp and Lisp-like syntax, and so it uses
> the buffer's syntax. Which is why ';' affects the result.
>
> Adding Stefan in case he has comments for this.
AFAICT, `sexp-at-point` correctly finds the parenthesized thingy, but it
is asked to return the Lisp object it represents rather than a string,
so it `read`s, which inevitably obeys the ELisp syntax.
IOW, I suspect you want (thing-at-point 'sexp) rather than
(sexp-at-point).
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 15:53:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 71777 <at> debbugs.gnu.org (full text, mbox):
Il 26/06/24 15:46, Stefan Monnier ha scritto:
>>> $K(U_1, V_1, x_1; t_2, x_2)$
>>>
>>> If the pointer is located on the opened "(" and I run "forward-sexp" it
>>> works and the
>>> pointer goes after the closed ")".
>>>
>>> But if, again, the pointer is located on the opened "(" and I evaluate
>>> "(sexp-at-point)" it returns nil.
>>>
>>> If I remove the ";" symbol from the expression it works and returns the
>>> sexp-at-point:
>>>
>>> $K(U_1, V_1, x_1 t_2, x_2)$
>>>
>>> Is it a bug?
>> I don't think it's a bug. forward-sexp moves across balanced
>> expressions, so it is not specific to Lisp. By contrast,
>> sexp-at-point is specific to Lisp and Lisp-like syntax, and so it uses
>> the buffer's syntax. Which is why ';' affects the result.
>>
>> Adding Stefan in case he has comments for this.
> AFAICT, `sexp-at-point` correctly finds the parenthesized thingy, but it
> is asked to return the Lisp object it represents rather than a string,
> so it `read`s, which inevitably obeys the ELisp syntax.
>
> IOW, I suspect you want (thing-at-point 'sexp) rather than
> (sexp-at-point).
>
>
> Stefan
I need to test if a parenthesis in LaTeX (latex-mode) starts a balanced
expression.
sexp-at-point: Return the sexp at point, or nil if none is found.
This is not possible with (thing-at-point 'sexp) because it does no return nil in the case, e.g.:
$K(U_1, V_1, x_1 t_2, x_2$
Gabriele
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 19:44:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 71777 <at> debbugs.gnu.org (full text, mbox):
From the previous responses, I have understood that the sexp-at-point
function is not suitable for my purpose.
However, I suggest updating the documentation because the explanations
you provided are not trivial, and the similarity in names with other
functions (forward-sexp, etc.) creates misunderstandings.
Lastly, I would like to point out an issue on Stack Exchange:
https://emacs.stackexchange.com/q/81603/15606
where I asked for help with a function that fits my needs.
Thank you!
Gabriele
Il 26/06/24 15:46, Stefan Monnier ha scritto:
>>> $K(U_1, V_1, x_1; t_2, x_2)$
>>>
>>> If the pointer is located on the opened "(" and I run "forward-sexp" it
>>> works and the
>>> pointer goes after the closed ")".
>>>
>>> But if, again, the pointer is located on the opened "(" and I evaluate
>>> "(sexp-at-point)" it returns nil.
>>>
>>> If I remove the ";" symbol from the expression it works and returns the
>>> sexp-at-point:
>>>
>>> $K(U_1, V_1, x_1 t_2, x_2)$
>>>
>>> Is it a bug?
>> I don't think it's a bug. forward-sexp moves across balanced
>> expressions, so it is not specific to Lisp. By contrast,
>> sexp-at-point is specific to Lisp and Lisp-like syntax, and so it uses
>> the buffer's syntax. Which is why ';' affects the result.
>>
>> Adding Stefan in case he has comments for this.
> AFAICT, `sexp-at-point` correctly finds the parenthesized thingy, but it
> is asked to return the Lisp object it represents rather than a string,
> so it `read`s, which inevitably obeys the ELisp syntax.
>
> IOW, I suspect you want (thing-at-point 'sexp) rather than
> (sexp-at-point).
>
>
> Stefan
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 20:12:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 71777 <at> debbugs.gnu.org (full text, mbox):
> I need to test if a parenthesis in LaTeX (latex-mode) starts
> a balanced expression.
You mentioned `forward-sexp` which should do the trick, so what made you
try `sexp-at-point`?
> sexp-at-point: Return the sexp at point, or nil if none is found.
>
> This is not possible with (thing-at-point 'sexp) because it does no return nil in the case, e.g.:
>
> $K(U_1, V_1, x_1; t_2, x_2$
The "<foo>-at-point" functions (by the very nature of the concept of
"foo at point") are DWIMish functions.
They're usually not appropriate for use from ELisp code unless that
ELisp code itself wants to be DWIMish.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 20:19:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Il 26/06/24 22:11, Stefan Monnier ha scritto:
>> I need to test if a parenthesis in LaTeX (latex-mode) starts
>> a balanced expression.
> You mentioned `forward-sexp` which should do the trick, so what made you
> try `sexp-at-point`?
Because `forward-sexp` does not return nil if the parenthesis does not
start a balanced expression.
Gabriele
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 20:26:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 71777 <at> debbugs.gnu.org (full text, mbox):
>>> I need to test if a parenthesis in LaTeX (latex-mode) starts
>>> a balanced expression.
>> You mentioned `forward-sexp` which should do the trick, so what made you
>> try `sexp-at-point`?
> Because `forward-sexp` does not return nil if the parenthesis does not start
> a balanced expression.
There is no function that does just what you want; you need to make them
do what you want. E.g.
(save-excursion
(condition-case nil
(progn (forward-sexp 1) t)
(scan-error nil)))
Note that "test if a parenthesis in LaTeX (latex-mode) starts a balanced
expression" is a kind of weird request, because it will only return nil
if there's a missing close-paren but not if there are too many
close-parens, i.e. it only detects one half of the imbalances.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 20:41:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Il 26/06/24 22:25, Stefan Monnier ha scritto:
> Note that "test if a parenthesis in LaTeX (latex-mode) starts a balanced
> expression" is a kind of weird request, because it will only return nil
> if there's a missing close-paren but not if there are too many
> close-parens, i.e. it only detects one half of the imbalances.
>
>
> Stefan
For my purposes it is enough.
I need to write a function to interactively resize mathematical
parentheses based on their content, such as "\left( ... \right)". So
far, I have successfully used `sexp-at-point`, but this function does
not recognize balanced expressions that contain ";" and only works with
"(" and "[" but not with < etc..
The `forward-sexp` function does not necessarily give an error if the
parenthesis does not start a balanced expression. E.g.
$( x + y ]$
here "(" does not start a balanced expression but `forward-sexp` does
not return an error.
Gabriele
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 21:05:01 GMT)
Full text and
rfc822 format available.
Message #38 received at 71777 <at> debbugs.gnu.org (full text, mbox):
> The `forward-sexp` function does not necessarily give an error if the
> parenthesis does not start a balanced expression. E.g.
>
> $( x + y ]$
Yup. Most of the functions that are meant to be used to parse code
while it's being edited don't check validity. Basically they try to
find "what is the meaning of this text" rather than "does this text have
meaning". That's on purpose, because it makes them more usable even
when the text is not 100% valid.
`read` (which parses an ELisp s-exp and is used in `sexp-at-point` to
try and turn the string "( x + y ]" (found by `forward-sexp) into a Lisp
value) is one of the rare exceptions because that one is not meant to
parse text as you type it but rather to parse text in order to process
it (typically, to execute it).
But it obeys the ELisp syntax rather than the LaTeX syntax.
> here "(" does not start a balanced expression but `forward-sexp` does not
> return an error.
I don't think there's code in Emacs which does what you want, so if you
really need to check proper pairing you're going to have to write the code.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 21:15:01 GMT)
Full text and
rfc822 format available.
Message #41 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> I don't think there's code in Emacs which does what you want, so if you
> really need to check proper pairing you're going to have to write the code.
>
>
> Stefan
Thank you very much!
Gabriele
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 21:27:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> I don't think there's code in Emacs which does what you want, so if you
> really need to check proper pairing you're going to have to write the code.
>
>
> Stefan
FYI. NickD offers me this code
https://emacs.stackexchange.com/a/81604/15606:
|(defun ndk/paren-match-p () (let ((mismatch (nth 4
(show-paren--default)))) (not mismatch))) It seems working. Gabriele |
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Wed, 26 Jun 2024 22:20:01 GMT)
Full text and
rfc822 format available.
Message #47 received at 71777 <at> debbugs.gnu.org (full text, mbox):
> |(defun ndk/paren-match-p () (let ((mismatch (nth 4 (show-paren--default))))
> (not mismatch))) It seems working. Gabriele |
AFAIK It only checks the outside pair of parens.
E.g. it won't detect the problem in
((a + b])
- Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#71777
; Package
emacs
.
(Thu, 27 Jun 2024 06:02:02 GMT)
Full text and
rfc822 format available.
Message #50 received at 71777 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> |(defun ndk/paren-match-p () (let ((mismatch (nth 4 (show-paren--default))))
>> (not mismatch))) It seems working. Gabriele |
> AFAIK It only checks the outside pair of parens.
> E.g. it won't detect the problem in
>
> ((a + b])
>
>
> - Stefan
it is good for me because it cover the case, e.g.:
B=((1,3)∪(2,5])
Gabriele
[Message part 2 (text/html, inline)]
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 29 Jun 2024 12:26:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
:
bug acknowledged by developer.
(Sat, 29 Jun 2024 12:26:02 GMT)
Full text and
rfc822 format available.
Message #55 received at 71777-done <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 27 Jun 2024 08:01:13 +0200
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 71777 <at> debbugs.gnu.org
> From: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
>
> it is good for me because it cover the case, e.g.:
>
> B=((1,3)∪(2,5])
Thanks, I've now made clear in the doc string that sexp-at-point is
for returning Lisp objects, and I'm therefore closing this bug.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 28 Jul 2024 11:24:18 GMT)
Full text and
rfc822 format available.
This bug report was last modified 203 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.