all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to define a comment syntax for files having a specific extension?
@ 2007-04-02  8:53 gento
  2007-04-02 14:01 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: gento @ 2007-04-02  8:53 UTC (permalink / raw)
  To: help-gnu-emacs

Hi All, I'm using
"GNU Emacs 21.2.1 (i686-pc-cygwin, X toolkit) of 2004-03-22 on cm-
test"
and working on journal text files *.jou for which the commented lines
must start with the character "/".

While editing one of such files I need to run
M-: (setq comment-start "/")
in order to comment regions with the sequence C-c;

I'd like to have emacs recognize the "*.jou" files and
apply the corresponding comment syntax automatically,
sparing me from having to type
M-: (setq comment-start "/")
each time I start working on a *.jou file.

I appreciate any help

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

* Re: how to define a comment syntax for files having a specific extension?
  2007-04-02  8:53 how to define a comment syntax for files having a specific extension? gento
@ 2007-04-02 14:01 ` Stefan Monnier
  2007-04-02 15:23   ` gento
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2007-04-02 14:01 UTC (permalink / raw)
  To: help-gnu-emacs

> and working on journal text files *.jou for which the commented lines
> must start with the character "/".

> While editing one of such files I need to run
> M-: (setq comment-start "/")
> in order to comment regions with the sequence C-c;

> I'd like to have emacs recognize the "*.jou" files and
> apply the corresponding comment syntax automatically,
> sparing me from having to type
> M-: (setq comment-start "/")
> each time I start working on a *.jou file.

You need to create a major mode for those types of files.
Check out sample-mode.el


        Stefan

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

* Re: how to define a comment syntax for files having a specific extension?
  2007-04-02 14:01 ` Stefan Monnier
@ 2007-04-02 15:23   ` gento
  2007-04-03  7:30     ` Pascal Bourguignon
  2007-04-03  8:27     ` Tim X
  0 siblings, 2 replies; 6+ messages in thread
From: gento @ 2007-04-02 15:23 UTC (permalink / raw)
  To: help-gnu-emacs

> You need to create a major mode for those types of files.
> Check out sample-mode.el

Thank you Stefan.

Is there a simplest way for reaching this scope,
for example by modifying the ~/.emacs file only?

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

* Re: how to define a comment syntax for files having a specific extension?
  2007-04-02 15:23   ` gento
@ 2007-04-03  7:30     ` Pascal Bourguignon
  2007-04-03 10:51       ` gento
  2007-04-03  8:27     ` Tim X
  1 sibling, 1 reply; 6+ messages in thread
From: Pascal Bourguignon @ 2007-04-03  7:30 UTC (permalink / raw)
  To: help-gnu-emacs

"gento" <gento_distefano@hotmail.com> writes:

>> You need to create a major mode for those types of files.
>> Check out sample-mode.el
>
> Thank you Stefan.
>
> Is there a simplest way for reaching this scope,
> for example by modifying the ~/.emacs file only?

Well, there is first the simpliest way to do it: insert a file
variable comment in these files. (info "(emacs)File Variables")

/ -*- mode:text; comment-start:"/"; coding:utf-8 

on the first or second line, or:

/ Local Variables:
/ mode: text
/ comment-start: "/"
/ coding: utf-8
/ End:

at the end.



You don't necessarily need to make a major mode, you can put any
function in auto-mode-alist.

(require 'cl)
(push `(\\.jou$" . ,(lambda ()
                       (text-mode)
                       (setf comment-start "/"))) 
      auto-mode-alist)

should work (not tested).


Also you could do it with a find-file-hook, etc.

-- 
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org

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

* Re: how to define a comment syntax for files having a specific extension?
  2007-04-02 15:23   ` gento
  2007-04-03  7:30     ` Pascal Bourguignon
@ 2007-04-03  8:27     ` Tim X
  1 sibling, 0 replies; 6+ messages in thread
From: Tim X @ 2007-04-03  8:27 UTC (permalink / raw)
  To: help-gnu-emacs

"gento" <gento_distefano@hotmail.com> writes:

>> You need to create a major mode for those types of files.
>> Check out sample-mode.el
>
> Thank you Stefan.
>
> Is there a simplest way for reaching this scope,
> for example by modifying the ~/.emacs file only?
>

If the only issue is defining what emacs things is a comment, couldn't youjust
modify the syntax table and set the appropriate value to mark the comment
character? 

If not, its *really* easy to define a derived mode. You could derive a specific
mode for these files from text or fundamental mode. There is an example of a
derived mode on the meacs wiki I think (http://www.emacswiki.org).

tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: how to define a comment syntax for files having a specific extension?
  2007-04-03  7:30     ` Pascal Bourguignon
@ 2007-04-03 10:51       ` gento
  0 siblings, 0 replies; 6+ messages in thread
From: gento @ 2007-04-03 10:51 UTC (permalink / raw)
  To: help-gnu-emacs

> (require 'cl)
> (push `(\\.jou$" . ,(lambda ()
>                        (text-mode)
>                        (setf comment-start "/")))
>       auto-mode-alist)

It has worked !

> Also you could do it with a find-file-hook, etc.

I've  actually preferred this solution

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

that I have adapted on the basis of your post
http://groups.google.it/group/gnu.emacs.help/msg/83d7d3c1217a98b2

thank you

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

end of thread, other threads:[~2007-04-03 10:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-02  8:53 how to define a comment syntax for files having a specific extension? gento
2007-04-02 14:01 ` Stefan Monnier
2007-04-02 15:23   ` gento
2007-04-03  7:30     ` Pascal Bourguignon
2007-04-03 10:51       ` gento
2007-04-03  8:27     ` Tim X

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.