From: Leo Liu <sdl.web@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 31772@debbugs.gnu.org, tino.calancha@gmail.com
Subject: bug#31772: 26.1; (thing-at-point 'list) regression
Date: Tue, 11 Sep 2018 20:36:53 +0800 [thread overview]
Message-ID: <m1sh2gw6qi.fsf@gmail.com> (raw)
In-Reply-To: <83tvmwmgi7.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Sep 2018 14:16:00 +0300")
[-- Attachment #1: Type: text/plain, Size: 350 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: thing.diff --]
[-- Type: text/x-patch, Size: 5310 bytes --]
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
next prev parent reply other threads:[~2018-09-11 12:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-10 3:58 bug#31772: 26.1; (thing-at-point 'list) regression Leo Liu
2018-06-10 15:03 ` Eli Zaretskii
2018-06-10 15:21 ` Tino Calancha
2018-06-11 3:17 ` Leo Liu
2018-06-11 15:06 ` Tino Calancha
2018-06-11 16:08 ` Leo Liu
2018-06-11 16:25 ` Tino Calancha
2018-09-06 10:37 ` Leo Liu
2018-09-06 19:01 ` Andreas Röhler
2018-09-07 4:42 ` Leo Liu
2018-09-07 8:17 ` Andreas Röhler
2018-09-08 0:09 ` Leo Liu
2018-09-11 8:31 ` Eli Zaretskii
2018-09-11 10:26 ` Leo Liu
2018-09-11 11:16 ` Eli Zaretskii
2018-09-11 11:52 ` Andreas Röhler
2018-09-11 12:10 ` Eli Zaretskii
2018-09-11 12:36 ` Leo Liu [this message]
2018-09-11 12:39 ` Eli Zaretskii
2018-09-14 14:55 ` Leo Liu
2018-09-15 9:06 ` Eli Zaretskii
2018-09-15 12:58 ` Leo Liu
2018-09-15 13:28 ` Eli Zaretskii
2018-06-11 16:34 ` Eli Zaretskii
2018-06-11 15:10 ` Eli Zaretskii
2018-06-11 16:36 ` Leo Liu
2018-06-11 2:32 ` Leo Liu
2018-06-11 14:58 ` Eli Zaretskii
2018-06-11 17:04 ` Leo Liu
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=m1sh2gw6qi.fsf@gmail.com \
--to=sdl.web@gmail.com \
--cc=31772@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=tino.calancha@gmail.com \
/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).