unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: BobD <daycandle@gmail.com>, help-gnu-emacs@gnu.org
Subject: RE: Isearch - Incremental search with predefined initial character?
Date: Sat, 4 Oct 2014 14:58:45 -0700 (PDT)	[thread overview]
Message-ID: <cb3ba6a5-9bf4-4737-98c0-16bb36bd454c@default> (raw)
In-Reply-To: <3732af9c-0454-431c-88c5-975f34971eee@googlegroups.com>

> I wish to do incremental searches with the first character pre-
> defined, i.e. have emacs prepend a character to the characters I
> enter.
> 
> 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 ; <======= Value changed here
      ...)

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.)



  reply	other threads:[~2014-10-04 21:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-04 17:57 Isearch - Incremental search with predefined initial character? BobD
2014-10-04 21:58 ` Drew Adams [this message]
2014-10-08 20:49 ` BobD
2014-10-08 22:32   ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb3ba6a5-9bf4-4737-98c0-16bb36bd454c@default \
    --to=drew.adams@oracle.com \
    --cc=daycandle@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).