1

I'm trying to write an elisp program that will insert a section header and footer as a comment. For example, if I need a section called "intro" for my LaTeX document, the following would be inserted:

%----------BEGIN INTRO----------%



%-----------END INTRO-----------%

Similarly, if I need a section called "functions" in my C++ file, the following would be inserted:

//----------BEGIN FUNCTIONS----------//



//----------END FUNCTIONS-----------//

My trouble is finding a way to identify the comment pattern of the current major mode so that it can be included in the inserted string. Any insight would be appreciated.

  • 2
    What have you done to try and find an answer before posting this question? – Stefan Jan 15 '18 at 1:11
  • My research took me to syntax tables and the comment-dwim command. My plan was to try to figure out how comment-dwim knew what the comment character was in order to make its comment, but that didn't work out. Additionally, I couldn't find anything helpful via the syntax table route. I saw a bunch of stuff for making a syntax table, but nothing on how to extract the comment sequence from it. – Voytella Jan 16 '18 at 14:46
2

I'd suggest the variables comment-start and comment-end as well as the function comment-region.

  • Thank you, Stefan! I just used comment-start at the beginning of my line, and comment-end at the end. While the visual formatting isn't exactly what I had in mind, that can't really be helped, since not all languages have regional comments (LaTeX only has % while C has /* and */. Nevertheless, it's functionally perfect! Thanks for showing me these helpful variables! – Voytella Jan 16 '18 at 14:46

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.