mode specific comment tag

I have added a ‘append’ file option to my editor, which works great. I would like to append the filename commented out before the text.

my question is, can I get the comment needed for single line comment from the mode that is loaded?


editing a python file. comments are #

var c = getSingleCommentType()
txt = c+fileName+"\n"+txt

obviously that is all just to get my intentions in an example.

can this be done?

Yes, you can do editor.getMode().lineComment. Note that this may be undefined for languages that don’t define a line comment prefix.


PERFECT! Thank you for your fast reply. That is exactly what I needed. I just added a undefined/null/’’ check before adding the comment.

Thank you very much.

One more question.

Can I get the beginning and end tags for comments (block) like HTML and others. So I could first check the above, then if not, wrap it with these?

Hope I explained well enough. Thank you again.

I found:

But neither return anything for htmlmixed or ‘text/html’ mime.

I figured it out. Since I am appending after the last line, I just get the mode of the last line:

var mode = cm.getModeAt({line:cm.lastLine(),ch:0});
if (mode.blockCommentStart) {

Works great! Thanks for your original help. ’