Mercurial > emacs
changeset 17790:3ae7560f0959
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 13 May 1997 19:52:56 +0000 |
parents | 120a8d934816 |
children | c113f8bd706c |
files | lisp/thingatpt.el |
diffstat | 1 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/thingatpt.el Tue May 13 19:51:29 1997 +0000 +++ b/lisp/thingatpt.el Tue May 13 19:52:56 1997 +0000 @@ -75,6 +75,7 @@ (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 @@ (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 @@ (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 @@ (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 @@ (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)))))