emacs-devel
[Top][All Lists]
Advanced

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

Re: How to get a fixed search string into the editable area of an isearc


From: Michael Heerdegen
Subject: Re: How to get a fixed search string into the editable area of an isearch.
Date: Thu, 02 Jun 2016 00:21:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux)

Robert Weiner <address@hidden> writes:

> I have a need for a command that starts an isearch with a specific
> string in the editable area that I can add and subtract characters
> from interactively during the search. I have things working with the
> following code except the string does not appear in the editable area
> even though the search is done for the fixed string. Can anyone solve
> this? I couldn't get any of the isearch-yank-* commands to do the
> right thing here either. Please help. Thanks.

I'm just a user like you, but figured out some missing elements I think.
Try this:

#+begin_src emacs-lisp
(defun my-isearch-for-string ()
  (interactive)
  (let ((isearch-mode-hook
         (cons (lambda ()
                 (setq isearch-string "test"
                       isearch-message "test"
                       isearch-yank-flag t)
                 (isearch-search-and-update))
               isearch-mode-hook)))
    (isearch-forward)))
#+end_src

You probably want to add your updating of the search ring and other
things.

AFAICT, the text displayed in the minibuffer is (based on) the current
binding of the variable `isearch-message', and it is up to you to update
it properly (it doesn't happen automatically).

`isearch-search-and-update' triggers, yes, what it says.

I'm not sure why isearch-yank-flag -> t was useful, a comment in my code
says

|    ;; Don't move cursor in reverse search.


BTW, in your code:

#+begin_src emacs-lisp
(let* ((match-str "fixed-string")
       (isearch-mode-hook
        (append '((lambda () (interactive) (setq isearch-string match-str)))
                isearch-mode-hook))))
#+end_src

there is a quoted lambda; it's better to avoid quoted lambdas for
several reasons.


HTH,

Michael.




reply via email to

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