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: Thu, 13 Oct 2016 17:50:05 +0900 Message-ID: <87eg3keipu.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> 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 1476348695 9506 195.159.176.226 (13 Oct 2016 08:51:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Oct 2016 08:51:35 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 24627@debbugs.gnu.org, Tino Calancha To: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 13 10:51:27 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 1bubjP-0000Xq-Mu for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Oct 2016 10:51:15 +0200 Original-Received: from localhost ([::1]:38578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bubjO-0007YF-Fs for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Oct 2016 04:51:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bubjG-0007Xx-VS for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 04:51:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bubjC-0002hF-0Z for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 04:51:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bubjB-0002gw-Tc for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 04:51:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bubjB-00043l-Lt for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2016 04:51:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Oct 2016 08:51: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.147634861615540 (code B ref 24627); Thu, 13 Oct 2016 08:51:01 +0000 Original-Received: (at 24627) by debbugs.gnu.org; 13 Oct 2016 08:50:16 +0000 Original-Received: from localhost ([127.0.0.1]:53703 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bubiS-00042Z-8w for submit@debbugs.gnu.org; Thu, 13 Oct 2016 04:50:16 -0400 Original-Received: from mail-pf0-f174.google.com ([209.85.192.174]:35778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bubiQ-00042K-AB for 24627@debbugs.gnu.org; Thu, 13 Oct 2016 04:50:15 -0400 Original-Received: by mail-pf0-f174.google.com with SMTP id s8so32261187pfj.2 for <24627@debbugs.gnu.org>; Thu, 13 Oct 2016 01:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=vFy5OVPBGQ3lKnN4BCwMgzbeVXptZ3q+Ulw0AezDQ2I=; b=gT9azstyGbIYQWXDgGEsvWXktIXG/Iz0RY4QTkfad+5JSRwALkke0qK+8UtpjQxzUY xNGb3T/7MZA9l+xTJB2M1Ze4D5/KSUQpZGW5xTFbJAjB122KQcheRp8S7O0Ce5PxEg2m 9lJPI/2u2jShIlxG2/it+Lm9X5K7isZvw1WpmLTHiB/ye3MEeCSfH1R8B73Yn6u/HCCS Fs4+EXK4H/C4NUAFh9Q2NKYa9vn/j+QD2Zd+9rJ4sstCGILJtOLloHcb6HWTi4j6Bml6 yjFEjBcbgLUoBnSGo2KOTb7GWCZxDJnyTm2uKXlgoQkGsrhWx9nzb/LvNYrMEAtJFsQ7 AeIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=vFy5OVPBGQ3lKnN4BCwMgzbeVXptZ3q+Ulw0AezDQ2I=; b=EmKbR9o31LgmG63xKSnJF1k6YYZoHeazW3ea1LITzX9ZkvpeuTu4c8cXy4SJciWbWq BX+WACSlMo3Qrvhs5cBeCTAY8P0LP3Kp0jfvV8aVhEssXyeOSHeB+IaKOaG4MM5tyE7X 682SYAF02DR3tiTDHwNcYfH79YfYA5anbHjPqRz1NEOU4VxQiqM01cStJbjAkkM4MU80 fY6Muh6UMF9AvTiEizLJi61izjZ+Q+BtcCqf2B1l5DGUS+zmmRz9E3XQi9m4TQHd66BV GAb734g6MuVbbTGqNb5N/c6O24X+dvcSjjm+L1YRCC+JSsgrEpczweW/O49X3aXVm8pK qtGw== X-Gm-Message-State: AA6/9RmnlKlqB/pP9dMyWYxOlc+gt7AK19XDsABVJq+yCckgGxFpBs9S9WebkG4M1fd/+g== X-Received: by 10.98.99.197 with SMTP id x188mr8348067pfb.121.1476348608659; Thu, 13 Oct 2016 01:50:08 -0700 (PDT) Original-Received: from calancha-pc (57.92.100.220.dy.bbexcite.jp. [220.100.92.57]) by smtp.gmail.com with ESMTPSA id g21sm17618659pfb.43.2016.10.13.01.50.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Oct 2016 01:50:08 -0700 (PDT) In-Reply-To: ("Andreas \=\?utf-8\?Q\?R\=C3\=B6hler\=22's\?\= message of "Wed, 12 Oct 2016 09:10:42 +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:124427 Archived-At: 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. 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 implementa= tion. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;; >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 =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)))) + (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) (=3D 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 (>=3D opoint (point)) - (cons opoint end)))))))) + (when beg + (forward-sexp) + (cons beg (point))))))) =20 ;; Defuns =20 --=20 2.9.3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.1) of 2016-10-13 Repository revision: 1dd54e3eef7543720eff161457677a35fae2435c