all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Migration from define-key to bind-key with prefix-command
@ 2015-11-09 12:55 Karl Voit
  2015-11-09 18:12 ` Alex Kost
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Voit @ 2015-11-09 12:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hi!

How can I define "define-key" commands with a global prefix-command to
bind-key(s) syntax?

I don't want to loose the ability to change my global prefix "my-map"
to a different one on one single place. I also want to keep my habit
of defining key bindings on many different places scattered all over
my init file and not on one single spot.

What I do have in my Emacs initialization file(s):

#+BEGIN_SRC elisp
(define-prefix-command 'my-map)
(global-set-key (kbd "C-c C-,") 'my-map)
(global-set-key (kbd "C-c ,") 'my-map)

[...]

;; scale text size (C-c C-, +/-)
(define-key my-map "-" 'text-scale-decrease)
(define-key my-map "+" 'text-scale-increase)

[...]

;; remove trailing whitespaces (C-c C-, " ")
(define-key my-map " " 'delete-trailing-whitespace)
#+END_SRC

What I think of (in totally wrong Elisp):

#+BEGIN_SRC elisp
(define-prefix-command 'my-map)
(global-set-key (kbd "C-c C-,") 'my-map)
(global-set-key (kbd "C-c ,") 'my-map)

[...]

;; scale text size (C-c C-, +/-)
(my-bind-key my-map "-" 'text-scale-decrease)
(my-bind-key my-map "+" 'text-scale-increase)

[...]

;; remove trailing whitespaces (C-c C-, " ")
(my-bind-key my-map " " 'delete-trailing-whitespace)
#+END_SRC

Or do I have to change my habits, get rid of my unified prefix
(my-map), and use define-key with repeating "C-c C-," prefix?

Thanks!


-- 
All in all, one of the most disturbing things today is the definitive
fact that the NSA, GCHQ, and many more government organizations are
massively terrorizing the freedom of us and the next generations.
                                                  http://Karl-Voit.at




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

* Re: Migration from define-key to bind-key with prefix-command
  2015-11-09 12:55 Migration from define-key to bind-key with prefix-command Karl Voit
@ 2015-11-09 18:12 ` Alex Kost
  2015-11-10 12:54   ` Karl Voit
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Kost @ 2015-11-09 18:12 UTC (permalink / raw)
  To: Karl Voit; +Cc: Karl Voit, help-gnu-emacs

Karl Voit (2015-11-09 15:55 +0300) wrote:

> Hi!
>
> How can I define "define-key" commands with a global prefix-command to
> bind-key(s) syntax?

Do you mean you want to use 'bind-key' package from
<https://github.com/jwiegley/use-package/>?

If so, you can use something like this:

(bind-keys
 :prefix-map my-map
 :prefix-docstring "My favourite map"
 :prefix "C-c ,"
 ("-" . text-scale-decrease)
 ("+" . text-scale-increase))

> I don't want to loose the ability to change my global prefix "my-map"
> to a different one on one single place. I also want to keep my habit
> of defining key bindings on many different places scattered all over
> my init file and not on one single spot.

You are not forced to use a single spot.  You can add keys to your map
later:

(bind-keys
 :map my-map
 ("f" . forward-char)
 ("b" . backward-char))

or:

(bind-key "RET" 'hanoi my-map)

-- 
Alex



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

* Re: Migration from define-key to bind-key with prefix-command
  2015-11-09 18:12 ` Alex Kost
@ 2015-11-10 12:54   ` Karl Voit
  2015-11-10 21:53     ` Emanuel Berg
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Voit @ 2015-11-10 12:54 UTC (permalink / raw)
  To: help-gnu-emacs

* Alex Kost <alezost@gmail.com> wrote:
> Karl Voit (2015-11-09 15:55 +0300) wrote:
>
>> How can I define "define-key" commands with a global prefix-command to
>> bind-key(s) syntax?
>
> Do you mean you want to use 'bind-key' package from
> <https://github.com/jwiegley/use-package/>?

Yes. However, I installed it from (M)Elpa directly.

> If so, you can use something like this:
>
> (bind-keys
> :prefix-map my-map
> :prefix-docstring "My favourite map"
> :prefix "C-c ,"
>  ("-" . text-scale-decrease)
>  ("+" . text-scale-increase))
>
> You are not forced to use a single spot.  You can add keys to your map
> later:
>
> (bind-keys
> :map my-map
>  ("f" . forward-char)
>  ("b" . backward-char))
>
> or:
>
> (bind-key "RET" 'hanoi my-map)

Great!

My first attempts did overwrite each other but your examples made
everything clear to me. I was able to migrate my config to bind-key
thanks to you.

Greetings from Graz/Austria!

-- 
All in all, one of the most disturbing things today is the definitive
fact that the NSA, GCHQ, and many more government organizations are
massively terrorizing the freedom of us and the next generations.
                                                  http://Karl-Voit.at




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

* Re: Migration from define-key to bind-key with prefix-command
  2015-11-10 12:54   ` Karl Voit
@ 2015-11-10 21:53     ` Emanuel Berg
  0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2015-11-10 21:53 UTC (permalink / raw)
  To: help-gnu-emacs

Karl Voit <devnull@Karl-Voit.at> writes:

>> (bind-keys
>> :prefix-map my-map
>> :prefix-docstring "My favourite map"
>> :prefix "C-c ,"
>>  ("-" . text-scale-decrease)
>>  ("+" . text-scale-increase))
>>
>> You are not forced to use a single spot. You can
>> add keys to your map later:
>>
>> (bind-keys
>> :map my-map
>>  ("f" . forward-char)
>>  ("b" . backward-char))
>>
>> or:
>>
>> (bind-key "RET" 'hanoi my-map)
>
> Great!

Sure is! Here is another way to do a new prefix
command and to have it work globally and on global
commands, if that is what you are doing:

    ;; Create a new prefix command: C-o
    (define-prefix-command 'C-o-prefix)
    (global-set-key "\C-o" 'C-o-prefix)

    ;; Assign `C-o m' to do something useful
    (global-set-key "\C-om"
       (lambda ()
         (interactive)
         (message "Humans are sure fun to watch. And from here, the look so small!") ))

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2015-11-10 21:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-09 12:55 Migration from define-key to bind-key with prefix-command Karl Voit
2015-11-09 18:12 ` Alex Kost
2015-11-10 12:54   ` Karl Voit
2015-11-10 21:53     ` Emanuel Berg

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.