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

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

RE: A couple of emacs lisp questions


From: Drew Adams
Subject: RE: A couple of emacs lisp questions
Date: Wed, 22 Dec 2010 17:34:39 -0800

> > > restore them upon exit of the latex-access stuff.
> > > I.e. when it is disabled.
> > > Note, that I haven't created a minor or major mode...
> > 
> > You don't want the prefix key defined globally, but just in 
> > your (minor) mode.
> 
> Are you suggesting I should make my code into a minor mode? 

I guess so. Actually, I thought you were suggesting it. ;-)  Why not?

> What work is involved to do this?

I just did it:

(define-minor-mode latax-mode "LaTeX access mode."
  nil " LaTax" latax-mode-map)

That's all there is to it, if all you want to do is provide some keys bound to
some commands.  If you want to do more, then put that in the BODY of
`define-minor-mode', i.e., after the map.

> Perhaps I should look at the docs. 

Or look at some examples in the directory .../lisp/.  It can be really simple,
depending on what you need.

> Currently I just
> have about a dozen different functions, most interactive which are
> called when necessary. I use hooks and advice to make my code
> execute... How different would my implementation have to be 
> if I built a
> minor mode? Would I have to change much? And what benefits would there
>  be in doing this?

I don't know what you do with the hooks and advice. But a minor mode is useful
for the key-binding case you described: have some keys active only while in the
mode.  And a minor mode can be either per-buffer or global.

A minor mode is much easier to define than a major mode.

> > ;; Create a keymap for your minor mode, and define the mode.
> > (defvar latax-mode-map (make-sparse-keymap)
> >   "LaTeX access minor mode keymap.")
> > 
> > (define-minor-mode latax-mode "LaTeX access mode."
> >   nil " LaTax" latax-mode-map)
> 
> What is the Latax-mode stuff for? I thought we are creating a 
> minor mode for latex-access?

I was being cute (trying to be).  Call it `latex-access-mode' instead of
`latax-mode', if you like.  Call it anything you like.
`C-h f define-minor-mode'.

> > ;; Create the prefix-key keymap.
> > (defvar latax-prefix-map nil
> >   "LaTeX access mode prefix keymap.")
> > 
> > ;; Bind command `latax-prefix-map' to `C-c C-l' in `latex-mode-map':
> > (define-key latax-mode-map "\C-c\C-l" 'latax-prefix-map)
> > 
> > ;; Bind other commands in the prefix map:
> > (define-key latax-prefix-map "a" 'forward-char)
> > (define-key latax-prefix-map "b" 'emacs-version)
> > 
> > Turn on/off the minor mode: `M-x latax-mode'.
> 
> Oh I think I understand now. So where should this code go? In a
> particular function definition? Or just straight in the .el
> file.

Top level in a *.el file.

> Currently I have 3 or 4 toggling functions, to change different
> behaviour of the mode, could I still use these? 

Sure. But to toggle the mode on/off you don't need anything - just use the mode
command `latex-access-mode' (it's a toggle).

> When the mode is
> disabled, I suppose all my interactive latex-access functions would
> still be available though through m-x?

Yes.

> > For fitting the window to the buffer, see 
> > `resize-temp-buffer-window' and `fit-window-to-buffer'.
> > 
> > You can also use a separate frame for the buffer - see 
> > `special-display-regexps'
> 
> I had a play, only thing that was a bit annoying, which I 
> wouldn't mind removing is the header and mode lines from
> the output buffer... I was just using a standard buffer,
> is this different for temp buffer?

Yes, a bit. But you might not care about the differences. Just try stuff and see
what it does for you.

> If I use a temp buffer, won't it get destroyed or have
> I misunderstood the temp buffer setup? 

Not necessarily. *Help* is a temp buffer, but nothing requires you to delete the
buffer or even close its window.

> I'm probably going to have a go at implementing this in the 
> next week or so (after Christmas), may I contact you directly
> if I run into problems?

You can, but it's better to use the mailing list or Emacs Wiki.  They are great
resources, and it helps to get multiple perspectives and input.  Your other
friend is the Elisp manual - use `i' in the manual to look things up.




reply via email to

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