Word Search Function in Emacs

Dec 26th, 2006No Comments

Instead of a post about my Christmas (which was Merry, but the whole story isn’t done yet — more later!), I’m going to give you a handy Emacs function.

Before I started working here, I was told that people speak a different language, filled with terms that I wouldn’t understand. And they were right — just last week, I understood half of what someone was saying in a meeting and I figured that I have come a long way. On my first day, someone gave me a book filled with terms that I hear in such meetings. It’s been very handy — but it’s a book, not file. I asked for the raw text file and they emailed it to me. Now I can quickly search it.

But how can I search it more quickly? I could write a command-line script for it, but always have Emacs within reach — why not write an Emacs function? I’ve never quite did this before, but it turned out to be pretty easy:

 (defun mh-find-rrword(rrword )
(interactive "sRR Word to Find: ")
(find-file "h:/Plans/UpRailRoadTerms.muse")
(goto-line 1)
(re-search-forward
(concat "^" rrword ":"))
)
(global-set-key (kbd "C-c s") 'mh-find-rrword)  

Now when I want to find a term, I just do C-c s and it asks me for the word. Then it loads the file, goes to the top, and starts looking. Very nice!

Leave a Reply

You must be logged in to post a comment.