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

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

Re: Newbie major-mode and elisp question


From: Stefan Monnier
Subject: Re: Newbie major-mode and elisp question
Date: Fri, 09 Sep 2005 01:07:13 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> I'm writing my first major mode to run Nyquist in a buffer. Nyquist is an
> extension of XLISP for audio synthesis and composition.  Nyquist-mode is a
> derivative of inferior-lisp mode,

If so, it should look somewhat similar to inferior-lisp-mode.
Or probably even use define-derived-mode directly.

> (defun nyquist-mode ()
>   (interactive)
>   (if (nyquist-has-process-p)
>       ;; If we are already live just switch to the nyquist buffer
>       (switch-to-buffer nyquist-buffer)
>     ;; Else start a new Nyquist process.
>     (progn 
>       ;; Clean up any old nyquist process buffers
>       (if (get-buffer nyquist-buffer)
>    (kill-buffer nyquist-buffer))
>       (kill-all-local-variables)
>       (run-lisp nyquist-program)
>       (switch-to-buffer "*inferior-lisp*")
>       (rename-buffer nyquist-buffer)
>       (setq major-mode 'nyquist-mode)
>       (setq mode-name "Nyquist")
>       (setq inferior-lisp-buffer nyquist-buffer)
>       (lisp-load-file nyquist-start-file)
>       (use-local-map nyquist-map)
>       (run-hooks 'nyquist-hook)
>       )))

Go read the Elisp manual, especially the part that talks about the coding
conventions to use for a major mode.  A major mode should *not* start
a process or do a switch-to-buffer.

You want to define another function, like `run-nyquist' which may do things
like `run-lisp' or `switch-to-buffer' (though I'd recommend against using
that and advise to use pop-to-buffer instead) and which will use
`nyquist-mode', defined with define-derived-mode.
    

        Stefan


reply via email to

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