unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to set a file major mode in elisp
@ 2007-11-02 12:42 Mirko
  2007-11-02 13:56 ` Eric Hanchrow
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Mirko @ 2007-11-02 12:42 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

In a piece of elisp, I would like to open an existing file and set its
major mode for later editing.  This is an example of the code that I
am using

(defun diary-entry ()
  (interactive)
  (find-file "~/diary")
  (goto-char (point-max))
  (open-line 1)
  (goto-char (point-max))
... )

I will be adding an entry to the diary file, and I would like the
buffer to be in the diary mode.  Is there some way of specifying it
explicitly instead of using auto-mode-alist?

Thank you,

Mirko

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

* Re: How to set a file major mode in elisp
  2007-11-02 12:42 How to set a file major mode in elisp Mirko
@ 2007-11-02 13:56 ` Eric Hanchrow
  2007-11-02 13:58 ` Sebastian Tennant
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Hanchrow @ 2007-11-02 13:56 UTC (permalink / raw)
  To: help-gnu-emacs


    I will be adding an entry to the diary file, and I would like the
    buffer to be in the diary mode.  Is there some way of specifying it
    explicitly instead of using auto-mode-alist?

Sure -- 

    (defun diary-entry ()
      (interactive)
      (find-file "~/diary")
      (diary-mode)
;-----^^^^^^^^^^^^
      (goto-char (point-max))
      (open-line 1)
      (goto-char (point-max))
    ... )

-- 
The woods aren't any drier than they were in 2000, but there
are a lot more people with matches.
        -- Doug Chapin, Electionline.org

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

* Re: How to set a file major mode in elisp
  2007-11-02 12:42 How to set a file major mode in elisp Mirko
  2007-11-02 13:56 ` Eric Hanchrow
@ 2007-11-02 13:58 ` Sebastian Tennant
  2007-11-02 15:05 ` Bastien
       [not found] ` <mailman.2888.1194012501.18990.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 7+ messages in thread
From: Sebastian Tennant @ 2007-11-02 13:58 UTC (permalink / raw)
  To: help-gnu-emacs

Quoth Mirko <mvukovic@nycap.rr.com>:
> In a piece of elisp, I would like to open an existing file and set its
> major mode for later editing.

Local variables are designed for this purpose.

You may either use this form as the first line of your file:

 -*- mode: text; fill-column: 120 -*-

or this form at the end of the file:

 Local Variables:
 mode: text
 fill-column: 120
 End:

Now each time you visit these files, Emacs will act accordingly.

Hope this helps.

Sebastian

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

* Re: How to set a file major mode in elisp
  2007-11-02 12:42 How to set a file major mode in elisp Mirko
  2007-11-02 13:56 ` Eric Hanchrow
  2007-11-02 13:58 ` Sebastian Tennant
@ 2007-11-02 15:05 ` Bastien
       [not found] ` <mailman.2888.1194012501.18990.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 7+ messages in thread
From: Bastien @ 2007-11-02 15:05 UTC (permalink / raw)
  To: help-gnu-emacs

Mirko <mvukovic@nycap.rr.com> writes:

> In a piece of elisp, I would like to open an existing file and set its
> major mode for later editing.  This is an example of the code that I
> am using
>
> (defun diary-entry ()
>   (interactive)
>   (find-file "~/diary")
>   (goto-char (point-max))
>   (open-line 1)
>   (goto-char (point-max))
> ... )

This looks weird...

> I will be adding an entry to the diary file, and I would like the
> buffer to be in the diary mode.  Is there some way of specifying it
> explicitly instead of using auto-mode-alist?

(diary-mode) ?

-- 
Bastien

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

* Re: How to set a file major mode in elisp
       [not found] ` <mailman.2888.1194012501.18990.help-gnu-emacs@gnu.org>
