From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Isearch - Incremental search with predefined initial character? Date: Sat, 4 Oct 2014 14:58:45 -0700 (PDT) Message-ID: References: <3732af9c-0454-431c-88c5-975f34971eee@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1412459972 18625 80.91.229.3 (4 Oct 2014 21:59:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Oct 2014 21:59:32 +0000 (UTC) To: BobD , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 04 23:59:24 2014 Return-path: Envelope-to: geh-help-gnu-emacs@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 1XaXMF-0001QU-0n for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Oct 2014 23:59:19 +0200 Original-Received: from localhost ([::1]:45447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaXME-00065s-MD for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Oct 2014 17:59:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaXLv-00065T-VA for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 17:59:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XaXLn-00069H-78 for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 17:58:59 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:20155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaXLn-000693-0k for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 17:58:51 -0400 Original-Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s94LwmOY005289 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 4 Oct 2014 21:58:49 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s94LwlCM012520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 4 Oct 2014 21:58:47 GMT Original-Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s94Lwl2P012517; Sat, 4 Oct 2014 21:58:47 GMT In-Reply-To: <3732af9c-0454-431c-88c5-975f34971eee@googlegroups.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100272 Archived-At: > I wish to do incremental searches with the first character pre- > defined, i.e. have emacs prepend a character to the characters I > enter. >=20 > E.g., if I start an i-search, and then enter "abc", emacs will > pretend I entered "Xabc". If I continue the i-search, emacs will > seek "Xabc". Just how do you want to tell Emacs to do this? 1. Do you want to hit a key during Isearch to prepend this prefix? IOW, on-demand insertion of your string? 2. Do you want a substitute for the normal `C-s', so this prefix is prepended each time you start Isearch, i.e., for every search? Is the prefix to prepend always the same (a constant string)? Your request is not specific. Try to specify it better. --- 1. Did you know that you can yank the last kill into the current search string, using `C-y'? Based on the code that does that, here is some code that you can use to yank a constant string at the end of the search string, when you hit `C-o' - #1, above. If you use it before typing anything then your prefix will be inserted before whatever you type. (defvar my-prefix "XYZ" "My Isearch prefix.") (defun my-yank-prefix (&optional prefix) "Yank PREFIX into current search string. Default is the value of `my-prefix'." (interactive) (unless prefix (setq prefix my-prefix)) (isearch-yank-string my-prefix)) (define-key isearch-mode-map "\C-o" 'my-yank-prefix) --- 2. If you want to automatically prepend your prefix each time you start Isearch - #2, above, then you can do this: Copy the code for function `isearch-mode' (from isearch.el), and change the "" binding of `isearch-string' in your copy, so that that variable is bound instead to your prefix. For example: (setq isearch-forward forward ; Initialize global vars. ... isearch-string my-prefix ; <=3D=3D=3D=3D=3D=3D=3D Value changed her= e ...) It is not usually a great idea to redefine a standard function this way, but (a) I don't see how advising the function would get this job done, and (b) I don't think there is a hook that you can use to accomplish the same thing. With luck, someone else will suggest a simpler, cleaner solution. (I would anyway question why you would want to do this.)