all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
@ 2021-02-07 18:07 Steinar Bang
  2021-02-07 18:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 18:53 ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Steinar Bang @ 2021-02-07 18:07 UTC (permalink / raw)
  To: help-gnu-emacs

The up and down arrows on my laptop keyboard are worn and flaky.

(I've cleaned dirt under the arrow keys and that made them work a little
better, but I'm afraid I may have damaged the keys a bit, removing
them.  So... still a bit flaky, especially the down arrow).

Is it possible to make M-C-n a global alias for M-down, and to make
M-C-p a global alias for M-up?

I.e. make them aliases across modes?

Thanks!


- Steinar



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 18:07 Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up? Steinar Bang
@ 2021-02-07 18:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 19:08   ` Steinar Bang
  2021-02-07 18:53 ` Stefan Monnier
  1 sibling, 1 reply; 17+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-07 18:46 UTC (permalink / raw)
  To: help-gnu-emacs

Steinar Bang wrote:

> Is it possible to make M-C-n a global alias for M-down, and
> to make M-C-p a global alias for M-up?
>
> I.e. make them aliases across modes?

The only way I know is, set the key globally to whatever
function you want, then for every mode that has it to
something else, for that key map, set the same key to nil.

This was discussed here a while ago, but I don't remember in
what context. Anyway there were at least two suggestions how to
(semi-)automate the process.

Here is how I do it:

  https://dataswamp.org/~incal/emacs-init/super.el

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 18:07 Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up? Steinar Bang
  2021-02-07 18:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-07 18:53 ` Stefan Monnier
  2021-02-07 19:06   ` Steinar Bang
  2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2021-02-07 18:53 UTC (permalink / raw)
  To: help-gnu-emacs

> Is it possible to make M-C-n a global alias for M-down, and to make
> M-C-p a global alias for M-up?
>
> I.e. make them aliases across modes?

You could try something like

    (define-key input-decode-map [?\C-\M-n] [M-down])
    (define-key input-decode-map [?\C-\M-p] [M-up])


-- Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 18:53 ` Stefan Monnier
@ 2021-02-07 19:06   ` Steinar Bang
  2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 17+ messages in thread
From: Steinar Bang @ 2021-02-07 19:06 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

>> Is it possible to make M-C-n a global alias for M-down, and to make
>> M-C-p a global alias for M-up?
>> 
>> I.e. make them aliases across modes?

> You could try something like

>     (define-key input-decode-map [?\C-\M-n] [M-down])
>     (define-key input-decode-map [?\C-\M-p] [M-up])

Thanks, Stefan! That worked perfectly!

(ie. at least: it worked where I needed it most, which was moving nodes
up and down in org-mode)



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 18:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-07 19:08   ` Steinar Bang
  2021-02-07 19:26     ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Steinar Bang @ 2021-02-07 19:08 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:

> The only way I know is, set the key globally to whatever
> function you want, then for every mode that has it to
> something else, for that key map, set the same key to nil.

Thanks for responding!

I tried Stefan's approach, and that seemed to work as expected.  I.e. no
surprises so far.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 19:08   ` Steinar Bang
@ 2021-02-07 19:26     ` Stefan Monnier
  2021-02-07 20:29       ` Steinar Bang
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2021-02-07 19:26 UTC (permalink / raw)
  To: help-gnu-emacs

> I tried Stefan's approach, and that seemed to work as expected.  I.e. no
> surprises so far.

I think the "bad surprise" would be when you need to use a major mode
which places important bindings on `C-M-p` and `C-M-n` because you won't
be able to use those any more (the keys get remapped to `M-up` and `M-down`
before they're looked up in the mode's keymaps).


        Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 18:53 ` Stefan Monnier
  2021-02-07 19:06   ` Steinar Bang
@ 2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 20:25     ` Steinar Bang
  2021-02-07 20:52     ` Stefan Monnier
  1 sibling, 2 replies; 17+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-07 19:27 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> Is it possible to make M-C-n a global alias for M-down, and
>> to make M-C-p a global alias for M-up?
>>
>> I.e. make them aliases across modes?
>
> You could try something like
>
>     (define-key input-decode-map [?\C-\M-n] [M-down])
>     (define-key input-decode-map [?\C-\M-p] [M-up])

Well, then you move the problem from C-M-n to M-down... but
sure, if there is no problem with M-down, then there is
no problem.

