Function: viper-mouse-click-search-word
viper-mouse-click-search-word is an interactive and byte-compiled
function defined in viper-mous.el.gz.
Signature
(viper-mouse-click-search-word CLICK N)
Documentation
Find the word clicked or double-clicked on. Word may be in another window.
With prefix argument, N, search for N-th occurrence.
This command must be bound to a mouse click. The double-click action of the
same button must not be bound (or it must be bound to the same function).
See viper-surrounding-word for the details on what constitutes a word for
this command.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/emulation/viper-mous.el.gz
(defun viper-mouse-click-search-word (click arg)
"Find the word clicked or double-clicked on. Word may be in another window.
With prefix argument, N, search for N-th occurrence.
This command must be bound to a mouse click. The double-click action of the
same button must not be bound \(or it must be bound to the same function).
See `viper-surrounding-word' for the details on what constitutes a word for
this command.
\n(fn CLICK N)"
(interactive "e\nP")
(if viper-frame-of-focus ;; to handle clicks in another frame
(select-frame viper-frame-of-focus))
(if (save-excursion
(or (not (eq (key-binding viper-mouse-down-search-key-parsed)
'viper-mouse-catch-frame-switch))
(not (eq (key-binding viper-mouse-up-search-key-parsed)
'viper-mouse-click-search-word))))
() ; do nothing, if binding isn't right or not over text
(let ((previous-search-string viper-s-string)
click-word click-count)
(if (and
(viper-multiclick-p)
;; This trick checks if there is a pending mouse event if so, we use
;; this latter event and discard the current mouse click If the next
;; pending event is not a mouse event, we execute the current mouse
;; event
(progn
(read-event)
(viper-mouse-event-p last-input-event)))
(progn ; interrupted wait
(setq viper-global-prefix-argument (or viper-global-prefix-argument
arg)
;; remember command that was before the multiclick
this-command last-command))
;; uninterrupted wait
(setq click-count (event-click-count click))
(setq click-word (viper-mouse-click-get-word click nil click-count))
(if (> click-count 1)
(setq arg viper-global-prefix-argument
viper-global-prefix-argument nil))
(setq arg (or arg 1))
(deactivate-mark)
(if (or (not (string= click-word viper-s-string))
(not (markerp viper-search-start-marker))
(not (equal (marker-buffer viper-search-start-marker)
(current-buffer)))
(not (eq last-command 'viper-mouse-click-search-word)))
(progn
(setq viper-search-start-marker (point-marker)
viper-local-search-start-marker viper-search-start-marker
viper-mouse-click-search-noerror t
viper-mouse-click-search-limit nil)
;; make search string known to Viper
(setq viper-s-string (if viper-re-search
(regexp-quote click-word)
click-word))
(if (not (string= viper-s-string (car viper-search-history)))
(setq viper-search-history
(cons viper-s-string viper-search-history)))
))
(push-mark nil t)
(while (> arg 0)
(viper-forward-word 1)
(condition-case nil
(progn
(if (not (search-forward
click-word viper-mouse-click-search-limit
viper-mouse-click-search-noerror))
(progn
(setq viper-mouse-click-search-noerror nil)
(setq viper-mouse-click-search-limit
(save-excursion
(if (and
(markerp viper-local-search-start-marker)
(marker-buffer viper-local-search-start-marker))
(goto-char viper-local-search-start-marker))
(viper-line-pos 'end)))
(goto-char (point-min))
(search-forward click-word
viper-mouse-click-search-limit nil)))
(goto-char (match-beginning 0))
(message "Searching for: %s" viper-s-string)
(if (<= arg 1) ; found the right occurrence of the pattern
(progn
(viper-adjust-window)
(viper-flash-search-pattern)))
)
(error (beep 1)
(if (or (not (string= click-word previous-search-string))
(not (eq last-command 'viper-mouse-click-search-word)))
(message "`%s': String not found in %s"
viper-s-string (buffer-name (current-buffer)))
(message
"`%s': Last occurrence in %s. Back to beginning of search"
click-word (buffer-name (current-buffer)))
(setq arg 1) ;; to terminate the loop
(sit-for 2))
(setq viper-mouse-click-search-noerror t)
(setq viper-mouse-click-search-limit nil)
(if (and (markerp viper-local-search-start-marker)
(marker-buffer viper-local-search-start-marker))
(goto-char viper-local-search-start-marker))))
(setq arg (1- arg)))
))))