From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Greg Hill Newsgroups: gmane.emacs.help Subject: Re: placing cursor at *start* of match in incremental search Date: Wed, 22 Jan 2003 11:53:29 -0800 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <3E2D7F8E.1050205@ihs.com> <3E2ED36A.4080003@ihs.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Trace: main.gmane.org 1043265947 6554 80.91.224.249 (22 Jan 2003 20:05:47 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 22 Jan 2003 20:05:47 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18bR85-0001hT-00 for ; Wed, 22 Jan 2003 21:05:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18bR78-0007NM-00 for gnu-help-gnu-emacs@m.gmane.org; Wed, 22 Jan 2003 15:04:46 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18bR68-0006nz-00 for help-gnu-emacs@gnu.org; Wed, 22 Jan 2003 15:03:44 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18bQyS-00027w-00 for help-gnu-emacs@gnu.org; Wed, 22 Jan 2003 14:55:49 -0500 Original-Received: from renfield.synergymicro.com ([153.105.4.30] helo=synergymicro.com) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18bQwh-0001KT-00 for help-gnu-emacs@gnu.org; Wed, 22 Jan 2003 14:54:00 -0500 Original-Received: from synergy.synergy.encinitas.ca.us ([153.105.4.29]) by synergymicro.com (8.9.3/8.9.3) with ESMTP id LAA10335 for ; Wed, 22 Jan 2003 11:54:46 -0800 Original-Received: from [198.17.100.22] (G-Hill-Mac [198.17.100.22])LAA15130 for ; Wed, 22 Jan 2003 11:59:46 -0800 In-Reply-To: <3E2ED36A.4080003@ihs.com> Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5881 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5881 At 10:22 AM -0700 1/22/03, Kevin Rodgers wrote: >Use the source: Good "advice" :) for those of us who can make heads or tails of it. But it's probably a bit much to ask of someone like Maciej who isn't really a lisp programmer. >`C-g' is bound in isearch-mode-map to isearch-abort, which sets >isearch-success to nil before calling isearch-done, which is what runs >isearch-mode-end-hook. So you could check isearch-success before >calling goto-char in the hook function. i.e., for someone who isn't a lisp programmer: (add-hook 'isearch-mode-end-hook (function (lambda () (if isearch-success (goto-char (match-beginning 0)))))) Seems to work. Thanks, Kevin. Incidentally, Maciej, when you are experimenting with different versions of anonymous (lambda) functions as hooks in the same Emacs session, don't forget to explicitly remove any old versions of the function from the hook variable, or you will end up executing more that one version and wondering why the new one you just added doesn't seem to work the way it should. For example, after (add-hook 'isearch-mode-end-hook (function (lambda () (goto-char (match-beginning 0))))) you should either (setq isearch-mode-end-hook nil) which will remove ALL functions from that hook, or (remove-hook 'isearch-mode-end-hook (function (lambda () (goto-char (match-beginning 0))))) which will specifically remove just that one function, before you (add-hook 'isearch-mode-end-hook (function (lambda () (if isearch-success (goto-char (match-beginning 0)))))) In case you didn't know, the *scratch* buffer, which uses lisp-interaction-mode, is the right place to do stuff like that. I don't remember what source I used to learn about how to use lisp-interaction mode. The versions I have of the GNU Emacs Manual and the GNU Emacs Lisp Reference Manual don't seem to be much help; but there really isn't much to it. Perhaps someone else can point you to a geed tutorial. --Greg