When I try to comment a block of code using
comment-region in a file type emacs doesn't know the proper comment type for, then it prompts me
No comment syntax is defined. Use: so I can specify the comment character and it works.
However this only happens on modern versions of emacs. In older version that I have to use on our servers, e.g. 21.4.1 It doesn't prompt me for a character. It only says
No comment syntax is defined.
Right now my solution to this is that when I see this message, I run my own function e.g.
M-x setcomchar RET # RET
and this sets the comment character to #, or whatever else I want (90% of the time it will be #, but could also be //, -- etc) My function is as follows:
(defun setcomchar (cc) "Sets the default comment characted in the current mode" (interactive "sCharacter::") (setq comment-start cc) )
Once I've set this, I can run comment-region again and it works.
However, what I would like to achieve is effectively to replicate the behaviour seen in newer versions of emacs. Whereby if no comment is set or known about then it automatically prompts me for one. And in fact, once I enter it, it automatically does the commenting for me without a need for another M-x comment-region.
I do M-x comment-region, if there is a comment set then apply it.
Otherwise prompt me for a comment, (it would be nice for this to be pre-filled with the "#" character as it will be this one 90% of the time), then apply it without any further
M-x ing from me. Any thoughts on how to proceed with this one?
Also as a general point, how can I detect the status of a function in emacs, e.g. is there a concept of return code for something like comment-region. And since
comment-region returns the string
No comment syntax is defined, how can I get access to this string?
Thanks a lot