But let me ask, what is the right way to do, e.g., I want M-i
`scroll-up-1' everywhere?

  https://dataswamp.org/~incal/emacs-init/scroll.el

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-07 20:25     ` Steinar Bang
  2021-02-07 20:52     ` Stefan Monnier
  1 sibling, 0 replies; 17+ messages in thread
From: Steinar Bang @ 2021-02-07 20:25 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:

> But let me ask, what is the right way to do, e.g., I want M-i
> `scroll-up-1' everywhere?

>   https://dataswamp.org/~incal/emacs-init/scroll.el

Hm... maybe I would be better off just doing the binding where this is a
problem?

Or maybe I should spring for a new laptop...?



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 19:26     ` Stefan Monnier
@ 2021-02-07 20:29       ` Steinar Bang
  2021-02-07 20:47         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 20:50         ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Steinar Bang @ 2021-02-07 20:29 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

>> I tried Stefan's approach, and that seemed to work as expected.  I.e. no
>> surprises so far.

> I think the "bad surprise" would be when you need to use a major mode
> which places important bindings on `C-M-p` and `C-M-n` because you won't
> be able to use those any more (the keys get remapped to `M-up` and `M-down`
> before they're looked up in the mode's keymaps).

Hm... maybe I should spring for a new laptop with a working keyboard...? :-)

(My current laptop is a cheap laptop from 2014, that has proved
surprisingly resilient...) 

On a releated note: is it possible to be able to use C-p for what down
does and C-n for what up does, when cycling through 'M-x' commands in
the minibuffer?

(I have googled on minibuffer keybinding but haven't found anything
useful) 



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 20:29       ` Steinar Bang
@ 2021-02-07 20:47         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 20:50         ` Stefan Monnier
  1 sibling, 0 replies; 17+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-07 20:47 UTC (permalink / raw)
  To: help-gnu-emacs

Steinar Bang wrote:

> On a releated note: is it possible to be able to use C-p for
> what down does and C-n for what up does, when cycling
> through 'M-x' commands in the minibuffer?

Isn't that the `minibuffer-local-map'?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 20:29       ` Steinar Bang
  2021-02-07 20:47         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-07 20:50         ` Stefan Monnier
  2021-02-26 17:28           ` Steinar Bang
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2021-02-07 20:50 UTC (permalink / raw)
  To: help-gnu-emacs

> Hm... maybe I should spring for a new laptop with a working keyboard...? :-)

Doesn't seem worth the trouble.

> (My current laptop is a cheap laptop from 2014, that has proved

So it's still younger than all my laptops ;-)

> On a releated note: is it possible to be able to use C-p for what down
> does and C-n for what up does, when cycling through 'M-x' commands in
> the minibuffer?

Sure, just tweak the bindings in `minibuffer-local-map`.
IIRC up/down are bound to previous/next-line-or-history-element, so just
bind C-p/C-n to those.


        Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-07 20:25     ` Steinar Bang
@ 2021-02-07 20:52     ` Stefan Monnier
  2021-02-07 21:01       ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2021-02-07 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

> But let me ask, what is the right way to do, e.g., I want M-i
> `scroll-up-1' everywhere?

For those rare cases where this is reeally what you want, then the
solution is usually to use `emulation-mode-map-alists`.


        Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 20:52     ` Stefan Monnier
@ 2021-02-07 21:01       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 17+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-07 21:01 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> But let me ask, what is the right way to do, e.g., I want
>> M-i `scroll-up-1' everywhere?
>
> For those rare cases

I currently have are 15 such cases including 2 prefix keys.

> where this is reeally what you want, then the solution is
> usually to use `emulation-mode-map-alists`.

OK, thanks, never heard of. A variable:

  List of keymap alists to use for emulation modes. It is
  intended for modes or packages using multiple minor-mode
  keymaps. Each element is a keymap alist just like
  ‘minor-mode-map-alist’, or a symbol with a variable binding
  which is a keymap alist, and it is used the same way.
  The "active" keymaps in each alist are used before
  ‘minor-mode-map-alist’ and
  ‘minor-mode-overriding-map-alist’.

Yeah, how do you use that? Maybe mentioned in the info
pages...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-07 20:50         ` Stefan Monnier
@ 2021-02-26 17:28           ` Steinar Bang
  2021-02-26 17:49             ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Steinar Bang @ 2021-02-26 17:28 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

>> On a releated note: is it possible to be able to use C-p for what
>> down does and C-n for what up does, when cycling through 'M-x'
>> commands in the minibuffer?

> Sure, just tweak the bindings in `minibuffer-local-map`.  IIRC up/down
> are bound to previous/next-line-or-history-element, so just bind
> C-p/C-n to those.

