Subject: bug#9148: Make `comment-normalize-vars' more syntax-aware

From: Štěpán Němec <[email-masked]>
Date: Fri, 22 Jul 2011 16:52:10 +0200

Problem:
--------

Emacs currently provides relatively decent support for major modes with
multiple syntaxes, mainly via the `syntax-table' text property.

Unfortunately, even though there is a `comment-use-syntax' variable
which is apparently supposed to indicate that the comment functions
should rely on syntax information instead of `comment-prefix' and
friends, one piece is missing -- the function `comment-normalize-vars',
called at invocation of functions like {comment,uncomment}-region, still
requires `comment-start' to be set explicitly even though the syntax
information is sufficient and `comment-use-syntax' set.

Suggested solution:
-------------------

Modify `comment-normalize-vars' so that it uses the syntax information
(current syntax table, `syntax-table' text property) _only_, whenever
`comment-use-syntax' is set and this is possible.

Use case:
---------

Consider a major mode with two or more clearly separate syntaxes (Org
mode source blocks could be one example), including comments.

Even though it is possible to provide the different text extents with
different values of the `syntax-table' text property, the only way to
work around `comment-normalize-vars' not relying on them currently seems
something like the following:

(defadvice comment-normalize-vars (around use-syntax-info activate)
  (set (make-local-variable 'comment-start)
       (determine-comment-start-based-on-syntax-info))
  ad-do-it)

...which is evil, ugly and doesn't scale.

-- 
Štěpán