[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Isearch - Incremental search with predefined initial character?
From: |
BobD |
Subject: |
Re: Isearch - Incremental search with predefined initial character? |
Date: |
Wed, 8 Oct 2014 13:49:12 -0700 (PDT) |
User-agent: |
G2/1.0 |
I want a conditional substitute for the normal isearch, depending on which key
I use to start the search.
Always using the same prefix is OK; I use "{".
After fiddling a while, I came up with this, which does what I want.
I bind [lwindow] to isearch-forward and isearch-repeat-forward.
In the isearch-mode-hook function, I yank a "{" if [lwindow] started the search.
([lwindow] is the left-side Windows key on keyboards made for Windows.)
(defvar my-prefix "{" "My Isearch prefix") ;My one-char prefix
(defun rjd-prebrace ()
;Function for isearch-mode-hook
(if (equal (this-command-keys) [lwindow]) ;If invoked by
[lwindow]
(isearch-yank-string my-prefix) ; yank
the prefix
)
)
(add-hook 'isearch-mode-hook 'rjd-prebrace) ;Plant function
in hook list
(global-set-key [lwindow] 'isearch-forward) ;Plant key in
maps (Only forward direction)
(define-key isearch-mode-map [lwindow] 'isearch-repeat-forward)
Thank you very much for your help. Pointing me at (isearch-yank-string ...)
made this work.
I wish to do this so that I can search for "{abc" without typing the "{" first.
Typing something like "\C-s{abc" is exhausting.