I am trying to set isearch-string
from the command line. The purpose is to have a Perl script start Emacs with a given search string, and go directly to the first line of the string and enter search mode. For example:
$ emacs +2 t.txt -l srep.el &
with t.txt
the text file to search in, for example here is a dummy file:
a bb c
aa
aa bb c d
The Lisp file srep.el
(generated by the Perl script) sets the isearch-string
, for example:
(setq isearch-string "aa")
(isearch-search-and-update)
However, this does not work. I get a wrong-type-argument
error from the debugger.
I then modified srep.el
to :
(defun my-set-search-word()
(interactive)
(setq isearch-string "aa"))
(add-hook 'isearch-mode-hook 'my-set-search-word)
This works in the beginning. I can press C-s
to search for the string aa
, but if I try to escape isearch-mode
(press arrow up key for example) and do some editing and later try to search for another string (by pressing C-s
again) for example the string b
. I get error Failing I-search
.
I tried to solve this by changing srep.el
to:
(defun my-set-search-word()
(interactive)
(if *my-search-str-flag*
(setq isearch-string "aa")
(setq *my-search-str-flag* nil)))
(defun my-set-search-word()
(interactive)
(setq isearch-string "aa"))
(defvar *my-search-str-flag* t)
(add-hook 'isearch-mode-hook 'my-set-search-word)
But I still get same behavior. I am using Emacs 24.3 on Ubuntu 14.04.