Personal tools
You are here: Home ブログ sugawara Stuff swapley.el
« December 2010 »
Su Mo Tu We Th Fr Sa
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Recent entries
jlineで日本語を使えるようにする。 sugawara 2009-12-10
五反田Emacsの資料 sugawara 2009-10-19
trac-ticket.el sugawara 2007-11-19
Emacs Lisp 勉強会(バッファとウィンドウ編) sugawara 2007-10-22
Categories
Emacs
勉強会
java
 
Document Actions

swapley.el

Click here to get the file

Size 2.4 kB - File type text/x-emacs-lisp

File contents

;;; swapley.el --- key swapping mode.

;; Copyright (C) 2008  Taiki SUGAWARA

;; Author: Taiki SUGAWARA <buzz.taiki@gmail.com>
;; Keywords: convenience, hentai

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This mode provides key swappings.
;; `swapley-key-alist' define the swapped key pairs. Defualt definition translate number and symbols.

;;; Code:

(defvar swapley-key-alist
  '((?1 . ?!)
    (?2 . ?\")
    (?3 . ?#)
    (?4 . ?$)
    (?5 . ?%)
    (?6 . ?&)
    (?7 . ?')
    (?8 . ?\()
    (?9 . ?\))))

(defvar swapley-modifiers '(control meta super hyper))

(define-minor-mode swapley-mode
  "key swapping mode."
  :global t
  :keymap nil
  (if swapley-mode
      (swapley-apply)
    (swapley-apply 'cancel)))

(defun swapley-apply (&optional cancel-p)
  (mapc (lambda (key)
	  (mapc (lambda (mods)
		  (define-key
		    key-translation-map
		    (vector (append mods (list (car key))))
		    (unless cancel-p (vector (append mods (list (cdr key))))))
		  (define-key
		    key-translation-map
		    (vector (append mods (list (cdr key))))
		    (unless cancel-p (vector (append mods (list (car key)))))))
		(cons nil (swapley-modifier-combinations))))
	swapley-key-alist))

(defun swapley-modifier-combinations ()
  (swapley-modifier-combinations-1 swapley-modifiers))

(defun swapley-modifier-combinations-1 (list)
  (when list
    (append
     (list (list (car list)))
     (swapley-modifier-combinations-2 (list (car list))
				      (cdr list))
     (swapley-modifier-combinations-1 (cdr list)))))

(defun swapley-modifier-combinations-2 (list1 list2)
  (when list2
    (append
     (mapcar (lambda (x) (append list1 (list x))) list2)
     (swapley-modifier-combinations-2 (append list1 (list (car list2)))
				      (cdr list2)))))

(provide 'swapley)
;;; swapley.el ends here

Copyright(C) 2001 - 2006 Ariel Networks, Inc. All rights reserved.