all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Daniel Dalton'" <d.dalton@iinet.net.au>
Cc: help-gnu-emacs@gnu.org
Subject: RE: A couple of emacs lisp questions
Date: Wed, 22 Dec 2010 17:34:39 -0800	[thread overview]
Message-ID: <BE617FEE5E424D01B14CDCC04290FEA8@us.oracle.com> (raw)
In-Reply-To: <20101223010859.GA9006@gwsc.vic.edu.au>

> > > 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	other threads:[~2010-12-23  1:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-21 13:18 A couple of emacs lisp questions Daniel Dalton
2010-12-21 18:12 ` Drew Adams
2010-12-23  1:08   ` Daniel Dalton
2010-12-23  1:34     ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BE617FEE5E424D01B14CDCC04290FEA8@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=d.dalton@iinet.net.au \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.