unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* comment / uncomment region
@ 2004-07-31 21:34 exits funnel
  0 siblings, 0 replies; 7+ messages in thread
From: exits funnel @ 2004-07-31 21:34 UTC (permalink / raw)


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.

-exits

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
       [not found] <mailman.2297.1091309895.1960.help-gnu-emacs@gnu.org>
@ 2004-08-01  1:57 ` Pascal Bourguignon
  2004-08-02  2:33   ` exits funnel
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pascal Bourguignon @ 2004-08-01  1:57 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
  2004-08-01  1:57 ` Pascal Bourguignon
@ 2004-08-02  2:33   ` exits funnel
  2004-08-02 15:49   ` Kevin Rodgers
  2004-08-03  3:12   ` exits funnel
  2 siblings, 0 replies; 7+ messages in thread
From: exits funnel @ 2004-08-02  2:33 UTC (permalink / raw)



--- Pascal Bourguignon
<spam@thalassa.informatimago.com> wrote:

> 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 "//")
>            ;; ...
>            )))

Thanks, Pascal, that is exactly what I was looking
for.

-exits
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> 



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
  2004-08-01  1:57 ` Pascal Bourguignon
  2004-08-02  2:33   ` exits funnel
@ 2004-08-02 15:49   ` Kevin Rodgers
  2004-08-03  3:12   ` exits funnel
  2 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2004-08-02 15:49 UTC (permalink / raw)


Pascal Bourguignon wrote:
 > 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 "//")
 >            ;; ...
 >            )))

Those are all good suggestions, but I would recommend trying out
define-generic-mode: you can define your own major mode just by
specifying 6 values, most of which are just lists of strings
(keywords, etc.).

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
  2004-08-01  1:57 ` Pascal Bourguignon
  2004-08-02  2:33   ` exits funnel
  2004-08-02 15:49   ` Kevin Rodgers
@ 2004-08-03  3:12   ` exits funnel
  2 siblings, 0 replies; 7+ messages in thread
From: exits funnel @ 2004-08-03  3:12 UTC (permalink / raw)


> 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 "//")
>            ;; ...
>            )))

Actually, I was surprised to find that adding this to
my .emacs file didn't have any affect.  If I replaced
the setf with a call to message( ) it similarly was
not being exectued when I visited a .grammar file. 
I'm running emacs 21.3.1 on Redhat Linux.  This seems
simple enough.  Any thoughts?  Thanks.

-exits




		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
       [not found] <mailman.2535.1091502983.1960.help-gnu-emacs@gnu.org>
@ 2004-08-03  8:21 ` Pascal Bourguignon
  2004-08-03 14:16   ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Pascal Bourguignon @ 2004-08-03  8:21 UTC (permalink / raw)


exits funnel <exitsfunnel@yahoo.com> writes:

> > 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 "//")
> >            ;; ...
> >            )))
> 
> Actually, I was surprised to find that adding this to
> my .emacs file didn't have any affect.  If I replaced
> the setf with a call to message( ) it similarly was
> not being exectued when I visited a .grammar file. 
> I'm running emacs 21.3.1 on Redhat Linux.  This seems
> simple enough.  Any thoughts?  Thanks.

Sorry, there's an 's' at find-file-hooks:

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

With this variable, it works.

-- 
__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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: comment / uncomment region
  2004-08-03  8:21 ` Pascal Bourguignon
@ 2004-08-03 14:16   ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2004-08-03 14:16 UTC (permalink / raw)


> Sorry, there's an 's' at find-file-hooks:

Actually in Emacs-CVS this was fixed: you can now use find-file-hook
without the `s', as god intended.

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

> With this variable, it works.

But it's still extremely poor style.
It should really be something like

   (define-derived-mode sablecc-grammar-mode java-mode "SableCC-Gram"
     "Major mode for SableCC grammar files."
     ;; We should do something here, but we can start by leaving things as they
     ;; are in java.
     )
   (add-to-list 'auto-mode-alist '("\\.grammar\\'" . sablecc-grammar-mode))


-- Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-08-03 14:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-31 21:34 comment / uncomment region exits funnel
     [not found] <mailman.2297.1091309895.1960.help-gnu-emacs@gnu.org>
2004-08-01  1:57 ` Pascal Bourguignon
2004-08-02  2:33   ` exits funnel
2004-08-02 15:49   ` Kevin Rodgers
2004-08-03  3:12   ` exits funnel
     [not found] <mailman.2535.1091502983.1960.help-gnu-emacs@gnu.org>
2004-08-03  8:21 ` Pascal Bourguignon
2004-08-03 14:16   ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).