unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: 24627@debbugs.gnu.org, tino.calancha@gmail.com
Subject: bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list
Date: Sat, 15 Oct 2016 18:44:33 +0900	[thread overview]
Message-ID: <87vawuc5fi.fsf@gmail.com> (raw)
In-Reply-To: <18783e9f-e834-bb49-61f4-8eaf7b684590@easy-emacs.de> ("Andreas \=\?utf-8\?Q\?R\=C3\=B6hler\=22's\?\= message of "Thu, 13 Oct 2016 19:50:22 +0200")

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

> On 13.10.2016 10:50, Tino Calancha wrote:
>> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>>
>>> beg still needs a check like
>>>
>>> (not (nth 8 (parse-partial-sexp (point-min) (point))))
>>>
>>> otherwise it could match inside a string or comment
>> I have the feeling that this should return the local list
>> at point, even if inside a string or comment.
>
> Yes, but that would be reported by pps. However, when point is at
> opening delimiter, this is not recognised by pps. Then we must be sure
> not being inside a string or comment, where an opening delimiter is
> meaningless, i.e. just a literal.
>
> IMO all needed is  something like
>
> (beg (or (nth 1 (parse-partial-sexp...))
>
>          (and (eq 4 (car (syntax-after (point))))
>               (not (nth 8 (parse-partial-sexp...))
>               (point)))))
>      
>
> Should both fail, there is not list at point.
Thank you.  I think i got what you mean.
I need to invert the order of the above `or':
(nth 1 (parse-partial-sexp...))
need to appear the second.  Otherwise,
(with-temp-buffer
  (insert "(foo (a b) bar)")
  (goto-char 6)
  (list-at-point))

will return:
(foo (a b) bar)
instead of:
(a b)

The new patch pass following test:
(We might want to add this test into test/lisp/thingatpt-tests.el)

(ert-deftest list-at-point-tests ()
  "Test `list-at-point'."
  (let ((string-result '(("(a \"b\" c)" . (a "b" c))
                         (";(a \"b\" c)")
                         ("(a \"b\" c\n)" . (a "b" c))
                         ("\"(a b c)\"")
                         ("(a ;(b c d)\ne)" . (a e))
                         ("(foo\n(a ;(b c d)\ne) bar)" . (a e))
                         ("(foo\na ;(b c d)\ne bar)" . (foo a e bar))
                         ("(foo\n(a \"(b c d)\"\ne) bar)" . (a "(b c d)" e))
                         ("(b\n(a ;(foo c d)\ne) bar)" . (a e))
                         ("(princ \"(a b c)\")" . (princ "(a b c)"))
                         ("(defun foo ()\n  \"Test function.\"\n  ;;(a b)\n  nil)" . (defun foo nil "Test function." nil)))))
    (dolist (str-res string-result)
      (with-temp-buffer
        (emacs-lisp-mode)
        (insert (car str-res))
        (re-search-backward "\\((a\\|^a\\)")
        (should (equal (list-at-point)
                       (cdr str-res)))))))


This is the new patch:
please, let me know if it's OK for you and feel free to suggest
additional tests.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 693aeed2a7251d23885ee53db9bf7026c7c1af3f Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Sat, 15 Oct 2016 18:21:36 +0900
Subject: [PATCH] (thing-at-point 'list) return nil if no list at point

* lisp/thingatpt.el (thing-at-point-bounds-of-list-at-point):
Check first if we are at the beginning of a top-level sexp (Bug#24627).
If point is inside a comment or string, look for a list out of the
comment/string.
Escape '[' in doc string.
---
 lisp/thingatpt.el | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 6d1014b..e423630 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -219,22 +219,17 @@ 'beginning-of-sexp
 
 (defun thing-at-point-bounds-of-list-at-point ()
   "Return the bounds of the list at point.
-[Internal function used by `bounds-of-thing-at-point'.]"
+\[Internal function used by `bounds-of-thing-at-point'.]"
   (save-excursion
-    (let ((opoint (point))
-	  (beg (ignore-errors
-		 (up-list -1)
-		 (point))))
-      (ignore-errors
-	(if beg
-	    (progn (forward-sexp)
-		   (cons beg (point)))
-	  ;; Are we are at the beginning of a top-level sexp?
-	  (forward-sexp)
-	  (let ((end (point)))
-	    (backward-sexp)
-	    (if (>= opoint (point))
-		(cons opoint end))))))))
+    (let* ((st (parse-partial-sexp (point-min) (point)))
+           (beg (or (and (eq 4 (car (syntax-after (point))))
+                         (not (nth 8 st))
+                         (point))
+                    (nth 1 st))))
+      (when beg
+        (goto-char beg)
+        (forward-sexp)
+        (cons beg (point))))))
 
 ;; Defuns
 
-- 
2.9.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 26.0.50.4 (x86_64-pc-linux-gnu, GTK+ Version 3.22.1)
 of 2016-10-15
Repository revision: b0f1d23ec482aa71a0ae0251f6f44f4b8d261259





  reply	other threads:[~2016-10-15  9:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06  9:43 bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list Tino Calancha
2016-10-07  6:42 ` Andreas Röhler
2016-10-11  3:42   ` Tino Calancha
2016-10-11 15:37     ` Andreas Röhler
2016-10-11 16:29       ` Tino Calancha
2016-10-11 16:47         ` Noam Postavsky
2016-10-11 17:09           ` Tino Calancha
2016-10-11 17:15             ` Noam Postavsky
2016-10-11 17:21               ` Tino Calancha
2016-10-11 17:16         ` bug#24627: "internal" designation [was: bug#24627: 24.5; (thing-at-point 'list) ...] Drew Adams
2016-10-11 17:21           ` Drew Adams
2016-10-11 18:40         ` bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list Andreas Röhler
2016-10-12  4:58           ` Tino Calancha
2016-10-12  7:10             ` Andreas Röhler
2016-10-13  8:50               ` Tino Calancha
2016-10-13 17:50                 ` Andreas Röhler
2016-10-15  9:44                   ` Tino Calancha [this message]
2016-10-15 10:26                     ` Andreas Röhler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vawuc5fi.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=24627@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).