unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Newbie major-mode and elisp question
@ 2005-09-08  7:02 sj
  2005-09-08 16:21 ` rgb
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sj @ 2005-09-08  7:02 UTC (permalink / raw)


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, its working pretty well except for one
annoying side effect. Whenever I issue (nyquist-mode) to start a new
Nyquist process, whatever buffer I'm currently in gets switched to
fundamental-mode. I have isolated the problem to the
kill-all-local-variables statement.  Is there some other way I should be
doing this?   



(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)
      )))
    
Some background: 

There is only --one-- nyquist process at any time.  The variable
nyquist-buffer holds the buffer name for the nyquist process (needed
because I ultimately need other non-nyquist lisp running)

nyquist-program contains the local invocation to run nyquist.  Hopefully the
rest is self-explanatory. 


-- 
Remove underscores to reply
_jones_57_@_swbell_._net

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

* Re: Newbie major-mode and elisp question
  2005-09-08  7:02 Newbie major-mode and elisp question sj
@ 2005-09-08 16:21 ` rgb
  2005-09-08 17:12 ` Kevin Rodgers
  2005-09-09  5:07 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: rgb @ 2005-09-08 16:21 UTC (permalink / raw)


sj wrote:
> 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, its working pretty well except for one
> annoying side effect. Whenever I issue (nyquist-mode) to start a new
> Nyquist process, whatever buffer I'm currently in gets switched to
> fundamental-mode. I have isolated the problem to the
> kill-all-local-variables statement.  Is there some other way I should be
> doing this?
>
>
>
> (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.

a progn isn't necessary here but doesn't hurt anything
>     (progn

>       ;; Clean up any old nyquist process buffers
>       (if (get-buffer nyquist-buffer)
>    (kill-buffer nyquist-buffer))

Simply delete this line.  It's purpose is to allow a buffer's
mode to be changed without lingering artifacts from the old mode.
Since you are creating a derived mode, the mode from which
nyquist-mode derives is already doing the kill appropriately.

>       (kill-all-local-variables)

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

* Re: Newbie major-mode and elisp question
  2005-09-08  7:02 Newbie major-mode and elisp question sj
  2005-09-08 16:21 ` rgb
@ 2005-09-08 17:12 ` Kevin Rodgers
  2005-09-09  5:07 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2005-09-08 17:12 UTC (permalink / raw)


sj wrote:
 > 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, its working pretty well except for one
 > annoying side effect. Whenever I issue (nyquist-mode) to start a new
 > Nyquist process, whatever buffer I'm currently in gets switched to
 > fundamental-mode. I have isolated the problem to the
 > kill-all-local-variables statement.  Is there some other way I should be
 > doing this?

,----[ C-h f define-derived-mode RET ]
| define-derived-mode is a Lisp macro in `derived'.
| (define-derived-mode CHILD PARENT NAME &optional DOCSTRING &rest BODY)
|
| Create a new mode as a variant of an existing mode.
|
| The arguments to this command are as follow:
|
| CHILD:     the name of the command for the derived mode.
| PARENT:    the name of the command for the parent mode (e.g. `text-mode').
| NAME:      a string which will appear in the status line (e.g. 
"Hypertext")
| DOCSTRING: an optional documentation string--if you do not supply one,
|            the function will attempt to invent something useful.
| BODY:      forms to execute just before running the
|            hooks for the new mode.
|
| Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
|
|   (define-derived-mode LaTeX-thesis-mode LaTeX-mode "LaTeX-Thesis")
|
| You could then make new key bindings for `LaTeX-thesis-mode-map'
| without changing regular LaTeX mode.  In this example, BODY is empty,
| and DOCSTRING is generated by default.
|
| On a more complicated level, the following command uses `sgml-mode' as
| the parent, and then sets the variable `case-fold-search' to nil:
|
|   (define-derived-mode article-mode sgml-mode "Article"
|     "Major mode for editing technical articles."
|     (setq case-fold-search nil))
|
| Note that if the documentation string had been left out, it would have
| been generated automatically, with a reference to the keymap.
`----

-- 
Kevin Rodgers

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

* Re: Newbie major-mode and elisp question
  2005-09-08  7:02 Newbie major-mode and elisp question sj
  2005-09-08 16:21 ` rgb
  2005-09-08 17:12 ` Kevin Rodgers
@ 2005-09-09  5:07 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-09-09  5:07 UTC (permalink / raw)


> 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

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

end of thread, other threads:[~2005-09-09  5:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-08  7:02 Newbie major-mode and elisp question sj
2005-09-08 16:21 ` rgb
2005-09-08 17:12 ` Kevin Rodgers
2005-09-09  5:07 ` 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).