From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#31772: 26.1; (thing-at-point 'list) regression Date: Tue, 11 Sep 2018 20:36:53 +0800 Message-ID: References: <838t7msmy1.fsf@gnu.org> <87k1r6acqo.fsf@gmail.com> <83y3c8mo40.fsf@gnu.org> <83tvmwmgi7.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1536669440 18639 195.159.176.226 (11 Sep 2018 12:37:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Sep 2018 12:37:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (macOS 10.12.6) Cc: 31772@debbugs.gnu.org, tino.calancha@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 11 14:37:16 2018 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 1fzhut-0004eo-Kj for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Sep 2018 14:37:15 +0200 Original-Received: from localhost ([::1]:57458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzhwv-0000id-1w for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Sep 2018 08:39:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzhwj-0000iK-DC for bug-gnu-emacs@gnu.org; Tue, 11 Sep 2018 08:39:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzhve-0007SW-H6 for bug-gnu-emacs@gnu.org; Tue, 11 Sep 2018 08:38:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fzhve-0007Rq-C9 for bug-gnu-emacs@gnu.org; Tue, 11 Sep 2018 08:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fzhve-0008Ld-6S for bug-gnu-emacs@gnu.org; Tue, 11 Sep 2018 08:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Sep 2018 12:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31772 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31772-submit@debbugs.gnu.org id=B31772.153666942732019 (code B ref 31772); Tue, 11 Sep 2018 12:38:02 +0000 Original-Received: (at 31772) by debbugs.gnu.org; 11 Sep 2018 12:37:07 +0000 Original-Received: from localhost ([127.0.0.1]:36296 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzhuk-0008KN-Tl for submit@debbugs.gnu.org; Tue, 11 Sep 2018 08:37:07 -0400 Original-Received: from mail-pg1-f169.google.com ([209.85.215.169]:40039) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fzhui-0008Js-PE for 31772@debbugs.gnu.org; Tue, 11 Sep 2018 08:37:05 -0400 Original-Received: by mail-pg1-f169.google.com with SMTP id l63-v6so12196609pga.7 for <31772@debbugs.gnu.org>; Tue, 11 Sep 2018 05:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version; bh=mq6EN8SoloUFXDTa5PX9Kg7E2adiaogr6IYseTWiW+g=; b=QVTg+8GEDNbSPzkQcMNWsPo74bDrNUKL2PUcoKODNNFV1VhiwZSuYovHyTWpWQsyUf rNv50QcDPAdLGisa/9T9BeYExaV0v5iv+0/OWQIF94/f52MF8QhaxmyXP0J+TNKmg9QB MBZZ8Tbx1kg8QEyw5YcQVDu7HcMS2GTj0m2SdFbd3I1uJbciOW+W6ktJX43rDjc9xjJV YJ7jmGKomNpcG5j3r85oVkscGovQ4NxhNRkrxYTsEmq3rWcBo+r9LggGi6pImDx2LrZl h5n+nkx7ZmJwg8Ei/BbtQX5bhLFDZ3WWdOBcMdt/HlDzZ+6XX5U1N9PIpwoY0Dl2Khr/ TdIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:face:date :in-reply-to:message-id:user-agent:mime-version; bh=mq6EN8SoloUFXDTa5PX9Kg7E2adiaogr6IYseTWiW+g=; b=GidsLTo/HfVHNsJTvwTWeXSfL1FOqnV48zt3OJroH1jW2uoeMybWgNDDIIRBnDIgn0 2yptGWza66N5ABEzj0FiEGZSrRhcMc06ir+wfdfiFILdTB5pI5dY946fngLspPA2q9wu hSS6NZyaR+z9aI8S2jUvOPv9Gwh/M+gAb7FqZr+JHJR64iWINVNutmHvbSqJGW4q5jVI U0tWNpdMVdcHoT1uxiXjXQ1sriy96RzAs/eJLrrQSVDsvn1T04a8T4Qd/5Ry2MNgXUWo 7soD05rzYL9SP9N+T3P4KJdJb8qNSfTiN2wYY8Li2dfzCYTCc0OmAs5EyKEYvQdN+nNA Y1Jg== X-Gm-Message-State: APzg51AAdo+dGeUn4lWwjUpwxEFxJ6xCAfyi1Mj9QWXK16JncQXpr6CB 6tPm7PppfA5fMryMFez/fMM= X-Google-Smtp-Source: ANB0VdZKH9NOKD6jexPGwmbmgfwmlI0f9tr9JACmdAahsuWY5tsRyydaevlkvvuZlAGlDp88uvoR7Q== X-Received: by 2002:a62:cac5:: with SMTP id y66-v6mr29079233pfk.187.1536669418759; Tue, 11 Sep 2018 05:36:58 -0700 (PDT) Original-Received: from Zeuss-MacBook-Air.local ([112.208.219.22]) by smtp.gmail.com with ESMTPSA id 22-v6sm28920897pfl.126.2018.09.11.05.36.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 05:36:57 -0700 (PDT) Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAGFBMVEUKDAg1NjRWV1V9fnyg op/DxcLk5uP8/voi63ReAAAACXBIWXMAAAWJAAAFiQFtaJ36AAAAB3RJTUUH1goZAgAz00bgXgAA AeVJREFUKM9lk0Fz2jAQhQXJD3CCO70CmcC1YMtcWyTZ14Bl69xats4N9r6/3zWQBlodNKNPu/s0 b1cCQFuZGpfVVh3vAvBJolIXRkapSuoRUtIdFyo1Y5xSdlAj7OtvD1XnXxmWRi+eWgcxyCed1lVV B1CrKyujMoi+eLA5kU1SsjoHlW+nQjTtFxk4MXgrOxvIqzoTZR8XgPaLl419zgsMaSGFPiUOZCIh thsx5Xy9NsK8Kwf/JoQgMxcVJ301HKkcSWaT0O7FY056J4U9xcYfnmVXG4801lW6lqwu2nKFZoHC HuzvaTVndZ+LaRQgZdthXw1cpynEkLEwyFHXk/aIxNQ6QeooJuzPMB+wn+D7JJNsiCcVA13/A3h/ xE9J+WidpAwoYNmRFwyvSRhNVtsdaAewzZZP5uw82QL9+tyNfocyP0McAzICUr5Mk9RdIjWasUNx aIIt6NK4ZtXIMdfMQt3nuMAyWbLI4DqZ4xPq/ag8jPond4XU/cLuOgw6XCFX/YCUfcDAMMH58fD4 G9kDchwfqVefkBwup2uZM+Q4WhJt5jN3AxXCsaS2yXEDuWgS8VOzW0gFjhEPmLyFMKBFaLb1HRwc DiaKwx0EeTMRYnYPQRW3PP4HApvlMv0PttX5v/D6Aws3IOSEwzmLAAAAAElFTkSuQmCC In-Reply-To: <83tvmwmgi7.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Sep 2018 14:16:00 +0300") 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:150220 Archived-At: --=-=-= Content-Type: text/plain On 2018-09-11 14:16 +0300, Eli Zaretskii wrote: > Would you mind submitting a patch that includes the above, and also > fixes/augments the tests accordingly? I think these changes then > could go into the emacs-26 branch, unless someone raises objections. Please find the new patch in the attachment. Thanks a lot for helping straighten this out. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=thing.diff Content-Description: thing.diff diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 6a978fe9..fdc12f32 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -221,15 +221,12 @@ The bounds of THING are determined by `bounds-of-thing-at-point'." "Return the bounds of the list at point. \[Internal function used by `bounds-of-thing-at-point'.]" (save-excursion - (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)))))) + (if (ignore-errors (up-list -1)) + (ignore-errors (cons (point) (progn (forward-sexp) (point)))) + (let ((bound (bounds-of-thing-at-point 'sexp))) + (and bound + (<= (car bound) (point)) (< (point) (cdr bound)) + bound))))) ;; Defuns @@ -608,8 +605,13 @@ Signal an error if the entire string was not used." (put 'number 'thing-at-point 'number-at-point) ;;;###autoload -(defun list-at-point () - "Return the Lisp list at point, or nil if none is found." - (form-at-point 'list 'listp)) +(defun list-at-point (&optional ignore-comment-or-string) + "Return the Lisp list at point, or nil if none is found. +If IGNORE-COMMENT-OR-STRING is non-nil comments and strings are +treated as white space." + (let ((ppss (and ignore-comment-or-string (syntax-ppss)))) + (save-excursion + (goto-char (or (nth 8 ppss) (point))) + (form-at-point 'list 'listp)))) ;;; thingatpt.el ends here diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index cfb57de6..43172f4f 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -84,41 +84,44 @@ position to retrieve THING.") (goto-char (nth 1 test)) (should (equal (thing-at-point (nth 2 test)) (nth 3 test)))))) -;; These tests reflect the actual behavior of -;; `thing-at-point-bounds-of-list-at-point'. -(ert-deftest thing-at-point-bug24627 () - "Test for https://debbugs.gnu.org/24627 ." - (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)))) - (file - (expand-file-name "lisp/thingatpt.el" source-directory)) - buf) - ;; Test for `thing-at-point'. - (when (file-exists-p file) - (unwind-protect - (progn - (setq buf (find-file file)) - (goto-char (point-max)) - (forward-line -1) - (should-not (thing-at-point 'list))) - (kill-buffer buf))) - ;; Tests for `list-at-point'. - (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))))))) +;; See bug#24627 and bug#31772. +(ert-deftest thing-at-point-bounds-of-list-at-point () + (cl-macrolet ((with-test-buffer (str &rest body) + `(with-temp-buffer + (emacs-lisp-mode) + (insert ,str) + (search-backward "|") + (delete-char 1) + ,@body))) + (let ((tests1 + '(("|(a \"b\" c)" (a "b" c)) + (";|(a \"b\" c)" (a "b" c) nil) + ("|(a \"b\" c\n)" (a "b" c)) + ("\"|(a b c)\"" (a b c) nil) + ("|(a ;(b c d)\ne)" (a e)) + ("(foo\n|(a ;(b c d)\ne) bar)" (foo (a e) bar)) + ("(foo\n|a ;(b c d)\ne bar)" (foo a e bar)) + ("(foo\n|(a \"(b c d)\"\ne) bar)" (foo (a "(b c d)" e) bar)) + ("(b\n|(a ;(foo c d)\ne) bar)" (b (a e) bar)) + ("(princ \"|(a b c)\")" (a b c) (princ "(a b c)")) + ("(defun foo ()\n \"Test function.\"\n ;;|(a b)\n nil)" + (defun foo nil "Test function." nil) + (defun foo nil "Test function." nil)))) + (tests2 + '(("|list-at-point" . "list-at-point") + ("list-|at-point" . "list-at-point") + ("list-at-point|" . nil) + ("|(a b c)" . "(a b c)") + ("(a b c)|" . nil)))) + ;; Tests for `list-at-point'. + (dolist (test tests1) + (with-test-buffer (car test) + (should (equal (list-at-point) (cl-second test))) + (when (cddr test) + (should (equal (list-at-point t) (cl-third test)))))) + (dolist (test tests2) + (with-test-buffer (car test) + (should (equal (thing-at-point 'list) (cdr test)))))))) (ert-deftest thing-at-point-url-in-comment () (with-temp-buffer --=-=-=--