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>, <help-gnu-emacs@gnu.org>
Subject: RE: A couple of emacs lisp questions
Date: Tue, 21 Dec 2010 10:12:03 -0800	[thread overview]
Message-ID: <95C1839A334140008F8D40431F62E23B@us.oracle.com> (raw)
In-Reply-To: <20101221131820.GA24113@gwsc.vic.edu.au>

> 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	other threads:[~2010-12-21 18:12 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 [this message]
2010-12-23  1:08   ` Daniel Dalton
2010-12-23  1:34     ` Drew Adams

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=95C1839A334140008F8D40431F62E23B@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.