1

How would I implement a bare bones function that 're-evaluates' with every key-press? I mean key-press loosely; I'm looking to emulate the behavior of isearch and friends.

I would be using this to interactively test XPath expressions against an open nxml-mode buffer using something along the lines of buffer narrowing. For the purposes of this question though, just a function that calls message on whatever is in the minibuffer would be absolutely grand.

Sean Allred
  • 1,372

1 Answers1

1

Depending of what you want, you could cheat and use isearch-mode: its third argument (OP-FUN) is a function called after each input is processed, and its 5th argument (WORD) can be any function that will transform the string typed in isearch into a regexp to look for in the buffer.

For exemble:

(defun my-op-fun (string &optional lax)
  (let ((words (split-string string ":")))
    (mapconcat '(lambda (word) 
                  (concat "\\<" (regexp-quote word)))
               words "\\>.*")))

(defun my-isearch-beggining-of-line ()
  (interactive)
  (isearch-mode t t nil t 'my-op-fun))

if you type "foo" it will look for a word beginning with "foo", it you type "foo:bar" it will look for the "foo" word followed by some other char then "bar" as the beggining of a word.

Some regexp mastery might be needed to make this work for you.

You could also just look at the source of isearch to see how it is done.

Rémi
  • 1,506