[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string wi
From: |
Tino Calancha |
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 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
Andreas Röhler <andreas.roehler@easy-emacs.de> 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 implementation.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>From bfc9b7fb739dfeab09c2ffd064a6ebe65a28b686 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
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
--
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
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, (continued)
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Tino Calancha, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Noam Postavsky, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Tino Calancha, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Noam Postavsky, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Tino Calancha, 2016/10/11
- bug#24627: "internal" designation [was: bug#24627: 24.5; (thing-at-point 'list) ...], Drew Adams, 2016/10/11
- bug#24627: "internal" designation [was: bug#24627: 24.5; (thing-at-point 'list) ...], Drew Adams, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Andreas Röhler, 2016/10/11
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Tino Calancha, 2016/10/12
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Andreas Röhler, 2016/10/12
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list,
Tino Calancha <=
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Andreas Röhler, 2016/10/13
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Tino Calancha, 2016/10/15
- bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list, Andreas Röhler, 2016/10/15