summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-03-03 18:27:51 +0000
committerRichard M. Stallman <rms@gnu.org>1994-03-03 18:27:51 +0000
commit1e8c5ac4c9bf5e8f373851c68e53f2b1c67d1c5d (patch)
treee0a34dd45096000b1e1ef0a6bb902c7dacf9ba16
parent88d00c7e26ef3a462eacc4c641177c5c7d3aa4ac (diff)
downloademacs-1e8c5ac4c9bf5e8f373851c68e53f2b1c67d1c5d.tar.gz
(current-word): Check properly for bolp. New optional arg STRICT. Doc fix.
-rw-r--r--lisp/simple.el46
1 files changed, 26 insertions, 20 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index cc847efec64..5e0c9ccdfbb 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1952,32 +1952,38 @@ With argument, do this that many times."
(interactive "p")
(kill-word (- arg)))
-(defun current-word ()
- "Return the word point is on as a string, if it's between two
-word-constituent characters. If not, but it immediately follows one,
-move back first. Otherwise, if point precedes a word constituent,
-move forward first. Otherwise, move backwards until a word constituent
-is found and get that word; if you reach a newline first, move forward
-instead."
+(defun current-word (&optional strict)
+ "Return the word point is on (or a nearby word) as a string.
+If optional arg STRICT is non-nil, return nil unless point is within
+or adjacent to a word."
(save-excursion
(let ((oldpoint (point)) (start (point)) (end (point)))
(skip-syntax-backward "w_") (setq start (point))
(goto-char oldpoint)
(skip-syntax-forward "w_") (setq end (point))
(if (and (eq start oldpoint) (eq end oldpoint))
- (progn
- (skip-syntax-backward "^w_"
- (save-excursion (beginning-of-line) (point)))
- (if (eq (preceding-char) ?\n)
- (progn
- (skip-syntax-forward "^w_")
- (setq start (point))
- (skip-syntax-forward "w_")
- (setq end (point)))
- (setq end (point))
- (skip-syntax-backward "w_")
- (setq start (point)))))
- (buffer-substring start end))))
+ ;; Point is neither within nor adjacent to a word.
+ (and (not strict)
+ (progn
+ ;; Look for preceding word in same line.
+ (skip-syntax-backward "^w_"
+ (save-excursion (beginning-of-line)
+ (point)))
+ (if (bolp)
+ ;; No preceding word in same line.
+ ;; Look for following word in same line.
+ (progn
+ (skip-syntax-forward "^w_"
+ (save-excursion (end-of-line)
+ (point)))
+ (setq start (point))
+ (skip-syntax-forward "w_")
+ (setq end (point)))
+ (setq end (point))
+ (skip-syntax-backward "w_")
+ (setq start (point)))
+ (buffer-substring start end)))
+ (buffer-substring start end)))))
(defconst fill-prefix nil
"*String for filling to insert at front of new line, or nil for none.