I'm very new to programming in Elisp so maybe the mistake is there but I'm completely stuck right now.

I wanted to make a small, simple Elisp function to remove the AUTOs from my Verilog files so I don't commit those lines to our git repository since the rest of my team doesn't use Emacs. I thought this would be a very simple task but for the life of me, I can't get flush-lines to work properly.

The regular expression I'm trying to use is \/\*AUTO\w+\*/. When I do M-x flush-lines RET \/\*AUTO\w+\*/ RET this works. So I would think the regular expression works. But when I try to do it in either my .emacs or by doing M-: (flush-lines "\/\*AUTO\w+\*/" nil (buffer-size) t) RET, it just outputs a nil. I also tried (flush-lines "\/\*AUTO\w+\*/") and (flush-lines "\/\*AUTO\w+\*/" nil (buffer-size)) and they both just output nil and don't remove the matching lines. My point is set to the top of the buffer, so I don't understand what the issue is. I can't seem to find anywhere any resources that could point me in the right direction. The closest I found was this post from a couple years ago but it goes far beyond the simple task I'm trying to do, and I seem to be suffering from a different issue than that user was.

  • 2
    After successfully completing your interactive command, you can try M-x command-history to see what Emacs thinks you did in Elisp terms. In your case, it shows the command as (flush-lines "\\/\\*AUTO\\w+\\*/" nil nil t)
    – gregoryg
    Aug 12, 2020 at 17:39
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Aug 12, 2020 at 17:41
  • 1
    @gregoryg: Please consider developing your comment into an answer. Bonus points for linking to the doc (about doubling backslashes in Lisp).
    – Drew
    Aug 12, 2020 at 17:44
  • 1
    Does this answer your question? re-search-forward Regex behavior for OR boolean
    – Drew
    Aug 12, 2020 at 17:47

1 Answer 1


The syntax for escaping elements of regular expressions can be confusing.

Once you find an interactive solution that works, a handy tip is to look at Emacs' command history:

M-x command-history

With the command given in the question, the command history shows:

(flush-lines "\\/\\*AUTO\\w+\\*/" nil nil t)

That gives the Elisp that will work. The reason all the extra escaping is necessary can be found in the following doc: Special Characters in Regular Expressions

The character \ has special meaning both in regexp and in the Lisp reader.

  • 1
    That worked! Thank you so much!
    – Rice
    Aug 13, 2020 at 11:58

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.