bug-gnu-emacs
[Top][All Lists]
Advanced

[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: Andreas Röhler
Subject: bug#24627: 24.5; (thing-at-point 'list) may return a non-empty string without a list
Date: Wed, 12 Oct 2016 09:10:42 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.4.0



On 12.10.2016 06:58, Tino Calancha wrote:
Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

Hmm, what if cursor is inside a string or comment?
The list will be returned anyway as thingatpt always does.
AFAICT, skipping lists inside comments/strings would be a new feature
for this lib: better request that in a separated bug report.


BTW "list" might be more universal if understood syntactically
What about writing

(eq 4 (car (syntax-after (point))))
Agreed.  Thank you!
Here is the new patch:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 From 71da9ad4f6bbc307c5fb3f8bd0c6621312b2d4f4 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Wed, 12 Oct 2016 13:49:32 +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).
Escape '[' in doc string.
---
  lisp/thingatpt.el | 22 +++++++++-------------
  1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 6d1014b..421dcde 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -219,22 +219,18 @@ '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))))
+          (beg (if (eq 4 (car (syntax-after (point))))
+                   (point)
+                 (ignore-errors
+                   (up-list -1)
+                   (point)))))
        (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

beg still needs a check like

(not (nth 8 (parse-partial-sexp (point-min) (point))))

otherwise it could match inside a string or comment





reply via email to

[Prev in Thread] Current Thread [Next in Thread]