diff options
author | Leo Liu <sdl.web@gmail.com> | 2018-09-14 22:31:50 +0800 |
---|---|---|
committer | Leo Liu <sdl.web@gmail.com> | 2018-09-14 22:38:58 +0800 |
commit | 1e3b3fa6159db837fca2f2d564e51b01048a906f (patch) | |
tree | 405eb6253616b634f29433c33fbe560054bcf7d7 /lisp/thingatpt.el | |
parent | 219893a519e57a53425ea2c821ef0781f9642771 (diff) | |
download | emacs-1e3b3fa6159db837fca2f2d564e51b01048a906f.tar.gz |
Fix (thing-at-point 'list) regression (Bug#31772)
* lisp/thingatpt.el (thing-at-point-bounds-of-list-at-point): Revert
to pre 26.1 behavior. Return whole sexp at point if no enclosing
list.
(list-at-point): New optional arg to ignore comments and strings.
* test/lisp/thingatpt-tests.el
(thing-at-point-bounds-of-list-at-point): Fix and augment tests.
Diffstat (limited to 'lisp/thingatpt.el')
-rw-r--r-- | lisp/thingatpt.el | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 6a978fe96ef..79f0230a20a 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -219,17 +219,15 @@ The bounds of THING are determined by `bounds-of-thing-at-point'." (defun thing-at-point-bounds-of-list-at-point () "Return the bounds of the list at point. +Prefer the enclosing list with fallback on sexp 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 +606,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 |