emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

isearch-yank-word-at-point (was Re: Key map translations)


From: Christoph Scholtes
Subject: isearch-yank-word-at-point (was Re: Key map translations)
Date: Wed, 13 Apr 2011 17:06:01 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9

On 4/13/2011 1:07 AM, Deniz Dogan wrote:

This is something I've been wanting for a long time but never really
realized it. Is there really nothing similar in isearch already? Maybe
we could add it?

I reworked my function a little and the interface is slightly different. You press `C-s' to enter isearch mode and then `C-a' to select the entire word at point, much like `C-w' would select the word from point on. `Word' is in this case defined as a sequence of word and symbol constituents.

Here is the code:

(defun isearch-yank-word-at-point ()
  "Pull word at point into the search string."
  (interactive)
  ;; Only yank if point is on a word constituent or
  ;; symbol constituent per the syntax table.
  (when (or (= (char-syntax (or (char-after) 0)) ?w)
            (= (char-syntax (or (char-after) 0)) ?_))
    ;; If part of the string has been yanked to the search string
    ;; already, unwind the isearch state stack to the beginning to
    ;; start over.
    (while (not (string= isearch-string ""))
      (isearch-pop-state))

    ;; Go to beginning of word at point
    (skip-syntax-backward "w_")
    ;; and yank entire word into search string.
    (isearch-yank-internal
     (lambda ()
       (skip-syntax-forward "w_")
       (point)))))


I bind the command as follows:

(define-key isearch-mode-map (kbd "C-a") 'isearch-yank-word-at-point)

Feedback welcome. I would be happy to add this to isearch.el if people find it useful.

Christoph



reply via email to

[Prev in Thread] Current Thread [Next in Thread]