I have a programming language I want to make a major mode for where both the start and the end characters of a comment are the same. Specifically
# This is a comment #
As you can see it can match either multiple lines as well as single lines.
Single lines are no problem, that can be done with this regex in a
However the problem occurs on multiple line comments. Due to the start and the end being the same Emacs sometimes misjudges which part of the code is actually a comment, especially if one part of the comment is off-screen.
# This is a comment and should always be recognized # This isn't a comment but is sometimes recognized if the top is off screen # This is a comment and is always recognized but sometimes isn't if the last block is wrongly detected as a comment #
I've also tried this code set as the
(defconst amanatsu-comment-regex "\\(#\\([^#]*?\\)#\\)" ) (defun amanatsu-syntax-propertize-function (start end) (save-excursion (goto-char start) (while (re-search-forward amanatsu-comment-regex end 'noerror) (let ((a (match-beginning 1)) (b (match-end 1)) (comment-fence (string-to-syntax "!"))) (put-text-property a (1+ a) 'syntax-table comment-fence) (put-text-property (1- b) b 'syntax-table comment-fence)))))
but this occasionally suffers the same off-screen errors.