Вопрос

In emacs, I would like to rebind the top row of my keyboard [1...0] so that hitting an unmodified key results in its shifted equivalent. That is, typing 1234567890 would result in !"£$%^&*() being inserted in the buffer.

I am using emacs 24.1.1 in Windows Vista, with viper-mode enabled. I am doing some Common Lisp programming using slime. I use viper so that I can avoid using Ctrl and Shift too often as I can get a bit of emacs pinkie (RSI). Having started programming in lisp, I have found that hitting S-9 and S-0 to open and close parentheses is starting to take its toll.

By including the following in my start-up file, I can bind "9" to "(" and vice-versa.

(defvar my-keymap
    (let ((map (make-sparse-keymap)))
    (define-key map (kbd "9") '(lambda () (interactive) (insert "(")))
    (define-key map (kbd "(") '(lambda () (interactive) (insert "9")))
    map))

(viper-modify-major-mode
    'lisp-mode
    'insert-state
    my-key-map)

This works well enough and is easily extended to the rest of the row, except that I would like to be able to toggle between the two modes without having to hold down shift (say, by toggling Caps Lock).

Is there any way to do this, or am I approaching it all wrong?

Thanks

B

Это было полезно?

Решение

Here's an example I quickly hacked together, tested it in Emacs24 on Linux:

(setq viper-mode-key-mapping "custom")

(defvar custom-viper-keymap
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "9") '(lambda () (interactive) (insert "(")))
      (define-key map (kbd "(") '(lambda () (interactive) (insert "9")))
      map))

(defvar default-viper-keymap
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "9") '(lambda () (interactive) (insert "9")))
      (define-key map (kbd "(") '(lambda () (interactive) (insert "(")))
      map))


(defun switch-viper-mode-custom-keymap () 
  (interactive) 
  (if (string= viper-mode-key-mapping "default")
      (progn (setq viper-mode-key-mapping "custom")
         (viper-modify-major-mode 'lisp-mode 'insert-state custom-viper-keymap))
    (progn (setq viper-mode-key-mapping "default")
       (viper-modify-major-mode 'lisp-mode 'insert-state default-viper-keymap))))

(global-set-key [(control f1)] 'switch-viper-mode-custom-keymap)

When I have viper-mode activated, pressing CTRL-F1 switches the keyboard mapping from custom to normal.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top