help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comment / uncomment region


From: Pascal Bourguignon
Subject: Re: comment / uncomment region
Date: 01 Aug 2004 03:57:32 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

exits funnel <exitsfunnel@yahoo.com> writes:

> Hello,
> 
> I'm having trouble getting comment-region and
> uncomment-region to work in the .grammar files I'm
> editing.  I'm pretty new to Emacs but I understnad
> they don't work because there is no major mode for
> these sablecc grammar files.  I've looked at the doc a
> bit and I understand that I have to set the variable
> comment-start to "//" but when I evaluate (setq
> comment-start) in the scratch buffer it seems to
> change the value only for that buffer.  Can anyone
> give me a jump start here?  Ideally, I'd like to be
> able to put something in my .emacs file which will set
> its value for any active .grammar file, but I'd be
> satisfied if I could at least figure out how to set it
> interactively for the current buffer.  Thanks in
> advance.

Yes, that's because comment-start is a buffer-local variable.
You have to set it in your grammar buffer.

You can do it manually with:

    M-x eval-expression RET (setq comment-start "//") RET

or rather:

    M-x set-variable    RET comment-start RET "//" RET


You could put this at the end of each of your grammar files:

// Local Variables:
// comment-start: "//"
// End:


Or, if you don't want to program a mode for your grammar files you
could have a find-file-hook that would check the file type (or file
name extension) and would initialize the buffer environment when it
finds that a grammar is being opened. Something like:

(add-hook 'find-file-hook
     (lambda () 
        (when (string-match "\\.grammar$" (buffer-file-name))
           (setf comment-start "//")
           ;; ...
           )))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein


reply via email to

[Prev in Thread] Current Thread [Next in Thread]