0

Sometimes, i wish to mark all code in a file as comments. I tried putting all code between the markups #|| and #||. On file loading, emacs threw the error,

Invalid read syntax: #

I can't use #+nil, because the file has multiple statements and not a single function. Is there a way to comment?

5
  • 2
    What about selecting the region you want to comment first, then calling the comment-region function? – Nsukami _ Apr 25 '15 at 2:58
  • 4
    This will do it C-x h M-; – Kaushal Modi Apr 25 '15 at 3:36
  • 1
    As @kaushalmodi suggests, you can use M-; after selecting the buffer text. But be aware that if you use M-; on a region that is already completely commented out then it becomes uncommented, instead of becoming nested in a new comment level. I generally use comment-region instead of M-;, as it is more flexible (IMO) in this regard. It always comments, except with C-u, where it removes a level of commenting. (Bind comment-region to a key.) – Drew Apr 25 '15 at 14:46
  • i did see, that M-x comment-region retains existing comments as it is and just adds two extra semicolons in the line beginning. But i didn't know C-h M-; will uncomment already commented lines. – Madhavan Apr 25 '15 at 14:49
  • 1
    @MadhavanKumar M-; will uncomment only if every line in the selected region is already a comment. For your use case, if your whole file is already commented out, M-; will uncomment it. But then, why would you want to comment an already completely commented out file? Let's say you have a commented line and an uncommented line. Now if you select those 2 lines and do M-;, you will end up with that first line double commented and the second line single commented. – Kaushal Modi Apr 25 '15 at 20:18
1

Select the whole buffer (C-x h) and comment it (M-;).

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.