views:

122

answers:

3

I'm giving ErgoEmacs mode a try to see if I can use Emacs more comfortably. Some of its keybindings are fairly intuitive, but in many cases I don't want to outright replace the defaults.

For example, in the context of ErgoEmacs' navigation shortcut structure, M-h makes sense as a replacement for C-a--but I want to be able to use both, not just M-h. I tried simply duplicating the commands:

;; Move to beginning/ending of line
(defconst ergoemacs-move-beginning-of-line-key   (kbd "C-a")) ; original
(defconst ergoemacs-move-end-of-line-key         (kbd "C-e")) ; original
(defconst ergoemacs-move-beginning-of-line-key   (kbd "M-h")) ; ergoemacs
(defconst ergoemacs-move-end-of-line-key         (kbd "M-H")) ; ergoemacs

But Emacs simply overwrites the first keybinding with the second. What's the best way to address this?

+1  A: 

Huh? Is having one and only one way for every function some golden principle of ErgoEmacs? Because normal keybinding works exactly the opposite way: you name one key at a time and specify what it should do. If a mode defines a global variable to mean "the key that end-of-line is bound to", then of course there can be only one value, but with the normal binding commands you can bind the same function to as many combinations as you like. In fact, every keybinding I have ever seen used looked either like this

(global-set-key [(meta space)] 'just-one-space)

or like this

(add-hook 'c-mode-hook 'my-c-mode-hook)
(defun my-c-mode-hook ()
  (define-key c-mode-map [(control c) b] 'c-insert-block))

if it's only for a specific mode.

Kilian Foth
Thanks, Kilian--that was the clue that led me to the answer. Turns out ErgoEmacs defines the keybinding in ergoemacs-mode.el according to a mapping, which is defined in the 'defconst' I pasted above.
Dan
+1  A: 

As it turns out, ErgoEmacs uses two files to define the keybinding. One is the main ergoemacs-mode.el file, and the other is the specific keyboard layout you select (e.g. ergoemacs-layout-us.el). The latter document creates a constant, which the former uses to create the keybinding. So while I thought I was duplicating the keybinding, I was actually changing the constant which was subsequently used for that purpose.

Solution:

In ergomacs-mode.el:

;; Move to beginning/ending of line
(define-key ergoemacs-keymap ergoemacs-move-beginning-of-line-key 'move-beginning-of-line)
(define-key ergoemacs-keymap ergoemacs-move-end-of-line-key 'move-end-of-line)
(define-key ergoemacs-keymap ergoemacs-move-beginning-of-line-key2 'move-beginning-of-line)  ; new
(define-key ergoemacs-keymap ergoemacs-move-end-of-line-key2 'move-end-of-line)  ; new

In ergoemacs-layout-us.el:

;; Move to beginning/ending of line
(defconst ergoemacs-move-beginning-of-line-key  (kbd "M-h"))
(defconst ergoemacs-move-end-of-line-key        (kbd "M-H"))
(defconst ergoemacs-move-beginning-of-line-key2 (kbd "C-a"))    ; new
(defconst ergoemacs-move-end-of-line-key2       (kbd "C-e"))    ; new
Dan
+1  A: 

To re-post reply from ergo-emacs mailing list:

Xah Lee said:

that's very easy.
in the ergoemacs-mode.el file, there's this line (load "ergoemacs-unbind") just comment it out. That should be all you need to do. However, note that ErgoEmacs keybinding defines those common shortcuts such as Open, Close, New, Save... with keys Ctrl+o, Ctrl+w, Ctrl+n, Ctrl+s etc. About 7 of them or so. So, i think some of these will hit on emacs traditional bindings with Ctrl. if you are new to ErgoEmacs and trying to explore it, you might just try starting with few keys. this page might have some useful info: http://code.google.com/p/ergoemacs/wiki/adoption thanks for checking out ErgoEmacs!
Xah ∑ http://xahlee.org/

boskom