unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
@ 2013-03-16  7:51 Andreas Röhler
  2013-03-16 10:33 ` Leo Liu
  2021-08-23  1:09 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 11+ messages in thread
From: Andreas Röhler @ 2013-03-16  7:51 UTC (permalink / raw)
  To: 13973

(defun end-of-sexp ()
   "Move point to the end of the current sexp.
\[This is an internal function.]"
   (let ((char-syntax (char-syntax (char-after))))
     (if (or (eq char-syntax ?\))
	    (and (eq char-syntax ?\") (in-string-p)))
	(forward-char 1)
       (forward-sexp 1))))

"or" asks if inside a string and calls (forward-char 1).

This must fail with some probability with
triple-quoted-strings as used in Python.

Solution:

When inside a string, jump to (nth 8 (syntax-ppss)) and
call (forward-sexp 1) from there.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2013-03-16  7:51 bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp Andreas Röhler
@ 2013-03-16 10:33 ` Leo Liu
  2013-03-16 12:09   ` Andreas Röhler
  2013-03-16 13:50   ` Stefan Monnier
  2021-08-23  1:09 ` Lars Ingebrigtsen
  1 sibling, 2 replies; 11+ messages in thread
From: Leo Liu @ 2013-03-16 10:33 UTC (permalink / raw)
  To: 13973

On 2013-03-16 15:51 +0800, Andreas Röhler wrote:
> When inside a string, jump to (nth 8 (syntax-ppss)) and
> call (forward-sexp 1) from there.

In my experience (a while ago, I use little python these days) this
cannot reliably goes to the end of the triple-quoted string.

Leo






^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2013-03-16 10:33 ` Leo Liu
@ 2013-03-16 12:09   ` Andreas Röhler
  2013-03-16 13:50   ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2013-03-16 12:09 UTC (permalink / raw)
  To: 13973

Am 16.03.2013 11:33, schrieb Leo Liu:
> On 2013-03-16 15:51 +0800, Andreas Röhler wrote:
>> When inside a string, jump to (nth 8 (syntax-ppss)) and
>> call (forward-sexp 1) from there.
>
> In my experience (a while ago, I use little python these days) this
> cannot reliably goes to the end of the triple-quoted string.
>
> Leo
>
>
>
>
>

Indeed seems a bug in python-mode.el at this place just now.
Anyway - forward-sexp must go to the end of string from it's beginning,
a string is a balanced expression.


Best,

Andreas










^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2013-03-16 10:33 ` Leo Liu
  2013-03-16 12:09   ` Andreas Röhler
@ 2013-03-16 13:50   ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2013-03-16 13:50 UTC (permalink / raw)
  To: Leo Liu; +Cc: 13973

>> When inside a string, jump to (nth 8 (syntax-ppss)) and
>> call (forward-sexp 1) from there.

Sounds right, yes.

> In my experience (a while ago, I use little python these days) this
> cannot reliably goes to the end of the triple-quoted string.

That would be a bug in python-mode, then.


        Stefan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2013-03-16  7:51 bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp Andreas Röhler
  2013-03-16 10:33 ` Leo Liu
