Function: viper-surrounding-word
viper-surrounding-word is a byte-compiled function defined in
viper-mous.el.gz.
Signature
(viper-surrounding-word COUNT CLICK-COUNT)
Documentation
Return word surrounding point according to a heuristic.
COUNT indicates how many regions to return.
If CLICK-COUNT is 1, word is a word in Vi sense.
If CLICK-COUNT is 2,then word is a Word in Vi sense.
If the character clicked on is a non-separator and is non-alphanumeric but
is adjacent to an alphanumeric symbol, then it is considered alphanumeric
for the purpose of this command. If this character has a matching
character, such as ( is a match for ), then the matching character is
also considered alphanumeric.
For convenience, in Lisp modes, - is considered alphanumeric.
If CLICK-COUNT is 3 or more, returns the line clicked on with leading and trailing space and tabs removed. In that case, the first argument, COUNT, is ignored.
Source Code
;; Defined in /usr/src/emacs/lisp/emulation/viper-mous.el.gz
(defun viper-surrounding-word (count click-count)
"Return word surrounding point according to a heuristic.
COUNT indicates how many regions to return.
If CLICK-COUNT is 1, `word' is a word in Vi sense.
If CLICK-COUNT is 2,then `word' is a Word in Vi sense.
If the character clicked on is a non-separator and is non-alphanumeric but
is adjacent to an alphanumeric symbol, then it is considered alphanumeric
for the purpose of this command. If this character has a matching
character, such as `(' is a match for `)', then the matching character is
also considered alphanumeric.
For convenience, in Lisp modes, `-' is considered alphanumeric.
If CLICK-COUNT is 3 or more, returns the line clicked on with leading and
trailing space and tabs removed. In that case, the first argument, COUNT,
is ignored."
(let ((modifiers "_")
beg skip-flag result
word-beg)
(if (> click-count 2)
(save-excursion
(beginning-of-line)
(viper-skip-all-separators-forward 'within-line)
(setq beg (point))
(end-of-line)
(setq result (buffer-substring beg (point))))
(if (and (not (viper-looking-at-alphasep))
(or (save-excursion (viper-backward-char-carefully)
(viper-looking-at-alpha))
(save-excursion (viper-forward-char-carefully)
(viper-looking-at-alpha))))
(setq modifiers
(concat modifiers
(cond ((looking-at "\\\\") "\\\\")
((looking-at "-") "C-C-")
((looking-at "[][]") "][")
((looking-at "[()]") ")(")
((looking-at "[{}]") "{}")
((looking-at "[<>]") "<>")
((looking-at "[`']") "`'")
((looking-at "\\^") "\\^")
((viper-looking-at-separator) "")
(t (char-to-string (following-char))))
)
))
;; Add `-' to alphanum, if it wasn't added and if we are in Lisp
(or (looking-at "-")
(not (string-match "lisp" (symbol-name major-mode)))
(setq modifiers (concat modifiers "C-C-")))
(save-excursion
(cond ((> click-count 1) (viper-skip-nonseparators 'backward))
((viper-looking-at-alpha modifiers)
(viper-skip-alpha-backward modifiers))
((not (viper-looking-at-alphasep modifiers))
(viper-skip-nonalphasep-backward))
(t (if (> click-count 1)
(viper-skip-nonseparators 'backward)
(viper-skip-alpha-backward modifiers))))
(setq word-beg (point))
(setq skip-flag nil) ; don't move 1 char forw the first time
(while (> count 0)
(if skip-flag (viper-forward-char-carefully 1))
(setq skip-flag t) ; now always move 1 char forward
(if (> click-count 1)
(viper-skip-nonseparators 'forward)
(viper-skip-alpha-forward modifiers))
(setq count (1- count)))
(setq result (buffer-substring word-beg (point))))
) ; if
;; FIXME: Use `buffer-substring-no-properties' above instead?
(set-text-properties 0 (length result) nil result)
result))