[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c2c9e7e: Don't return whitespace for thing-at-point in whitespace
From: |
Lars Ingebrigtsen |
Subject: |
master c2c9e7e: Don't return whitespace for thing-at-point in whitespace-only buffers |
Date: |
Mon, 29 Nov 2021 11:18:57 -0500 (EST) |
branch: master
commit c2c9e7e3cbb485d4240f9c9c44694f310711e4e9
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Don't return whitespace for thing-at-point in whitespace-only buffers
* lisp/thingatpt.el (bounds-of-thing-at-point): If the buffer is
empty, return nil for most things (bug#52098).
---
lisp/thingatpt.el | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 32e6618..2d1bf20 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -106,8 +106,17 @@ valid THING.
Return a cons cell (START . END) giving the start and end
positions of the thing found."
- (if (get thing 'bounds-of-thing-at-point)
- (funcall (get thing 'bounds-of-thing-at-point))
+ (cond
+ ((get thing 'bounds-of-thing-at-point)
+ (funcall (get thing 'bounds-of-thing-at-point)))
+ ;; If the buffer is totally empty, give up.
+ ((and (not (eq thing 'whitespace))
+ (save-excursion
+ (goto-char (point-min))
+ (not (re-search-forward "[^\t\n ]" nil t))))
+ nil)
+ ;; Find the thing.
+ (t
(let ((orig (point)))
(ignore-errors
(save-excursion
@@ -149,7 +158,7 @@ positions of the thing found."
(lambda () (forward-thing thing -1))))
(point))))
(if (and (<= real-beg orig) (<= orig end) (< real-beg end))
- (cons real-beg end))))))))))
+ (cons real-beg end)))))))))))
;;;###autoload
(defun thing-at-point (thing &optional no-properties)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master c2c9e7e: Don't return whitespace for thing-at-point in whitespace-only buffers,
Lars Ingebrigtsen <=