@ 2021-08-23  1:09 ` Lars Ingebrigtsen
  2021-08-23 17:11   ` Andreas Röhler
  1 sibling, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-23  1:09 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 13973

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> (defun end-of-sexp ()
>   "Move point to the end of the current sexp.
> \[This is an internal function.]"
>   (let ((char-syntax (char-syntax (char-after))))
>     (if (or (eq char-syntax ?\))
> 	    (and (eq char-syntax ?\") (in-string-p)))
> 	(forward-char 1)
>       (forward-sexp 1))))
>
> "or" asks if inside a string and calls (forward-char 1).
>
> This must fail with some probability with
> triple-quoted-strings as used in Python.
>
> Solution:
>
> When inside a string, jump to (nth 8 (syntax-ppss)) and
> call (forward-sexp 1) from there.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

It's not quite clear to me what the actual problem here is.  Do you have
a test case where thingatpt does the wrong thing in Python mode?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-23  1:09 ` Lars Ingebrigtsen
@ 2021-08-23 17:11   ` Andreas Röhler
  2021-08-25 10:38     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2021-08-23 17:11 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 13973


On 23.08.21 03:09, Lars Ingebrigtsen wrote:
> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
>> (defun end-of-sexp ()
>>    "Move point to the end of the current sexp.
>> \[This is an internal function.]"
>>    (let ((char-syntax (char-syntax (char-after))))
>>      (if (or (eq char-syntax ?\))
>> 	    (and (eq char-syntax ?\") (in-string-p)))
>> 	(forward-char 1)
>>        (forward-sexp 1))))
>>
>> "or" asks if inside a string and calls (forward-char 1).
>>
>> This must fail with some probability with
>> triple-quoted-strings as used in Python.
>>
>> Solution:
>>
>> When inside a string, jump to (nth 8 (syntax-ppss)) and
>> call (forward-sexp 1) from there.
> (I'm going through old bug reports that unfortunately weren't resolved
> at the time.)
>
> It's not quite clear to me what the actual problem here is.

It's only abstract reasoning when looking at the code.

Maybe put the Python code below at the top of some buffer and run the 
test delivered below:

# Python

def main():
     """Some hint"""
     if len(sys.argv) == 1:
         usage()

;; Elisp
(defun forward-sexp-text ()
   (interactive)
   (goto-char 30 )
   (forward-sexp))


>   Do you have
> a test case where thingatpt does the wrong thing in Python mode?
>





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-23 17:11   ` Andreas Röhler
@ 2021-08-25 10:38     ` Lars Ingebrigtsen
  2021-08-26  6:21       ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-25 10:38 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 13973

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> Maybe put the Python code below at the top of some buffer and run the
> test delivered below:
>
> # Python
>
> def main():
>     """Some hint"""
>     if len(sys.argv) == 1:
>         usage()
>
> ;; Elisp
> (defun forward-sexp-text ()
>   (interactive)
>   (goto-char 30 )
>   (forward-sexp))

By that goto-char, do you mean the "S" character?  (It's where point
lands in the buffer included below.)  If so, `forward-sex'
(in Emacs 28) does the correct thing -- it moves to the end of "Some".

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sexp.py --]
[-- Type: text/x-python, Size: 85 bytes --]

# Python

def main():
    """Some hint"""
    if len(sys.argv) == 1:
        usage()

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-25 10:38     ` Lars Ingebrigtsen
@ 2021-08-26  6:21       ` Andreas Röhler
  2021-08-26 14:05         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2021-08-26  6:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 13973


On 25.08.21 12:38, Lars Ingebrigtsen wrote:
> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
>> Maybe put the Python code below at the top of some buffer and run the
>> test delivered below:
>>
>> # Python
>>
>> def main():
>>      """Some hint"""
>>      if len(sys.argv) == 1:
>>          usage()
>>
>> ;; Elisp
>> (defun forward-sexp-text ()
>>    (interactive)
>>    (goto-char 30 )
>>    (forward-sexp))
> By that goto-char, do you mean the "S" character?


No, sorry, the 5th double-quote of the triple-quoted-string.

> (It's where point
> lands in the buffer included below.)  If so, `forward-sex'
> (in Emacs 28) does the correct thing -- it moves to the end of "Some".
>





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-26  6:21       ` Andreas Röhler
@ 2021-08-26 14:05         ` Lars Ingebrigtsen
  2021-08-27 18:44           ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-26 14:05 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 13973

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

>>> Maybe put the Python code below at the top of some buffer and run the
>>> test delivered below:
>>>
>>> # Python
>>>
>>> def main():
>>>      """Some hint"""
>>>      if len(sys.argv) == 1:
>>>          usage()
>>>
>>> ;; Elisp
>>> (defun forward-sexp-text ()
>>>    (interactive)
>>>    (goto-char 30 )
>>>    (forward-sexp))
>> By that goto-char, do you mean the "S" character?
>
> No, sorry, the 5th double-quote of the triple-quoted-string.

That gives me

forward-sexp: Scan error: "Unbalanced parentheses", 40, 86

which I think is the right thing?

This bug report started with thingatpt.  What is the real thingatpt use
case that doesn't work in triple-quoted strings?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-26 14:05         ` Lars Ingebrigtsen
@ 2021-08-27 18:44           ` Andreas Röhler
  2021-08-28 15:05             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2021-08-27 18:44 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 13973


On 26.08.21 16:05, Lars Ingebrigtsen wrote:
> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
>>>> Maybe put the Python code below at the top of some buffer and run the
>>>> test delivered below:
>>>>
>>>> # Python
>>>>
>>>> def main():
>>>>       """Some hint"""
>>>>       if len(sys.argv) == 1:
>>>>           usage()
>>>>
>>>> ;; Elisp
>>>> (defun forward-sexp-text ()
>>>>     (interactive)
>>>>     (goto-char 30 )
>>>>     (forward-sexp))
>>> By that goto-char, do you mean the "S" character?
>> No, sorry, the 5th double-quote of the triple-quoted-string.
> That gives me
>
> forward-sexp: Scan error: "Unbalanced parentheses", 40, 86
>
> which I think is the right thing?

If inside a string, forward-sexp --or end-of-- should reach the end of 
this string.

BTW end-of-sexp is declared obsolete meanwhile. Below an adapted test.


(defun my-thing-at-point--end-of-sexp-test ()
   (interactive)
   (goto-char (point-max))
   (search-backward "\"" nil t 6)
   ;; the only one ending correctly behind the string
   (thing-at-point--end-of-sexp)
   (goto-char (point-max))
   (search-backward "\"" nil t 6)
   (forward-char 4)
   (thing-at-point--end-of-sexp)
   (goto-char (point-max))
   (search-backward "\"" nil t 3)
   (thing-at-point--end-of-sexp)
   (goto-char (point-max))
   (search-backward "\"" nil t 2)
   (thing-at-point--end-of-sexp))

and here the Python code to test again:


def main():
      """Some hint"""
      if len(sys.argv) == 1:
          usage()



>
> This bug report started with thingatpt.  What is the real thingatpt use
> case that doesn't work in triple-quoted strings?
>





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
  2021-08-27 18:44           ` Andreas Röhler
@ 2021-08-28 15:05             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 11+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-28 15:05 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 13973

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> BTW end-of-sexp is declared obsolete meanwhile. Below an adapted test.

Thanks.  The odd movements happen in these cases:

"|""Some hint"""

"""Some hint|"""

where | is point.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-08-28 15:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-16  7:51 bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp Andreas Röhler
2013-03-16 10:33 ` Leo Liu
2013-03-16 12:09   ` Andreas Röhler
2013-03-16 13:50   ` Stefan Monnier
2021-08-23  1:09 ` Lars Ingebrigtsen
2021-08-23 17:11   ` Andreas Röhler
2021-08-25 10:38     ` Lars Ingebrigtsen
2021-08-26  6:21       ` Andreas Röhler
2021-08-26 14:05         ` Lars Ingebrigtsen
2021-08-27 18:44           ` Andreas Röhler
2021-08-28 15:05             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).