diff options
author | Richard M. Stallman <rms@gnu.org> | 1997-05-13 19:52:56 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1997-05-13 19:52:56 +0000 |
commit | 9e594a2e8ce78e4e783681e3714c7789e2d15016 (patch) | |
tree | 0264b67dddb71d06414e224a0bd0f182655a955a /lisp/thingatpt.el | |
parent | 46ed603f3e68cc502efcd386cf2fea9e26b208ae (diff) | |
download | emacs-9e594a2e8ce78e4e783681e3714c7789e2d15016.tar.gz |
(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.
Diffstat (limited to 'lisp/thingatpt.el')
-rw-r--r-- | lisp/thingatpt.el | 38 |
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." (let ((orig (point))) (condition-case nil (save-excursion + ;; Try moving forward, then back. (let ((end (progn (funcall (or (get thing 'end-op) @@ -85,9 +86,20 @@ of the textual entity that was found." (or (get thing 'beginning-op) (function (lambda () (forward-thing thing -1))))) (point)))) - (if (and beg end (<= beg orig) (<= orig end)) - (cons beg end) - ;; Try a second time, moving backward first and forward after, + (if (not (and beg (> beg orig))) + ;; If that brings us all the way back to ORIG, + ;; it worked. But END may not be the real end. + ;; So find the real end that corresponds to BEG. + (let ((real-end + (progn + (funcall + (or (get thing 'end-op) + (function (lambda () (forward-thing thing 1))))) + (point)))) + (if (and beg real-end (<= beg orig) (<= orig real-end)) + (cons beg real-end))) + (goto-char orig) + ;; Try a second time, moving backward first and then forward, ;; so that we can find a thing that ends at ORIG. (let ((beg (progn (funcall @@ -98,9 +110,15 @@ of the textual entity that was found." (funcall (or (get thing 'end-op) (function (lambda () (forward-thing thing 1))))) - (point)))) - (if (and beg end (<= beg orig) (<= orig end)) - (cons beg end)))))) + (point))) + (real-beg + (progn + (funcall + (or (get thing 'end-op) + (function (lambda () (forward-thing thing -1))))) + (point)))) + (if (and real-beg end (<= real-beg orig) (<= orig end)) + (cons real-beg end)))))) (error nil)))) ;;;###autoload @@ -189,9 +207,9 @@ a symbol as a valid THING." (defun forward-whitespace (arg) (interactive "p") (if (natnump arg) - (re-search-forward "[ \t]+\\|\n" nil nil arg) + (re-search-forward "[ \t]+\\|\n" nil 'move arg) (while (< arg 0) - (if (re-search-backward "[ \t]+\\|\n" nil nil) + (if (re-search-backward "[ \t]+\\|\n" nil 'move) (or (eq (char-after (match-beginning 0)) 10) (skip-chars-backward " \t"))) (setq arg (1+ arg))))) @@ -206,9 +224,9 @@ a symbol as a valid THING." (defun forward-symbol (arg) (interactive "p") (if (natnump arg) - (re-search-forward "\\(\\sw\\|\\s_\\)+" nil nil arg) + (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg) (while (< arg 0) - (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil nil) + (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil 'move) (skip-syntax-backward "w_")) (setq arg (1+ arg))))) |