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: Tue, 21 Dec 2010 10:12:03 -0800

> 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.

;; 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)

C-h k C-c C-l a
-> "C-c C-l a runs the command foo, which is"

> 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.

[And you apparently do want to use a prefix key for this stuff, so you won't
override some global or major-mode binding with a minor-mode binding.  If you
didn't care about that, then you could just forget about `C-c C-l' (a prefix
key) and bind your commands to any keys you wanted in the minor-mode map.]

So you need two keymaps: a minor-mode map and a prefix-key map.

;; 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)

;; 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'.

> 2. ... The translation in the echo area must be on screen at
> all times... and is updated when post-command hook is triggered.
> However, this is blocking important emacs messages.... My idea was to
> create some kind of minibuffer or window at the bottom of screen so I
> wouldn't interrupt the echo area.
> I would like the window to shrink/grow depending on how many lines
> I need to display.  What would the best way of doing this be?

Dunno. Sounds like you should just display another buffer (always), and send the
output you want there.  See `with-current-buffer' and the like.

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'
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

HTH.




reply via email to

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