branch: elpa/anzu
commit e56737531365f3d686d0cbeeb825778663dcb2ff
Author: Syohei YOSHIDA <[email protected]>
Commit: Syohei YOSHIDA <[email protected]>
Improve case when bounds-og-thing-at-point returns nil
---
anzu.el | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/anzu.el b/anzu.el
index 9a427d16ca..b944fe5adb 100644
--- a/anzu.el
+++ b/anzu.el
@@ -525,15 +525,22 @@
(defun anzu--thing-begin (thing)
(let ((bound (bounds-of-thing-at-point thing)))
- (and bound (car bound))))
-
-(defun anzu--thing-end (thing)
+ (if bound
+ (car bound)
+ (let ((fallback-bound (bounds-of-thing-at-point 'symbol)))
+ (if fallback-bound
+ (car fallback-bound)
+ (point))))))
+
+(defsubst anzu--thing-end (thing)
(let ((bound (bounds-of-thing-at-point thing)))
- (and bound (cdr bound))))
+ (if bound
+ (cdr bound)
+ (point-max))))
(defun anzu--region-begin (use-region thing backward)
(cond (current-prefix-arg (line-beginning-position))
- (thing (or (anzu--thing-begin thing) (point)))
+ (thing (anzu--thing-begin thing))
(use-region (region-beginning))
(backward (point-min))
(t (point))))
@@ -546,7 +553,7 @@
(defun anzu--region-end (use-region thing)
(cond (current-prefix-arg
(anzu--line-end-position (prefix-numeric-value current-prefix-arg)))
- (thing (or (anzu--thing-end thing) (point-max)))
+ (thing (anzu--thing-end thing))
(use-region (region-end))
(t (point-max))))