I have a plain text dictionary in which each headword is matched by

^# \(† \)?headword,

How can I make a custom search function that relieves me of typing the whole regex every time I want to look up a word? I tried recording a keyboard macro, but that didn't work.


Something like this might do. I wasn't sure how you store the dictionary though.

(defun my-search (word)
  (interactive "sWord: ")
  ;; some code to open your dictionary file
  (goto-char (point-min))
  (re-search-forward (format "^# \\(† \\)?%s," word) nil t))
  • Thanks. The dictionary is in one file, I didn't think about looking up from another buffer. Anyway, this doesn't seem to work .. – Toothrot Oct 24 '16 at 9:57
  • What does it do? more importantly, what do you expect it to do? All that code should do is prompt for a word, open a file (that code is missing), and search forward to the match. – John Kitchin Oct 24 '16 at 10:58
  • It doesn't find what I search for. For example, I have a line beginning with # pugilist, but that isn't found with the function. I get prompted for a search word, but after I have entered pugilist nothing happens. (Correction: point is moved to top of file.) – Toothrot Oct 24 '16 at 11:45
  • That probably means the regexp is wrong. What is the cross symbol in the parens? If you delete († )? Does it work? – John Kitchin Oct 24 '16 at 12:06
  • Should that matter with the question mark there? I've tested it manually and it works. (The dagger I think is put in front of obsolete words.) – Toothrot Oct 24 '16 at 19:06

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.