@ 2007-11-02 16:54   ` Mirko
  2007-11-02 21:10     ` Peter Dyballa
       [not found]     ` <mailman.2912.1194037808.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Mirko @ 2007-11-02 16:54 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 2, 9:56 am, Eric Hanchrow <off...@blarg.net> wrote:
>     I will be adding an entry to the diary file, and I would like the
>     buffer to be in the diary mode.  Is there some way of specifying it
>     explicitly instead of using auto-mode-alist?
>
> Sure --
>
>     (defun diary-entry ()
>       (interactive)
>       (find-file "~/diary")
>       (diary-mode)
> ;-----^^^^^^^^^^^^
>       (goto-char (point-max))
>       (open-line 1)
>       (goto-char (point-max))
>     ... )
>
> --
> The woods aren't any drier than they were in 2000, but there
> are a lot more people with matches.
>         -- Doug Chapin, Electionline.org

Thank you.  I don't think I will use Sebastian's suggestion, because I
don't want to mess with the diary file format if I can avoid it.

So, I will use the (obvious)  (diary-mode)

Mirko

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

* Re: How to set a file major mode in elisp
  2007-11-02 16:54   ` Mirko
@ 2007-11-02 21:10     ` Peter Dyballa
       [not found]     ` <mailman.2912.1194037808.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Dyballa @ 2007-11-02 21:10 UTC (permalink / raw)
  To: Mirko; +Cc: help-gnu-emacs


Am 02.11.2007 um 17:54 schrieb Mirko:

> I don't want to mess with the diary file format if I can avoid it.

You don't mess with the file format if you add local variables – you  
just make it clear to GNU Emacs what is obvious for you!

I, for example, make clear that the diary file is in UTF-8:

	;; Local variables:
	;; coding: utf-8
	;; End:

and you can add

	;; mode: diary

--
Greetings

   Pete

...And always remember the last words of my grandfather, who said:
      “A truck!”          — Emo Phillips

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

* Re: How to set a file major mode in elisp
       [not found]     ` <mailman.2912.1194037808.18990.help-gnu-emacs@gnu.org>
@ 2007-11-05 13:40       ` Mirko
  0 siblings, 0 replies; 7+ messages in thread
From: Mirko @ 2007-11-05 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 2, 4:10 pm, Peter Dyballa <Peter_Dyba...@Web.DE> wrote:
> Am 02.11.2007 um 17:54 schrieb Mirko:
>
> > I don't want to mess with the diary file format if I can avoid it.
>
> You don't mess with the file format if you add local variables - you
> just make it clear to GNU Emacs what is obvious for you!
>
> I, for example, make clear that the diary file is in UTF-8:
>
>         ;; Local variables:
>         ;; coding: utf-8
>         ;; End:
>
> and you can add
>
>         ;; mode: diary
>
> --
> Greetings
>
>    Pete
>
> ...And always remember the last words of my grandfather, who said:
>       "A truck!"          - Emo Phillips

Well, I decided to "cheat" by using the "built-in" make-diary-entry.
This function will set-up the file mode correctly.

(defun hj-entry ()
  "Insert the jounral template into the diary file"
  (interactive)
  (let ((calendar-date-display-form '((substring monthname 0 3) " "
day ", " year)))
    (make-diary-entry (concat (calendar-date-string (calendar-current-
date))
			      " Journal: "))))

Thanks,

Mirko

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

end of thread, other threads:[~2007-11-05 13:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-02 12:42 How to set a file major mode in elisp Mirko
2007-11-02 13:56 ` Eric Hanchrow
2007-11-02 13:58 ` Sebastian Tennant
2007-11-02 15:05 ` Bastien
     [not found] ` <mailman.2888.1194012501.18990.help-gnu-emacs@gnu.org>
2007-11-02 16:54   ` Mirko
2007-11-02 21:10     ` Peter Dyballa
     [not found]     ` <mailman.2912.1194037808.18990.help-gnu-emacs@gnu.org>
2007-11-05 13:40       ` Mirko

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).