help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you scroll the screen without moving the cursor ?


From: Xah
Subject: Re: How do you scroll the screen without moving the cursor ?
Date: Wed, 8 Oct 2008 10:07:02 -0700 (PDT)
User-agent: G2/1.0

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/

reply via email to

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