Created
June 3, 2010 14:21
-
-
Save bowbow99/423944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; -*- mode: lisp; package: editor -*- | |
;;; | |
;;; turnaround.l | |
(in-package :editor) | |
(export '(turnaround | |
turnaround-or-select-word | |
turnaround-or-self-insert)) | |
(defvar-local turnaround-candidates-list nil) | |
(defun select-region (from to) | |
(goto-char to) | |
(start-selection 2 t from)) | |
(defun %current-word (&optional (point (point) point-supplied-p)) | |
(save-excursion | |
(when point-supplied-p (goto-char point)) | |
(skip-syntax-spec-backward "w_") | |
(let ((from (point))) | |
(skip-syntax-spec-forward "w_") | |
(values (buffer-substring from (point)) | |
from | |
(point))))) | |
(defun turnaround-find-candidates (text) | |
(let ((all turnaround-candidates-list)) | |
(do ((candidates (car all) (car rest)) | |
(rest (cdr all) (cdr rest))) | |
((null candidates) nil) | |
(let ((pos (position text candidates :test 'string=))) | |
(when pos (return (values candidates pos))))))) | |
(defun next-item (list n) | |
(let ((next-n (1+ n))) | |
(if (= next-n (length list)) | |
(car list) | |
(nth next-n list)))) | |
(defun turnaround () | |
(interactive "*") | |
(multiple-value-bind (text from to) | |
(%current-word) | |
(unless (stringp text) (return-from turnaround nil)) | |
(multiple-value-bind (candidates n) | |
(turnaround-find-candidates text) | |
(if candidates | |
(progn | |
(delete-region from to) | |
(insert (next-item candidates n)) | |
(select-region from (point))) | |
(interactive-p))))) | |
(defun turnaround-or-select-word () | |
(interactive "*") | |
(or (turnaround) | |
(multiple-value-bind (text from to) | |
(%current-word) | |
(if text | |
(select-region from to) | |
(interactive-p))))) | |
(defun turnaround-or-self-insert () | |
(interactive "*") | |
(call-interactively | |
(if (member *last-command* '(turnaround turnaround-or-self-insert)) | |
'turnaround | |
'self-insert-command))) | |
;;; turnaround.l ends here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
うちで使ってる monday.vim っぽいもの。
.xyzzy の設定が↓な感じ。
(require :turnaround)