From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How do you scroll the screen without moving the cursor ?
Date: Wed, 8 Oct 2008 10:07:02 -0700 (PDT) [thread overview]
Message-ID: <0495effa-11ff-4c52-bcd7-e7a09f477b3f@f40g2000pri.googlegroups.com> (raw)
In-Reply-To: mailman.578.1223482753.25473.help-gnu-emacs@gnu.org
On Oct 8, 9:19 am, "Lorenzo Isella" <lorenzo.ise...@gmail.com> wrote:
> > aww cool thanks... i just tried the stuffs
>
> > this is what i ended up with ->
>
> > ;; ^E in Vi
> > (defun ctrl-e-in-vi (n)
> > (interactive "p")
> > (scroll-down n))
>
> > ;; ^Y in Vi
> > (defun ctrl-y-in-vi (n)
> > (interactive "p")
> > (scroll-up n))
>
> > (global-set-key "\M-n" 'ctrl-y-in-vi)
> > (global-set-key "\M-p" 'ctrl-e-in-vi)
>
> Hello,
> Sorry for jumping into this thread. I tried the functions above in my
> .emacs file (the only trivial difference is that I keybound them to f1
> and f2).
> They work beautifully with e.g. python, Fortran etc.. codes, but not
> with .tex files (where I use latex).
> In that case, the cursor moves when I invoke one of the functions above.
> How comes? I am not redefining any key-binding involving my f1 and f2 there.
> If needed, I can post the part of my .emacs file dealing with the
> customization of auctex, but I am not sure the problem lies there.
> Any suggestions?
> Cheers
The latex mode you are using probably defined its own binding for M-p
M-n. The rebinding of these 2 keys is actually very common.
What you want to do is to bind them back. :D
See:
• How To Reclaim Keybindings
http://xahlee.org/emacs/ergonomic_emacs_keybinding_minibuffer.html
Here's plain text version:
------------------------------
How To Reclaim Keybindings
Xah Lee, 2008-07
The following are some tips on how to reclaim keybindings.
To reclaim your binding, you'll need to find out the mode's name, then
use a hook to rebind keys in its keymap. Here's a example.
Suppose you defined:
(global-set-key (kbd "M-s") 'isearch-forward)
(global-set-key (kbd "M-S") 'isearch-backward)
You want to use M-s to repeat the search. However, once you are in the
isearch prompt, technically it is a mode named isearch-mode. In
isearch-mode, C-s is defined to run isearch-repeat-forward and M-s is
not defined. You want M-s to run isearch-repeat-forward. Here's the
code to reclaim it:
(add-hook 'isearch-mode-hook
(lambda ()
(define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
(define-key isearch-mode-map (kbd "M-S") 'isearch-repeat-backward)
)
)
In general, when you want to reclaim some bindings used in some mode,
first find out the mode's name, then the hook name would be xyz-mode-
hook, and its keymap name would typically be xyz-mode-map.
When you redefine some keys in a mode's keymap, be sure to make
bindings for the displaced commands if those commands are important to
you. (use describe-key to find out a key's binding while in that
mode.)
Reclaim Bindings for Minibuffer
The minibuffer is where emacs does prompts. It defines the following
keybindings:
Minibuffer's Keybindings Key Command
C-j exit-minibuffer
Enter exit-minibuffer
C-g abort-recursive-edit
M-n next-history-element
↑ next-history-element
M-p previous-history-element
↓ previous-history-element
M-s next-matching-history-element
M-r previous-matching-history-element
Note that several of the keys conflicts with our ergo keymap. Here's
how we fixed it in our ergo keymap dvorak:
;; reclaim some bindings used in minibuffer
(define-key minibuffer-local-map (kbd "M-p") 'kill-word)
(define-key minibuffer-local-map (kbd "M-n") 'forward-char)
(define-key minibuffer-local-map (kbd "M-r") 'forward-word)
(define-key minibuffer-local-map (kbd "M-s") 'isearch-forward)
(define-key minibuffer-local-map (kbd "<f11>") 'previous-matching-
input)
(define-key minibuffer-local-map (kbd "<f12>") 'next-matching-input)
Reference: Elisp Manual: Text-from-Minibuffer.
Reclaim Bindings for Shell
The shell mode (M-x shell), and shell command (M-!) both have M-‹key›
that conflics with our ergo keymaps. Here's how we fixed it for the
ergo keymap dvorak.
;; reclaim some binding used by shell mode and shell-command.
;; the shell mode and associated mode and commands use keys in comint-
mode-map.
(add-hook 'comint-mode-hook
(lambda ()
(define-key comint-mode-map (kbd "M-p") 'kill-word)
(define-key comint-mode-map (kbd "M-n") 'forward-char)
(define-key comint-mode-map (kbd "M-r") 'forward-word)
(define-key comint-mode-map (kbd "<f11>") 'comint-previous-matching-
input)
(define-key comint-mode-map (kbd "<f12>") 'comint-next-matching-
input)
))
Xah
∑ http://xahlee.org/
☄
next parent reply other threads:[~2008-10-08 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.578.1223482753.25473.help-gnu-emacs@gnu.org>
2008-10-08 17:07 ` Xah [this message]
2008-10-08 16:19 How do you scroll the screen without moving the cursor ? Lorenzo Isella
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0495effa-11ff-4c52-bcd7-e7a09f477b3f@f40g2000pri.googlegroups.com \
--to=xahlee@gmail.com \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).