[Top][All Lists]

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

Modal Keyboard Layout for EMACS

From: Junia
Subject: Modal Keyboard Layout for EMACS
Date: Thu, 22 Nov 2012 12:04:11 -0800 (PST)
User-agent: G2/1.0

I would like to write a small VI emulator for Emacs. By small, I mean really 
small. The source code should not go beyond 100 lines. I also need a better 
keyboard map than one can find in VIM. The ESC key should be replaced by a key 
that a typist can easily reach with the right hand.

My first idea was to substitute the [ square bracket for ESC. This substitution 
is nice since people often uses ^[ to represent ESC. If the typist needs a [ 
square bracket, she can press the [ square bracket key twice. If she presses 
the [ key once, Emacs enters the normal command mode, that appears as <N> on 
the mode-line. The program below works fine with the [ square bracket.

The problem is that Dvořák layout places the [ square bracket at the upper 
right hand side corner of the keyboard. In fewer words, the position of the [ 
square bracket in Dvořák layout is not easy to reach. As a matter of fact, it 
is almost as bad as the Esc position in VIM. Therefore, I decided to use / 
slash instead of [ square bracket. 

However, if I replace / slash for the square bracket, the program below does 
not work correctly. I mean, it ignores my remap of the / slash key. If I press 
slash after replacing / slash for the occurrences of [ the program fails to 
enter normal command mode.

Can anybody tell me why?

;; Variables for possible keyboards
(defvar default-keyboard 
   (copy-keymap (current-global-map)))

(defvar emap 
    (copy-keymap (current-global-map)))
(defun tovim()  (interactive)
    (setq minor-mode-alist
      (assq-delete-all 'normal minor-mode-alist))
    (add-to-list 'minor-mode-alist '(normal "<N>"))
    (use-global-map vmap))
(define-key emap "[" 'tovim)

(defvar vmap
    (copy-keymap (current-global-map)))
(define-key vmap (kbd "h") 'backward-char)
(define-key vmap (kbd "j") 'next-line)
(define-key vmap (kbd "k") 'previous-line)
(define-key vmap (kbd "l") 'forward-char)
(defun ademacs()
   (setq minor-mode-alist
    (assq-delete-all 'normal minor-mode-alist))
  (add-to-list 'minor-mode-alist '(normal "<I>"))
  (use-global-map emap) )
(defun toemacs()  (interactive)
(define-key vmap (kbd "i") 'toemacs)
(defun slash()(interactive)
   (ademacs) ; type twice for [
   (insert "["))
(define-key vmap (kbd "[") 'slash)

(defun puremacs()
   (use-global-map default-keyboard))

(define-minor-mode normal
       :init-value nil
       :lighter " <N> " 
       :keymap '(emap) 
      :group 'normal
   (if   normal   (ademacs) (puremacs) ))

(define-globalized-minor-mode gnormal normal
    (lambda()  (normal t)))   

(provide 'normal)

reply via email to

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