From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel 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 Message-ID: <8760tsczyc.fsf@web.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1464819778 11053 80.91.229.3 (1 Jun 2016 22:22:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jun 2016 22:22:58 +0000 (UTC) Cc: Robert Weiner To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 02 00:22:46 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b8EXA-0004xA-Ow for ged-emacs-devel@m.gmane.org; Thu, 02 Jun 2016 00:22:40 +0200 Original-Received: from localhost ([::1]:44368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8EX9-0002yo-Vi for ged-emacs-devel@m.gmane.org; Wed, 01 Jun 2016 18:22:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8EWa-0002yd-0U for emacs-devel@gnu.org; Wed, 01 Jun 2016 18:22:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8EWU-0000Ev-RS for emacs-devel@gnu.org; Wed, 01 Jun 2016 18:22:02 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:36694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8EWU-0000EF-Jp for emacs-devel@gnu.org; Wed, 01 Jun 2016 18:21:58 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1b8EWP-0004On-F9 for emacs-devel@gnu.org; Thu, 02 Jun 2016 00:21:53 +0200 Original-Received: from dslb-094-217-122-112.094.217.pools.vodafone-ip.de ([94.217.122.112]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Jun 2016 00:21:53 +0200 Original-Received: from michael_heerdegen by dslb-094-217-122-112.094.217.pools.vodafone-ip.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Jun 2016 00:21:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 57 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-094-217-122-112.094.217.pools.vodafone-ip.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux) Cancel-Lock: sha1:yoW9PykBJEP6ixhmX2Cg7WluQ1s= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:204172 Archived-At: Robert Weiner 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.