I've tried this:
(define-key minibuffer-local-map [C-p] 'previous-history-element)
(define-key minibuffer-local-map [C-n] 'next-history-element)

But pressing 'C-p' after doing M-x, still just outputs "Beginning of
buffer" and pressing 'C-n' still just outputs "End of buffer", which was
what I got before doing the define-key settings about.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-26 17:28           ` Steinar Bang
@ 2021-02-26 17:49             ` Stefan Monnier
  2021-02-26 18:41               ` [External] : " Drew Adams
  2021-02-26 20:40               ` Steinar Bang
  0 siblings, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2021-02-26 17:49 UTC (permalink / raw)
  To: help-gnu-emacs

> (define-key minibuffer-local-map [C-p] 'previous-history-element)
> (define-key minibuffer-local-map [C-n] 'next-history-element)

The C-n and C-p keys normally don't generate events `C-p` and `C-n`
(which are symbols) but `?\C-p` and `?\C-n` instead (which are
characters).  So use

    (define-key minibuffer-local-map [?\C-p] 'previous-history-element)
    (define-key minibuffer-local-map [?\C-n] 'next-history-element)

or

    (define-key minibuffer-local-map (kbd "C-p") 'previous-history-element)
    (define-key minibuffer-local-map (kbd "C-n") 'next-history-element)

since `kbd` is reasonably good at hiding those ugly internal details.

or

    (define-key minibuffer-local-map [(control p)] 'previous-history-element)
    (define-key minibuffer-local-map [(control n)] 'next-history-element)

Since XEmacs also tried to hide those details and Emacs does support
XEmacs's syntax here.


        Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [External] : Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-26 17:49             ` Stefan Monnier
@ 2021-02-26 18:41               ` Drew Adams
  2021-02-26 20:40               ` Steinar Bang
  1 sibling, 0 replies; 17+ messages in thread
From: Drew Adams @ 2021-02-26 18:41 UTC (permalink / raw)
  To: Stefan Monnier, help-gnu-emacs@gnu.org

> > (define-key minibuffer-local-map [C-p] 'previous-history-element)
> > (define-key minibuffer-local-map [C-n] 'next-history-element)
> 
> The C-n and C-p keys normally don't generate events `C-p` and `C-n`
> (which are symbols) but `?\C-p` and `?\C-n` instead (which are
> characters).  So use
> 
>     (define-key minibuffer-local-map [?\C-p] 'previous-history-element)
>     (define-key minibuffer-local-map [?\C-n] 'next-history-element)
> or
>     (define-key minibuffer-local-map (kbd "C-p") 'previous-history-
> element)
>     (define-key minibuffer-local-map (kbd "C-n") 'next-history-element)
> 
> since `kbd` is reasonably good at hiding those ugly internal details.
> or
>     (define-key minibuffer-local-map [(control p)] 'previous-history-
> element)
>     (define-key minibuffer-local-map [(control n)] 'next-history-
> element)

Also: https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Sequences.html



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up?
  2021-02-26 17:49             ` Stefan Monnier
  2021-02-26 18:41               ` [External] : " Drew Adams
@ 2021-02-26 20:40               ` Steinar Bang
  1 sibling, 0 replies; 17+ messages in thread
From: Steinar Bang @ 2021-02-26 20:40 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

>     (define-key minibuffer-local-map [(control p)] 'previous-history-element)
>     (define-key minibuffer-local-map [(control n)] 'next-history-element)

That was a nice syntax so I used that.

Works perfectly! Thanks, Stefan!



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-02-26 20:40 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-07 18:07 Is it possible to make M-C-p and M-C-n global aliases for M-down and M-up? Steinar Bang
2021-02-07 18:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-07 19:08   ` Steinar Bang
2021-02-07 19:26     ` Stefan Monnier
2021-02-07 20:29       ` Steinar Bang
2021-02-07 20:47         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-07 20:50         ` Stefan Monnier
2021-02-26 17:28           ` Steinar Bang
2021-02-26 17:49             ` Stefan Monnier
2021-02-26 18:41               ` [External] : " Drew Adams
2021-02-26 20:40               ` Steinar Bang
2021-02-07 18:53 ` Stefan Monnier
2021-02-07 19:06   ` Steinar Bang
2021-02-07 19:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-07 20:25     ` Steinar Bang
2021-02-07 20:52     ` Stefan Monnier
2021-02-07 21:01       ` Emanuel Berg via Users list for the GNU Emacs text editor

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.