[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A couple of emacs lisp questions
From: |
Daniel Dalton |
Subject: |
Re: A couple of emacs lisp questions |
Date: |
Thu, 23 Dec 2010 12:08:59 +1100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Hi Drew,
Thanks so much for the detailed response. Please see my comments below.
On Tue, Dec 21, 2010 at 10:12:03AM -0800, Drew Adams wrote:
> > 1. I need to make 5 or 6 key bindings. I presume the way to do this is
> > to create a prefix and then put my bindings under this. So perhaps the
> > prefix could be c-c c-l and then I can create key bindings to trigger
> > certain functions i.e.e c-c c-l t toggles the functionality on/off.
> > How would I implement something like this?
>
> C-h r i prefix key RET takes you to the Emacs manual node `Prefix Keys',
> which
> provides some help.
>
I shall take a look.
> ;; Define a keymap variable for your prefix-key commands:
> (defvar my-map () "My prefix key.")
>
> ;; Define the keymap as a prefix-key command:
> (define-prefix-command 'my-map)
>
> That defines `my-map' as a command whose function definition and whose value
> are
> the same, new (empty) keymap. More info:
>
> C-h f define-prefix-command
> C-h v my-map
> C-h f my-map
>
> ;; Bind command `my-map' to a key - the prefix key:
> (global-set-key "\C-c\C-l" 'my-map)
>
> ;; Bind cmds `foo' & `bar' to `a' & `b' following the prefix key:
> (define-key my-map "a" 'foo)
> (define-key my-map "b" 'bar)
Oh, that all seems to be fairly logical and make sense.
> > How could I record the current key bindings which use c-c c-l as a
> > prefix, and then 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, I'm just
> > using hooks
> > and advice as well as interactive functions to make my work available
> > under emacs.
>
> OK, let's start over from a clean slate (new Emacs session, to get rid of
> bindings etc. we created).
>
> 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? What work is
involved to do this? Perhaps I should look at the docs. 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?
> ;; 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?
> ;; 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. Currently I have 3 or 4 toggling functions, to change different
behaviour of the mode, could I still use these? When the mode is
disabled, I suppose all my interactive latex-access functions would
still be available though through m-x?
> Dunno. Sounds like you should just display another buffer (always), and send
> the
> output you want there. See `with-current-buffer' and the like.
I think that sounds like a good idea.
>
> 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? If I
use a temp buffer, won't it get destroyed or have I misunderstood the
temp buffer setup?
> and `special-display-buffer-names'. If you do that, you can use `fit-frame'
> in
> library `fit-frame.el' to fit the frame to the buffer.
> http://www.emacswiki.org/emacs/FrameModes#ShrinkWrappedFrames
That's something else I will checkout for sure.
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?
Once again thanks very much for your comprehensive response!
Kind regards,
Daniel Dalton