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.

  • How about?: (add-hook 'post-command-hook (lambda () (message "hello-world"))) and add a t to the tail end to make it buffer-local and another t if you want to append it to the existing functions already assigned to that hook (rather than pre-pending it). – lawlist Jul 29 '14 at 3:07
  • Here is a link to a strange animal that can be custom tailored, but is not necessarily scalable for other people to use -- more of an in-house job: stackoverflow.com/questions/23441478/… The post-command-hook is universal, but fires a little too often sometimes for my personal needs. – lawlist Jul 29 '14 at 3:15

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.