; -*- mode: emacs-lisp; coding: latin-1; -*- ; Time-stamp: "2006-10-07 19:59:06 AKDT" sburke@cpan.org! ;(fset 'delete-to-line-start ; [C-@ C-a C-w]) ;; i.e., set-mark-command beginning-of-line kill-region (defmacro onkey (key &rest body) "A complicated macro to simplify global key (un)binding. Uses: (onkey [f5]) => unbinds [f5] (onkey [f5] \'recenter) => binds [f5] to that command (onkey [f5] (message \"Hi!\") (insert \"Hooboy.\")) => to bind f5 to a new lambda consisting of those actions (onkey [f5] \"A greeting\" (message \"Hi!\") (insert \"Hooboy.\")) => to bind f5 to a new lambda consisting of those actions, with that given description " ; ()'" ; sburke@cpan.org (cond ;Input: (onkey [f5]) ;Output: (global-unset-key [f5]) ;Input: (onkey [f5] nil) ;Output: (global-unset-key [f5]) ((or (zerop (length body)) ; no params at all (and (= 1 (length body)) (null (car body)))) ; one param: nil `(global-unset-key ,key)) ;Input: (onkey [f5] 'recenter) ;Output: (global-set-key [f5] 'recenter) ((and ; symbolp doesn't work nicely in macros, it seems. (= 1 (length body)) (listp (car body)) (string-equal (caar body) 'quote)) `(global-set-key ,key ,(car body))) ; Common cases follow: ; Input: (onkey [f5] "A greeting" (message "Hi!")) ; Output: (global-set-key [f5] ; (lambda () "A greeting" ; (interactive) (message "Hi!"))) ((and (= 2 (length body)) (stringp (car body)) (listp (cadr body)) ) `(global-set-key ,key ;(byte-compile (lambda () ,(car body) (interactive) ,(cadr body) )));) ; Input: (onkey [f5] (message "Hi!")) ; Output: (global-set-key [f5] ; (lambda () "" ;[no real description] ; (interactive) (message "Hi there!"))) ((listp (car body)) `(global-set-key ,key ;(byte-compile (lambda () "" (interactive) ,(car body))));) ;Otherwise... (t (error "I don't understand this onkey parameter: %s" body)))) ;--------------------------------------------------------------------------- (onkey "\C-t") (global-set-key [?\C-\;] ctl-x-map) ; Alias control-; to control-x so all the control-x combinations ; become easier for us Dvorak users. (onkey [?\M-\;] 'execute-extended-command) (onkey [?\C-\M-\;] 'comment-dwim) (onkey [?\C-\M-\q] 'unfill-paragraph) ; TODO: make everything (or most things?) in ctl-x-map also be on H-s-key (global-set-key [?\C-\; ?\C-\;] 'exchange-point-and-mark) ; so that c-x c-x => c-; c-; and not just c-; c-x (define-key minibuffer-local-completion-map " " 'self-insert-command) ; Instead of the usual 'minibuffer-complete-word ; Otherwise, accessing filenames with an actual space in them is a hassle. (onkey [?\C-c ?\C-l] 'goto-line) (onkey [?\C-c ?\C-r] 'goto-random-line) (global-set-key "\C-\M-a" (string-to-vector (concat "" "\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-b" ))) (global-set-key "\C-\M-l" (string-to-vector (concat "" "\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-b" ))) (global-set-key "\C-\M-f" ; JavaScript for loop (vconcat (string-to-vector "for(var i=0; i < .length; i++) {\n\t\n}") [up up end] (duplicate-sequence [left] 15) )) (global-set-key "\M-f" ; JavaScript function (vconcat (string-to-vector "function _ (_) {\n\t\n}") [up up end left left left backspace left left backspace] )) ;; Alternate implementation: ;; ;; (global-set-key "\C-\M-a" '(lambda () "hyperlink!" (interactive) ;; (insert "this and that and stuff") ;; (dotimes (i 9) (backward-char) (load-library "iso-transl") ;^^ handy key definitions for characters in Latin-1 (onkey "\M-." 'iso-transl-angle-right) (onkey "\M-," 'iso-transl-angle-left) (onkey "\M-\C-s" "Dired this dir" (dired ".")) (onkey [M-up] "Dired this dir" (dired ".")) (onkey "\M-a" 'ascii-table) (onkey "\M-n" 'toggle-narrow) (when window-system (progn (onkey "\M-s" 'spawn-explore-pwd) ;(global-set-key "\M-\C-c" '(lambda () ; (interactive) (shell-command-into-void "xclipboard" ))) (onkey "\M-\C-c" "run xclipboard" (shell-command-into-void "xclipboard" )) (onkey "\M-\C-e" "run xclipboard" (shell-command-into-void "thunderbird" )) (onkey "\M-\C-w" "run firefox" (shell-command-into-void "firefox" )) (onkey "\M->" 'shell-command-into-void ) (onkey [?\C-\M-.] 'shell-command-into-void ) ; common typo for \M-> )) (onkey "\M-!" 'shell-command-to-new-scratch ) (onkey "\M-g" 'grep) (onkey "\M-b" 'sort-buffers) ;(onkey "\M-\C-b" 'bury-buffer) ; not as useful as: (onkey "\M-\C-b" "Back it up" (shell-command (rep!!basename "bu !!"))) ; make a backup (when (functionp 'spawn-terminal) (progn (onkey "\M-t" 'spawn-terminal) (onkey "\M-\S-t" 'spawn-terminal) (onkey "\M-\C-t" 'spawn-terminal) (onkey [C-f11] 'spawn-terminal) ;(global-set-key "\M-C-t" 'spawn-terminal) ;(global-set-key "\S-C-t" 'spawn-terminal) )) (when (functionp 'zoom-frm-in) (progn (onkey [C-kp-add] 'zoom-frm-in) (onkey [C-kp-subtract] 'zoom-frm-out) (onkey [C-kp-insert] 'zoom-frm-unzoom) (onkey [C-mouse-4] 'zoom-frm-out) (onkey [C-mouse-5] 'zoom-frm-in) )) (onkey [mouse-4] 'scroll-down) (onkey [mouse-5] 'scroll-up) (onkey "\M-\C-p" 'perl-eval) ;; put it on ctrl-alt-P (onkey "\M-m" 'woman) (onkey "\M-p" 'cperl-perldoc) (onkey "\M-k" 'kill-ring-save-line) (onkey "\M-j" "open my scratchpad" (find-file (expand-file-name "~/j.txt"))) (when window-system (onkey [(c-x) (c-c)] ;; ...never quit by mistake... (when (y-or-n-p "Quit emacs? ") (save-buffers-kill-emacs)))) (load-library "text-mode") ; Might as well just load it. It's tiny. And it has ; no text-load-hook or anything that we could attach to. (define-key text-mode-map "\M-s" nil) ; was: center-line, blocking my global spawn-explore-pwd (add-hook 'dired-load-hook '(lambda () (defun k (key cmd) (define-key dired-mode-map key cmd)) (k [f2] 'dired-do-rename) (k "\C-r" 'revert-buffer) (k [f5] 'revert-buffer) (k "\M-u" 'dired-up-directory) (k [M-up] 'dired-up-directory) (k [M-down] 'dired-advertised-find-file) (k "\M-r" 'dired-start-this-file) (k "%!" 'dired-do-shell-command) (k "\M-k" 'dired-copy-file-basename) (k "!" 'SMB-dired-do-shell-command) (k [key-20] '(lambda () (interactive) ; Run toggle_writeable on the current line's filename! (dired-do-shell-command "toggle_writeable" nil (list (dired-get-filename nil t))) (dired-do-redisplay) )) )) ; and NOW we can (and should) load dired: (require 'dired) (require 'dired-aux) (add-hook 'Man-mode-hook '(lambda () (defun k (key cmd) (define-key Man-mode-map key cmd)) (k "\M-n" nil) (k "\M-p" nil) )) (add-hook 'comint-mode-hook '(lambda () (defun k (key cmd) (define-key comint-mode-map key cmd)) (k [C-S-up] 'comint-previous-input) (k [C-S-down] 'comint-next-input ) )) (onkey "\M-o" 'occur) ;(global-set-key "\M-r" 'replace-string) ;(global-set-key "\M-r" 'start-current-buffer) (global-set-key "\M-r" 'mode-compile) (onkey "\M-(" 'blink-matching-open) (onkey "\C-x\C-o" 'other-window) (onkey "\C-x\C-i" 'insert-buffer) (onkey "\C-o" 'find-file) (onkey "\C-z" 'undo) (onkey "\C-x\C-d" 'dired) ; because I never want the normal binding of list-directory (onkey [C-tab] 'other-window) (onkey [C-S-iso-lefttab] 'mode-line-other-buffer) (onkey [right] 'forward-char) (onkey [left] 'backward-char) (onkey [up] 'previous-line) (onkey [down] 'next-line) (onkey [next] 'scroll-up) (onkey [prior] 'scroll-down) (onkey [C-next] 'end-of-buffer) (onkey [C-prior] 'beginning-of-buffer) (onkey [C-M-S-prior] 'enlarge-window) (onkey [C-M-S-next ] 'shrink-window) (onkey [home] 'beginning-of-line) (onkey [end] 'end-of-line) (onkey [C-home] 'beginning-of-line) ; should be kill-to-line-start ; if I can ever get it to work (onkey [C-end] 'kill-line) (onkey [C-left] 'backward-word) (onkey [C-right] 'forward-word) (onkey [C-up] 'backward-paragraph) (onkey [C-down] 'forward-paragraph) ;;(onkey [help] 'overwrite-mode) ;insert on mac keyboards is "Help" (onkey [insert] 'auto-fill-mode) (onkey [help] 'auto-fill-mode) (onkey [C-help] 'kill-ring-save) ;insert on mac keyboards (onkey [C-delete] 'delete-char) (onkey [S-help] 'yank) ;insert on mac keyboards (onkey [S-delete] 'kill-region) (onkey [C-S-up] 'previous-history-element) (onkey [C-S-down] 'next-history-element) (onkey [key-20] ; = Scroll-Lock 'toggle-read-only) (onkey "\M-=" 'hbar) (define-key Buffer-menu-mode-map "\M-k" 'copy-buffer-name) (define-key Buffer-menu-mode-map [key-20] '(lambda () (interactive) (Buffer-menu-toggle-read-only) (forward-line 1) )) ;(defun NODAMMIT () (interactive) ; (play-sound-file "~/sound_effects/arcanewolf_misc/chirp2.wav") ; (error "********* Use c-; instead now! *********") ;) ;(global-unset-key [?\C-x]) ;(onkey [?\C-x ?o] 'NODAMMIT) ;(onkey [?\C-x ?f] 'NODAMMIT) ;(onkey [?\C-x ?d] 'NODAMMIT) ;(onkey [?\C-x ?b] 'NODAMMIT) ;(onkey [?\C-x ?k] 'NODAMMIT) ;(onkey [?\C-x ?\C-o] 'NODAMMIT) ;(onkey [?\C-x ?\C-s] 'NODAMMIT) (onkey [menu] 'other-window) (onkey "\M-S-1" 'delete-other-windows) (onkey "\M-S-2" 'split-window-vertically) ;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; most of these commented-out things date from the zeroeth Bush presidency... ;(onkey [kp-f1] 'help-command) ;(onkey [kp-f2] 'set-mark-command) ;(onkey [kp-f3] 'search-forward) ;(onkey [kp-f4] 'other-window) ;(onkey [f1] 'help-command) (onkey [f1] 'blink-matching-open) (onkey [f2] 'set-mark-command) (onkey [f3] 'search-forward) ;(onkey [f4] 'other-window) (onkey [f4] 'bury-buffer) ;(onkey [f5] 'split-window-vertically) (onkey [f5] 'recenter) ;(onkey [f6] 'delete-window) ;(onkey [f7] 'ispell-word) (onkey [f7] 'ispell-buffer) ;(onkey [f8] 'fill-paragraph) ;(onkey [f9] 'find-file) ;(onkey [f10] 'save-buffers-kill-emacs) (onkey [f11] 'shell-command-to-new-scratch) ;(onkey [f11] 'delete-other-windows) ;(keyboard-translate [f12] ?\C-g) ;(onkey [f12] 'keyboard-quit) ;(onkey [f12] 'abort-recursive-edit) (onkey [f12] "Toggle to/from scratch" (switch-to-buffer (if (string-equal (buffer-name) "*scratch*") (other-buffer) "*scratch*"))) ;(onkey [C-f1] 'describe-key ) ;(onkey [C-f2] 'info ) ;(onkey [C-f3] 'search-forward-regexp) ;(onkey [C-f4] 'switch-to-buffer ) (onkey [C-f4] 'kill-this-buffer ) ;(onkey [C-f5] 'enlarge-window ) ;(onkey [C-f6] 'delete-other-windows ) (onkey [C-f6] 'mode-line-other-buffer) ;(onkey [C-f7] 'ispell-buffer ) ;(onkey [C-f8] 'auto-fill-mode ) ;(onkey [C-f9] 'insert-file ) ;(onkey [C-f10] 'save-buffer ) ;(onkey [C-f11] 'goto-line ) ;(onkey [C-f12] ' ) ;(onkey [M-f1] 'describe-function ) ;(onkey [M-f2] 'manual-entry ) ;(onkey [M-f3] 'search-backward-regexp ) ;(onkey [M-f4] 'list-buffers ) ;(onkey [M-f5] 'split-window-horizontally) ;(onkey [M-f6] ' ) ;(onkey [M-f7] 'ispell-region ) ;(onkey [M-f8] 'dired ) ;(onkey [M-f9] 'find-file-read-only ) ;(onkey [M-f10] 'set-visited-file-name ) ;(onkey [M-f11] 'what-line ) ;(onkey [M-f12] ' ) ;(onkey [S-f1] 'where-is) ;(onkey [S-f2] 'exchange-point-and-mark) ;(onkey [S-f3] 'search-backward) (onkey [S-f4] 'bury-buffer) ;(onkey [S-f5] 'enlarge-window-horizontally) ;(onkey [S-f6] ') ;(onkey [S-f7] ') ;(onkey [S-f8] ') ;(onkey [S-f9] 'append-to-file) ;(onkey [S-f10] 'revert-buffer) ;(onkey [S-f11] 'what-cursor-position) ;(onkey [S-f12] ') ;; ; Now, termcap or terminfo SHOULD'VE set these, but... ; (define-key function-key-map "\e[A" [up]) (define-key function-key-map "\e[B" [down]) (define-key function-key-map "\e[C" [right]) (define-key function-key-map "\e[D" [left]) (define-key function-key-map "\eOA" [up]) (define-key function-key-map "\eOB" [down]) (define-key function-key-map "\eOC" [right]) (define-key function-key-map "\eOD" [left]) (define-key function-key-map "\e[23~" [f11]) ;End.