From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list Date: Thu, 13 Oct 2016 19:50:22 +0200 Message-ID: <18783e9f-e834-bb49-61f4-8eaf7b684590@easy-emacs.de> 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1476381787 29045 195.159.176.226 (13 Oct 2016 18:03:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Oct 2016 18:03:07 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.4.0 Cc: 24627@debbugs.gnu.org To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 13 20:02:58 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 1bukLE-0005ob-GC for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Oct 2016 20:02:52 +0200 Original-Received: from localhost ([::1]:42279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bukLD-0003Db-1k for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Oct 2016 14:02:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buk26-0003cX-KW for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 13:43:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buk22-00071i-FY for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 13:43:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buk22-00071e-CI for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 13:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1buk22-00045s-3I for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 13:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Oct 2016 17:43:02 +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.147638057415721 (code B ref 24627); Thu, 13 Oct 2016 17:43:02 +0000 Original-Received: (at 24627) by debbugs.gnu.org; 13 Oct 2016 17:42:54 +0000 Original-Received: from localhost ([127.0.0.1]:54459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buk1u-00045V-4n for submit@debbugs.gnu.org; Thu, 13 Oct 2016 13:42:54 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.133]:63968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buk1s-00045I-64 for 24627@debbugs.gnu.org; Thu, 13 Oct 2016 13:42:52 -0400 Original-Received: from [192.168.178.35] ([77.3.37.31]) by mrelayeu.kundenserver.de (mreue003) with ESMTPSA (Nemesis) id 0MVZ1v-1bLnq72n3H-00Ywgs; Thu, 13 Oct 2016 19:42:44 +0200 In-Reply-To: <87eg3keipu.fsf@gmail.com> X-Provags-ID: V03:K0:Wkw5I99m4d4O3OKcQ8qq2Y12rl8OuFH1SRpVU49MeBACZPmZImE iwwsQZNq+DM6iomyPMKOu7CBPEAEqYpe1TmKjKDH+k3ViTIr3DSMLytxQpEyvpp66E5Ss7C VCwTw16LaRtcYfxNDK6ZS8W7cCjfGKEBOONUlrF7msDlwZ5x7NX+cblPjmrsztyczsLOJwY CldYqNAdWIk0MbkQqSmzg== X-UI-Out-Filterresults: notjunk:1;V01:K0:lUszLOytPaU=:A/mhF7XsAnwQGuVuWnN70B nxzW/w8RxcRDsRpaF5FAq5V//QRGqbWIa+O569nOyweDmgYIIwwZ4gX4TlGccdlqB81lnkyiz EmgtzA1XY/+5iKor0iPZqPpJ+I2s6omQ5oPDkuIqpHwdUMW+Owd8ePScAzeBe4dKNK1MD8E+I MdUKQpRVy1zZDHjx84ny8Sxjg4nzry7vH/HLKaEDlVzXoU/F0d/HdYhMX+E9078iG2EgZJWso qSS8Qno9wpB5gdBKASamT5p53lXnmg3JhwCjNy6Lla0Xwtb5y+7NWFIFpy5QSKqb97CMZZOm8 ffAvz52IMH5PjpJY93R59wwGKn9ayr9fbg8meq7Zd4eFnFJ7vu0BSW2UoVTxPe2sTiX4hSqLA X6E0p1jcc8JsfOMXIxk7zhEKtwBJcqx0YrU9yQTX6P91vAmNHYuWNBFUdh7s4eE9fOT6S4TdN tywk0YXYv3CtbetvQwivtk90EDmHbcTzPzZ2/6P4ZTl4e+xwIRdH3rvYnEP5dggrhjHhspRRe 1aE0zvwIk1G7ybyHEvpwoNN6RjnngVPS6jNmvQ1DiLRfc+aOLsvO1DK2X71RX3WYOgjD9qxLw rXj25tj3h/wkRYnOUF6CCET63pI0ER3kypAfuD8swwC31uZUhMLDuJMj9cr2br7ML+KZuU3N8 ygySWnuRm0Mtl6+WpUeDlUCLx953mPX9reZ4RgvIFD5jgjWPQE0uivYezVrZvhm58+dIgv1LR TopVIgU/o8oy4Q++ 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:124442 Archived-At: On 13.10.2016 10:50, Tino Calancha wrote: > Andreas Röhler 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. > Then, if > point is inside a comment/string and there is no list there, > the function might look for a list around (i.e., outside) that > comment/string region. See patch below. > > Anyway, neither the doc string of `thing-at-point' nor > `thing-at-point-bounds-of-list-at-point' mention what expect > when point is inside a comment/string. That's why i believe it > might be better to request that in a different bug report. > Writting additional tests also might be helpful to find a robust implementation. > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > From bfc9b7fb739dfeab09c2ffd064a6ebe65a28b686 Mon Sep 17 00:00:00 2001 > From: Tino Calancha > Date: Thu, 13 Oct 2016 16:34:35 +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 found a list inside a comment or string return it. Otherwise, look > for a list around the comment/string. > Escape '[' in doc string. > --- > lisp/thingatpt.el | 32 ++++++++++++++++++-------------- > 1 file changed, 18 insertions(+), 14 deletions(-) > > diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el > index 6d1014b..656d2c7 100644 > --- a/lisp/thingatpt.el > +++ b/lisp/thingatpt.el > @@ -219,22 +219,26 @@ '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)))) > + (let* ((opoint (point)) > + (st (syntax-ppss)) > + (find-list-fn (lambda () > + (ignore-errors > + (up-list -1) > + (point)))) > + (beg (if (eq 4 (car (syntax-after (point)))) > + (point) > + (funcall find-list-fn)))) > + ;; If inside a string or comment and there is no list > + ;; at point, check for a list surrounding the string/comment region. > + (when (and (nth 8 st) (= opoint (point))) > + (goto-char (nth 8 st)) > + (setq beg (funcall find-list-fn))) > (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)))))))) > + (when beg > + (forward-sexp) > + (cons beg (point))))))) > > ;; Defuns >