aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-05-13 19:52:56 +0000
committerRichard M. Stallman1997-05-13 19:52:56 +0000
commit9e594a2e8ce78e4e783681e3714c7789e2d15016 (patch)
tree0264b67dddb71d06414e224a0bd0f182655a955a
parent46ed603f3e68cc502efcd386cf2fea9e26b208ae (diff)
downloademacs-9e594a2e8ce78e4e783681e3714c7789e2d15016.tar.gz
emacs-9e594a2e8ce78e4e783681e3714c7789e2d15016.zip
(forward-whitespace, forward-symbol):
Don't get error at end of buffer. (bounds-of-thing-at-point): Don't get confused when a motion function stops at end of buffer and there really isn't a thing. Avoid redundant repeated scans.
-rw-r--r--lisp/thingatpt.el38
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index fda31632aa1..de97e761e0f 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -75,6 +75,7 @@ of the textual entity that was found."
75 (let ((orig (point))) 75 (let ((orig (point)))
76 (condition-case nil 76 (condition-case nil
77 (save-excursion 77 (save-excursion
78 ;; Try moving forward, then back.
78 (let ((end (progn 79 (let ((end (progn
79 (funcall 80 (funcall
80 (or (get thing 'end-op) 81 (or (get thing 'end-op)
@@ -85,9 +86,20 @@ of the textual entity that was found."
85 (or (get thing 'beginning-op) 86 (or (get thing 'beginning-op)
86 (function (lambda () (forward-thing thing -1))))) 87 (function (lambda () (forward-thing thing -1)))))
87 (point)))) 88 (point))))
88 (if (and beg end (<= beg orig) (<= orig end)) 89 (if (not (and beg (> beg orig)))
89 (cons beg end) 90 ;; If that brings us all the way back to ORIG,
90 ;; Try a second time, moving backward first and forward after, 91 ;; it worked. But END may not be the real end.
92 ;; So find the real end that corresponds to BEG.
93 (let ((real-end
94 (progn
95 (funcall
96 (or (get thing 'end-op)
97 (function (lambda () (forward-thing thing 1)))))
98 (point))))
99 (if (and beg real-end (<= beg orig) (<= orig real-end))
100 (cons beg real-end)))
101 (goto-char orig)
102 ;; Try a second time, moving backward first and then forward,
91 ;; so that we can find a thing that ends at ORIG. 103 ;; so that we can find a thing that ends at ORIG.
92 (let ((beg (progn 104 (let ((beg (progn
93 (funcall 105 (funcall
@@ -98,9 +110,15 @@ of the textual entity that was found."
98 (funcall 110 (funcall
99 (or (get thing 'end-op) 111 (or (get thing 'end-op)
100 (function (lambda () (forward-thing thing 1))))) 112 (function (lambda () (forward-thing thing 1)))))
101 (point)))) 113 (point)))
102 (if (and beg end (<= beg orig) (<= orig end)) 114 (real-beg
103 (cons beg end)))))) 115 (progn
116 (funcall
117 (or (get thing 'end-op)
118 (function (lambda () (forward-thing thing -1)))))
119 (point))))
120 (if (and real-beg end (<= real-beg orig) (<= orig end))
121 (cons real-beg end))))))
104 (error nil)))) 122 (error nil))))
105 123
106;;;###autoload 124;;;###autoload
@@ -189,9 +207,9 @@ a symbol as a valid THING."
189(defun forward-whitespace (arg) 207(defun forward-whitespace (arg)
190 (interactive "p") 208 (interactive "p")
191 (if (natnump arg) 209 (if (natnump arg)
192 (re-search-forward "[ \t]+\\|\n" nil nil arg) 210 (re-search-forward "[ \t]+\\|\n" nil 'move arg)
193 (while (< arg 0) 211 (while (< arg 0)
194 (if (re-search-backward "[ \t]+\\|\n" nil nil) 212 (if (re-search-backward "[ \t]+\\|\n" nil 'move)
195 (or (eq (char-after (match-beginning 0)) 10) 213 (or (eq (char-after (match-beginning 0)) 10)
196 (skip-chars-backward " \t"))) 214 (skip-chars-backward " \t")))
197 (setq arg (1+ arg))))) 215 (setq arg (1+ arg)))))
@@ -206,9 +224,9 @@ a symbol as a valid THING."
206(defun forward-symbol (arg) 224(defun forward-symbol (arg)
207 (interactive "p") 225 (interactive "p")
208 (if (natnump arg) 226 (if (natnump arg)
209 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil nil arg) 227 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg)
210 (while (< arg 0) 228 (while (< arg 0)
211 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil nil) 229 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil 'move)
212 (skip-syntax-backward "w_")) 230 (skip-syntax-backward "w_"))
213 (setq arg (1+ arg))))) 231 (setq arg (1+ arg)))))
214 232