;; toucan.el - Toucan Minor Mode ;; Provide a kind of simplified vi-like functionality. ;; Author: Sean B. Palmer, inamidst.com (if (file-regular-p "~/.emacs.d/visible.el") (load "~/.emacs.d/visible.el") (message "Unable to load visible-mark-mode")) (defun my-zap-up-to-char (arg char) "Kill up to the ARG'th occurrence of CHAR." (interactive "p\ncDelete to: ") (kill-region (point) (progn (search-forward (char-to-string char) nil nil arg) (backward-char) (point)))) (defun my-show-mark () (interactive) (visible-mark-mode)) (defun my-yank () (interactive) (kill-region (mark) (point)) (if (visible-mark-mode) (visible-mark-mode))) (defun my-find-next-char (arg char) "Find the next character." (interactive "p\ncMove to: ") (forward-char) (search-forward (char-to-string char) nil nil arg) (backward-char)) (defun my-find-previous-char (arg char) "Find the previous character." (interactive "p\ncMove back to: ") (search-backward (char-to-string char) nil nil arg)) (defun my-move-region () "Move region between last two mark points to point." (interactive) (kill-region (mark-marker) (nth 0 mark-ring)) (yank)) (defun my-duplicate-line-down () "Duplicate a line down." (interactive) (let ((my-previous-column (current-column))) (progn (my-kill-whole-line) (yank) (yank) (previous-line 2) (move-to-column my-previous-column)))) (defun my-t-exit () "Insert \\t and then exit Toucan Mode." (interactive) (insert "\\t") (toucan-mode)) (defun my-r-exit () "Insert \\r and then exit Toucan Mode." (interactive) (insert "\\r") (toucan-mode)) (defun my-n-exit () "Insert \\n and then exit Toucan Mode." (interactive) (insert "\\n") (toucan-mode)) (defun my-reverse-solidus-exit () "Insert \\ and then exit Toucan Mode." (interactive) (insert "\\") (toucan-mode)) (defun my-back-para-and-mark () "Go back a paragraph, forward a char, and mark at the new point." (interactive) (backward-paragraph) (push-mark)) (defun my-fore-para-and-mark () "Go forward a paragraph, and mark the new point." (interactive) (forward-paragraph) (push-mark)) (defun my-change-word (arg str) "Change a word." (interactive "p\nsNew word: ") (kill-word 1) (insert str)) (define-minor-mode toucan-mode "Toggle Toucan Minor Mode. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode. When Toucan Mode is available, keys will be rebound to provide vi-like functionality." nil ;; The initial value " Toucan" ;; Mode line indicator ;; Bindings '(("h" . backward-char) ("j" . next-line) ("k" . previous-line) ("l" . forward-char) ("u" . undo) ("i" . toucan-mode) ("f" . my-find-next-char) ("F" . my-find-previous-char) ("w" . forward-word) ("b" . backward-word) ("m" . set-mark-command) ("." . repeat) ;; @@ Only for toucan commands ("y" . my-show-mark) ("Y" . my-yank) ("x" . delete-char) ("d" . kill-word) ("D" . backward-kill-word) ;; Delete remainder of line in vi ("p" . my-move-region) ;; Paste in vi ("z" . my-zap-up-to-char) ;; Redraw and move back in vi. Like dtz ("c" . my-change-word) ;; Change in vi. Like cw (";" . my-duplicate-line-down) ;; Repeat minisearch in vi. Like yyp ;; ("t" . my-t-exit) ;; Till motion in vi ;; ("r" . my-r-exit) ;; Replace char in vi ;; ("n" . my-n-exit) ;; Repeat search in vi ;; ("\\" . my-reverse-solidus-exit) ;; Nothing in vi? ("{" . my-back-para-and-mark) ("}" . my-fore-para-and-mark) ("[" . backward-paragraph) ("]" . forward-paragraph) ;; @@ Delete current word? ;; ("I" . @@) - Insert before line ;; ("a" . @@) - Append after cursor ;; ("A" . @@) - Append after line ;; ("r" . @@) - Replace one character (@@ r is set to \r) ;; ("X" . @@) - Delete left ;; ("D" . @@) - Cut to end of line ;; () for sentences, {} for paragraphs ;; 0 beginning of line, $ end of line ;; Moving: m moves, what copies? what deletes? should s mark? ;; Could c be change word? p/P is put (after/before). m sets a marker ;; n is like / repeated. J joins lines. . repeats. u undoes. ~ for case ;; ^ is first non-blank character in line ;; s is like change character for word. how odd. r is replace char ;; <> for back and forward word would be good ;; @@ universal-argument. J for reducing whitespace. c for cw ;; K for delete remainder of line? ;; @@ Something for C-l )) ;; [EOF]