From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs 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 Message-ID: <87vawuc5fi.fsf@gmail.com> References: <48df5626-be32-ffb0-55f5-1b6f116a6940@easy-emacs.de> <87fuo3r1p0.fsf@gmail.com> <08d6c55e-f060-fabc-5657-2e80a1d06ab0@easy-emacs.de> <878ttu97e3.fsf@gmail.com> <781dea94-9f15-8bd2-66f5-055b55497471@easy-emacs.de> <87r37mupt0.fsf@gmail.com> <87eg3keipu.fsf@gmail.com> <18783e9f-e834-bb49-61f4-8eaf7b684590@easy-emacs.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1476524728 18926 195.159.176.226 (15 Oct 2016 09:45:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 15 Oct 2016 09:45:28 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 24627@debbugs.gnu.org, tino.calancha@gmail.com To: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 15 11:45:23 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bvLWm-0003M8-H9 for geb-bug-gnu-emacs@m.gmane.org; Sat, 15 Oct 2016 11:45:16 +0200 Original-Received: from localhost ([::1]:51131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvLWk-0007B9-RH for geb-bug-gnu-emacs@m.gmane.org; Sat, 15 Oct 2016 05:45:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvLWe-00077y-Fl for bug-gnu-emacs@gnu.org; Sat, 15 Oct 2016 05:45:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvLWY-00072W-CX for bug-gnu-emacs@gnu.org; Sat, 15 Oct 2016 05:45:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bvLWY-00072P-8L for bug-gnu-emacs@gnu.org; Sat, 15 Oct 2016 05:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bvLWY-0000lT-1h for bug-gnu-emacs@gnu.org; Sat, 15 Oct 2016 05:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 Oct 2016 09:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24627 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24627-submit@debbugs.gnu.org id=B24627.14765246912905 (code B ref 24627); Sat, 15 Oct 2016 09:45:01 +0000 Original-Received: (at 24627) by debbugs.gnu.org; 15 Oct 2016 09:44:51 +0000 Original-Received: from localhost ([127.0.0.1]:58633 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bvLWN-0000km-3Y for submit@debbugs.gnu.org; Sat, 15 Oct 2016 05:44:51 -0400 Original-Received: from mail-pf0-f169.google.com ([209.85.192.169]:33488) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bvLWL-0000kU-BD for 24627@debbugs.gnu.org; Sat, 15 Oct 2016 05:44:49 -0400 Original-Received: by mail-pf0-f169.google.com with SMTP id 128so60387992pfz.0 for <24627@debbugs.gnu.org>; Sat, 15 Oct 2016 02:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:cc:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=6Xk4CMFExQ7ePNJW+w95xfPF96ALSRNkpofg6rC+wFk=; b=cIOQZMtYU1NQagTNtMfUhtL3wDJcLAhvi/gbKNQeiia2Gx9bIyNvUATVloBtVj2KZy qZT8JbPkQOc8jHIlqfHWeVG8jNEH/NPAAG91wt7x0SmQQjobw9MOXci2bcNBq5DTbRcN ArOy2DCCpRdd/TUrIvg/FLaj2n9HxnDczwiSjen12mA400dXvxjnhwjZ/hSIpCkMqCzy QbpbG1V1JG48VWUsnHwdnrpU8WpyF3626z0diS4ta0PQJ5HRJsnhFdN48z1qtEnAjTr5 tSsCdm8KK7HlhbwmtLR/YJ7WiTEejp/sGtw+NSYhAyLAT53u0d0YO+7iTbjjRZMfUy9N /Lvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:references:cc:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=6Xk4CMFExQ7ePNJW+w95xfPF96ALSRNkpofg6rC+wFk=; b=U2gNaNdrb/uZ+eToiRNgv0JdRjomn+1n7gIL6RPpyFbsCwwwRDwRXYkra+nVlgbT7P +SmYWL5KVwwTCg1YNV2sLq4tZfiC0kiCQw0HUDKYe212I8vpK38VR5kGxsrPE6Ru43y5 2+07c5dIjxQXHAg670pVS3PSgNYeGgo5cPkr+5KUpsPilkmxfhuCQvo0lqptvd6W/sNQ 5ogjJij47M2+mwrdOnzOefJ3uDYVAwPguNJk5UkgNQVP6vqCS/vnALAqqCOtlOl8lsQh +6bYTydVpcIgklIy77TyXOjLz8ZyCy6iz2LuqIE9sfigOvMenOCJKL2Ko2REOp3HlBhf VDzw== X-Gm-Message-State: AA6/9RkfDjgfqtgKVUoFSysae5oSpslRf8Lt0sWKRRz920OhzMQU/a2A4FPKDM0o4oy12g== X-Received: by 10.98.14.197 with SMTP id 66mr24300257pfo.123.1476524683337; Sat, 15 Oct 2016 02:44:43 -0700 (PDT) Original-Received: from calancha-pc ([240f:6e:c00e:1:6875:2e94:598b:96cb]) by smtp.gmail.com with ESMTPSA id 74sm33480901pfp.77.2016.10.15.02.44.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Oct 2016 02:44:42 -0700 (PDT) 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") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:124500 Archived-At: Andreas R=C3=B6hler writes: > On 13.10.2016 10:50, Tino Calancha wrote: >> Andreas R=C3=B6hler 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))))) >=20=20=20=20=20=20 > > 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 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 =20 (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 (>=3D 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)))))) =20 ;; Defuns =20 --=20 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