v8, 6/13/08. Started visual mode. yank/put
Fri Jun 13 04:46:16 PDT 2008 larry@theclapp.org
* v8, 6/13/08. Started visual mode. yank/put
diff -rN -u old-lw-vim-mode/bindings.lisp new-lw-vim-mode/bindings.lisp
--- old-lw-vim-mode/bindings.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/bindings.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -4,7 +4,8 @@
(ecase mode-abbrev
(:c "Vim Command")
(:i "Vim Insert")
- (:o "Vim Operator Pending")))
+ (:o "Vim Operator Pending")
+ (:v "Vim Visual")))
(defmethod bind-vim ((name string) key (mode string))
(pushnew key *bound-vim-commands*)
@@ -85,9 +86,11 @@
("Vim Top of Window" #\H (:c :o))
("Vim Bottom of Window" #\L (:c :o))
("Vim Move to Window Line" #\M (:c :o))
- ("Vim Goto Line or Top of Buffer" "gg" :c)
- ("Vim Forward Form" #\) (:c :o))
- ("Vim Backward Form" #\( (:c :o))
+ ("Vim Goto Line or Top of Buffer" "gg" (:c :o))
+ ; ("Vim Forward Form" #\) (:c :o))
+ ; ("Vim Backward Form" #\( (:c :o))
+ ("Vim Forward Sentence" #\) (:c :o))
+ ("Vim Backward Sentence" #\( (:c :o))
("Vim Forward List" #\c-\) (:c :o))
("Vim Backward List" #\c-\( (:c :o))
("Vim Beginning of Line" ; for #\0 see Vim Beginning of Line or Collect Count
@@ -101,6 +104,14 @@
("Vim To Column N" #\| (:c :o))
+ ; Visual mode
+ ("Vim Visual Mode" #\v :c)
+
+ ; yank / put
+ ; ("Save Region" #\y :c)
+ ("Vim Put Before" #\P :c)
+ ("Vim Put After" #\p :c)
+
; scrolling
("Scroll Window Down" #\c-\f (:c :o))
("Scroll Window Up" #\c-\b (:c :o))
@@ -109,7 +120,7 @@
("Vim Scroll Line to Top of Window" ("zt" #(#\z #\Return)) (:c :o))
("Vim Scroll Line to Middle of Window" ("zz" "z.") (:c :o))
("Vim Scroll Line to Bottom of Window" ("zb" "z-") (:c :o))
-
+
; Repeating
("Vim Repeat" #\. :c)
("Vim Argument Digit" (#\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) (:c :o))
@@ -123,20 +134,21 @@
("Vim Insert Text at Beginning of Line" #\I :c)
("Vim Delete Motion" #\d :c)
("Vim Change Motion" #\c :c)
- ("Kill Line" #\D :c)
- ("Un-Kill" #\P :c)
- ("Vim Move Over Whole Line" #\d :o) ; used for "dd"
+ ("Vim Yank Motion" #\y :c)
+ ("Vim Kill To End Of Line" #\D :c)
+ ("Vim Yank Line" #\Y :c)
+ ("Vim Move Over Whole Line" (#\d #\y) :o) ; used for "dd" and "yy"
("Vim Move Over Inner Word" "iw" :o)
("Vim Move Over A Word" "aw" :o)
("Vim Move Over Inner BigWord" "iW" :o)
("Vim Move Over A BigWord" "aW" :o)
("Vim Open Line Down" #\o :c)
("Vim Open Line Up" #\O :c)
- ("Undo" #\u :c)
+ ("Vim Undo" #\u :c)
("Lowercase Word" "~w" :c)
- ("Lowercase Region" "vu" :c)
- ("Uppercase Region" "vU" :c)
+ ; ("Lowercase Region" "vu" :c)
+ ; ("Uppercase Region" "vU" :c)
("Indent Rigidly" ">>" :c)
("Vim Join Lines" #\J :c)
@@ -157,14 +169,14 @@
("Select Buffer" ":b " :c)
; search
- ("ISearch Forward Regexp" #\/ (:c :o))
- ("ISearch Backward Regexp" #\? (:c :o))
+ ("Vim ISearch Forward Regexp" #\/ (:c :o))
+ ("Vim ISearch Backward Regexp" #\? (:c :o))
("Vim Find Next" #\n (:c :o))
("Vim Find Previous" #\N (:c :o))
("List Matching Lines" ":gp" :c) ; not in Vim, exactly
("Delete Matching Lines" ":gd" :c) ; not in Vim
- ("Regexp Forward Search" #\c-\/ (:c :o))
- ("Regexp Reverse Search" #\c-\? (:c :o))
+ ("Vim Regexp Forward Search" #\c-\/ (:c :o))
+ ("Vim Regexp Reverse Search" #\c-\? (:c :o))
("Vim Find Char Right" #\f (:c :o))
("Vim Find Char Left" #\F (:c :o))
("Vim Find Till Char Right" #\t (:c :o))
Binary files old-lw-vim-mode/bindings.ufasl and new-lw-vim-mode/bindings.ufasl differ
diff -rN -u old-lw-vim-mode/changelog.mdwn new-lw-vim-mode/changelog.mdwn
--- old-lw-vim-mode/changelog.mdwn 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/changelog.mdwn 2014-07-26 10:13:07.000000000 -0700
@@ -1,3 +1,28 @@
+v8, 6/13/2008
+
+General changes:
+
+* Started Visual mode. Didn't get very far. Really just defined a minor mode
+ and a key to enter it, but nothing else. Don't use yet.
+* Normal mode yank/put commands added. `P` behavior changed / fixed.
+* Search commands changed to be real movement commands, so they work with
+ motion-pending commands.
+* vim::vim-delete-motion changed to vim::vim-action-over-motion.
+
+Mappings changed/added
+
+* `(` / `)`: changed from Vim Backward/Forward Form to Vim Backward/Forward Sentence. Use `C-(` / `C-)` for moving over lists.
+* `v` to enter Visual mode. Really just sets the mark to the current cursor position.
+* `P` / `p` to put before/after.
+* `Y` to yank line
+* `D` to kill to end of line.
+* `y{motion}` added
+* `dd` and `yy` to delete or yank whole line.
+* `vu` and `vU` removed (side effect of adding `v` to enter visual mode)
+* `/` and `?` changed to be real Vim movement commands, so they work with
+ motion-pending commands.
+* Same for `C-/` and `C-?`
+
v7, 5/19/2008
General changes:
Binary files old-lw-vim-mode/classes.ufasl and new-lw-vim-mode/classes.ufasl differ
diff -rN -u old-lw-vim-mode/commands.lisp new-lw-vim-mode/commands.lisp
--- old-lw-vim-mode/commands.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/commands.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -4,6 +4,7 @@
(defmode "Vim Command" :setup-function 'setup-vim-command-mode)
(defmode "Vim Insert" :setup-function 'setup-vim-insert-mode)
(defmode "Vim Operator Pending")
+(defmode "Vim Visual")
(defvar *orig-meta-prefix-gesture-spec* editor::*meta-prefix-gesture-spec*)
(defvar *orig-interrupt-keys* '(#\c-g))
@@ -37,6 +38,14 @@
(declare (ignore p))
t)
+(defcommand "Vim Visual Mode" (p) "" ""
+ (setf (buffer-minor-mode (current-buffer) "Vim Operator Pending") nil)
+ (setf (buffer-minor-mode (current-buffer) "Vim Command") t)
+ (setf (buffer-minor-mode (current-buffer) "Vim Visual") t)
+ ; from Barry Wilkes via Edi Weitz's lw-add-ons
+ (set-mark-command p)
+ (hl-on-command p))
+
(defcommand "Exit Vim Mode" (p)
"Exit Vim Command Mode"
"Exit Vim Command Mode"
@@ -156,6 +165,12 @@
(def-vim-move "Vim Backward BIGWORD End" (p) nil :inclusive "" ""
(vim-offset p :bigword nil (current-point) :end t))
+(def-vim-move "Vim Forward Sentence" (p) nil :exclusive "" ""
+ (vim-offset p :sentence t (current-point)))
+
+(def-vim-move "Vim Backward Sentence" (p) nil :exclusive "" ""
+ (vim-offset p :sentence nil (current-point)))
+
(def-vim-move "Vim Goto Line or End of File" (p) :linewise :inclusive "" ""
(if p
(goto-line-command p)
@@ -216,12 +231,40 @@
(clear-undo-command p))
(def-vim-movement-pending "Vim Delete Motion" (begin end) "" ""
- (vim-delete-motion begin end))
+ (save-linewise-status)
+ (vim-action-over-motion #'kill-region-command begin end))
(def-vim-movement-pending "Vim Change Motion" (begin end) "" ""
- (vim-delete-motion begin end)
+ (vim-action-over-motion #'kill-region-command begin end)
(setf b-vim-movement-pending-ending-mode "Vim Insert"))
-
+
+(def-vim-movement-pending "Vim Yank Motion" (begin end) "" ""
+ (save-linewise-status)
+ (vim-action-over-motion #'save-region-command begin end))
+
+;; Basically maps D to d$
+(def-vim-change "Vim Kill To End Of Line" (p) "" ""
+ (save-linewise-status)
+ (vim-delete-motion-command nil)
+ (vim-end-of-line-command p))
+
+(def-vim-change "Vim Yank Line" (p) "" ""
+ (save-linewise-status)
+ (vim-yank-motion-command nil)
+ (vim-move-over-whole-line-command p))
+
+(def-vim-change "Vim Put Before" (p) "" ""
+ (when *vim-saved-linewise-status*
+ (line-start (current-point)))
+ (save-excursion
+ (un-kill-command p)))
+
+(def-vim-change "Vim Put After" (p) "" ""
+ (when *vim-saved-linewise-status*
+ (line-offset (current-point) 1 0))
+ (save-excursion
+ (un-kill-command p)))
+
(defcommand "Vim Argument Digit" (p) "" ""
(setf w-vim-collecting-count t)
(argument-digit-command p))
@@ -262,7 +305,7 @@
(prompt-for-character* "Character: " :ignored)
(end-of-line-command p)
)
-
+
(def-vim-move "Vim Find Char Left" (p) nil :exclusive "" ""
(vim-find-char nil p :save t))
@@ -309,6 +352,18 @@
(dotimes (n (or p 1))
(delete-indentation-command 1))))
+(def-vim-move "Vim ISearch Forward Regexp" (p) nil :exclusive "" ""
+ (isearch-forward-regexp-command p))
+
+(def-vim-move "Vim ISearch Backward Regexp" (p) nil :exclusive "" ""
+ (isearch-backward-regexp-command p))
+
+(def-vim-move "Vim Regexp Forward Search" (p) nil :exclusive "" ""
+ (regexp-forward-search-command p))
+
+(def-vim-move "Vim Regexp Reverse Search" (p) nil :exclusive "" ""
+ (regexp-reverse-search-command p))
+
(def-vim-move "Vim Find Next" (p) nil :exclusive "" ""
(dotimes (n (or p 1))
(regular-expression-search (current-point) editor::*last-search-string*)))
@@ -316,3 +371,9 @@
(def-vim-move "Vim Find Previous" (p) nil :exclusive "" ""
(dotimes (n (or p 1))
(regular-expression-search (current-point) editor::*last-search-string* :forwardp nil)))
+
+;; Technically this is not a "change" and should not use def-vim-change.
+;; FIXME: tried a SAVE-EXCURSION around the undo, but that's not really right. LW undo
+;; leaves the point after the undone text; Vim leaves the point before the undone text.
+(defcommand "Vim Undo" (p) "" ""
+ (undo-command p))
Binary files old-lw-vim-mode/commands.ufasl and new-lw-vim-mode/commands.ufasl differ
diff -rN -u old-lw-vim-mode/def-stuff.lisp new-lw-vim-mode/def-stuff.lisp
--- old-lw-vim-mode/def-stuff.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/def-stuff.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -18,7 +18,7 @@
(editor:setup-indent 'def-vim-move 6)
(defmacro def-vim-move (name lambda-list linewise incl/excl command-doc function-doc
&body body)
- (when (not (member incl/excl '(:inclusive :exclusive)))
+ (unless (member incl/excl '(:inclusive :exclusive))
(error "Invalid incl/excl flag ~A in def-vim-move ~A; should be ~A or ~A~%"
incl/excl name :inclusive :exclusive))
(let ((p (car lambda-list))
@@ -43,6 +43,7 @@
(finish-pending-motion #',move)
(,move nil))))))))
+(editor:setup-indent 'def-vim-movement-pending 4)
(defmacro def-vim-movement-pending (name lambda-list command-doc function-doc &body body)
`(defcommand ,name (p) ,command-doc ,function-doc
(in-vim-command
Binary files old-lw-vim-mode/def-stuff.ufasl and new-lw-vim-mode/def-stuff.ufasl differ
diff -rN -u old-lw-vim-mode/functions.lisp new-lw-vim-mode/functions.lisp
--- old-lw-vim-mode/functions.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/functions.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -3,6 +3,9 @@
(defun linewise ()
b-vim-linewise)
+(defun save-linewise-status ()
+ (setf *vim-saved-linewise-status* b-vim-linewise))
+
(defun exclusive ()
b-vim-exclusive)
@@ -191,6 +194,10 @@
while (move)
finally return (= n count))))
+(defmethod vim-offset (count (type (eql :sentence)) forward point &key &allow-other-keys)
+ (unless count (setf count 1))
+ (sentence-offset point (if forward count (- count))))
+
(defun current-word (&optional (word-type :keyword) (point (current-point)))
(unless (listp word-type)
(setf word-type (list word-type)))
@@ -249,14 +256,15 @@
(defun finish-pending-motion (move)
(let ((saved-vim-movement-pending b-vim-movement-pending))
(flet ((command (p)
- (setf b-vim-movement-pending saved-vim-movement-pending)
- (move-point b-vim-point-before-movement (current-point))
- (funcall move p)
- (unless (exclusive)
- (character-offset (current-point) 1))
- (funcall *vim-pending-action*
- b-vim-point-before-movement
- (current-point))))
+ (save-excursion
+ (setf b-vim-movement-pending saved-vim-movement-pending)
+ (move-point b-vim-point-before-movement (current-point))
+ (funcall move p)
+ (unless (exclusive)
+ (character-offset (current-point) 1))
+ (funcall *vim-pending-action*
+ b-vim-point-before-movement
+ (current-point)))))
(command nil)
(setf *vim-last-action* #'command
*vim-repeat-multiplier* nil
@@ -344,7 +352,7 @@
; 123456789
; ^ ^
; an "exclusive" motion d2l deletes the "45".
-(defun vim-delete-motion (begin end)
+(defun vim-action-over-motion (action begin end)
;; Make sure begin and end are distinct objects, different from each other
;; and different from (current-point).
(with-point ((begin begin)
@@ -365,5 +373,5 @@
; (format t "begin is ~S, end is ~S~%" begin end)
(move-point (current-point) begin)
(set-current-mark end)
- (kill-region-command nil)
+ (funcall action nil)
(move-point (current-point) begin)))
Binary files old-lw-vim-mode/functions.ufasl and new-lw-vim-mode/functions.ufasl differ
Binary files old-lw-vim-mode/macros.ufasl and new-lw-vim-mode/macros.ufasl differ
Binary files old-lw-vim-mode/packages.ufasl and new-lw-vim-mode/packages.ufasl differ
diff -rN -u old-lw-vim-mode/vars.lisp new-lw-vim-mode/vars.lisp
--- old-lw-vim-mode/vars.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/vars.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -26,3 +26,8 @@
:inverse-p t))
(defvar *vim-default-char-attributes* (make-hash-table))
+
+;; FIXME: This is really a hack. To interact correctly with the Emacs kill-ring,
+;; we need a ring of these, too.
+(defvar *vim-saved-linewise-status* :linewise
+ "Stores the linewise status of the last yanked text.")
Binary files old-lw-vim-mode/vars.ufasl and new-lw-vim-mode/vars.ufasl differ
diff -rN -u old-lw-vim-mode/vim-vars.lisp new-lw-vim-mode/vim-vars.lisp
--- old-lw-vim-mode/vim-vars.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/vim-vars.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -28,7 +28,7 @@
(setf (gethash selector (values-of var))
(funcall (init-func-of var))))))
(error "vim-var: vim-var ~S of type ~S not found" name type))))
-
+
(defun vim-var-set (name type value)
(setf (gethash (vim-var-selector type)
(values-of (vim-var-lookup name type)))
Binary files old-lw-vim-mode/vim-vars.ufasl and new-lw-vim-mode/vim-vars.ufasl differ
diff -rN -u old-lw-vim-mode/wrap-editor.lisp new-lw-vim-mode/wrap-editor.lisp
--- old-lw-vim-mode/wrap-editor.lisp 2014-07-26 10:13:07.000000000 -0700
+++ new-lw-vim-mode/wrap-editor.lisp 2014-07-26 10:13:07.000000000 -0700
@@ -1,15 +1,19 @@
(in-package :vim)
(eval-when (:compile-toplevel :load-toplevel :execute)
- (defmacro wrap-editor (symbol)
+ (defmacro wrap-editor-function (symbol)
+ (let ((editor-symbol (intern symbol :editor)))
+ `(defun ,symbol (&rest rest)
+ (apply ',editor-symbol rest))))
+ (defmacro wrap-editor-macro (symbol)
(let ((editor-symbol (intern symbol :editor)))
`(defmacro ,symbol (&rest rest)
- `(,',editor-symbol ,@rest))))
- (defmacro wrap-list (&rest list)
+ `(,',editor-symbol ,@rest))))
+ (editor:setup-indent 'wrap-list-with 1)
+ (defmacro wrap-list-with (wrapper &rest list)
`(progn
,@(loop for s in list
- collect `(wrap-editor ,s)))))
-
+ collect `(,wrapper ,s)))))
#+cells
(defmodel point ()
@@ -25,36 +29,51 @@
; (defun current-point ()
; ())
-(wrap-list
+;;;; Not just importing these symbols is a deliberate design choice,
+;;;; on the assumption that I may well need to wrap some of these guys
+;;;; more extensively. Arguably I should just import them and cross
+;;;; that bridge when I come to it, and maybe I'll eventually change,
+;;;; but for now I'm just gonna leave it.
+
+(wrap-list-with wrap-editor-macro
+ buffer-minor-mode
+ buffer-modified
+ buffer-writable
+ collect-undo
+ defcommand
+ def-ed-var
+ defmode
+ next-character
+ save-excursion
+ use-buffer
+ with-point)
+
+(wrap-list-with wrap-editor-function
argument-digit-command
back-to-indentation-command
backward-character-command
backward-form-command
backward-list-command
+ backward-sentence-command
beginning-of-buffer-command
beginning-of-line-command
bind-key
bottom-of-window-command
- buffer-minor-mode
buffer-mode-names
buffer-pathname
buffers-end
buffers-start
character-offset
clear-undo-command
- collect-undo
copy-point
count-lines
current-buffer
current-point
current-window
- def-ed-var
- defcommand
- defmode
delete-indentation-command
delete-next-character-command
- delete-previous-character-command
delete-point
+ delete-previous-character-command
editor-error
end-of-buffer-command
end-of-line-command
@@ -66,10 +85,15 @@
forward-character-command
forward-form-command
forward-list-command
+ forward-sentence-command
gesture-to-simple-char
goto-line-command
+ hl-off-command
+ hl-on-command
insert-string
invoke-hook
+ isearch-backward-regexp-command
+ isearch-forward-regexp-command
kill-region-command
line-end
line-offset
@@ -78,29 +102,32 @@
move-point
move-to-window-line-command
new-line-command
- next-character
next-line-command
open-line-command
- point/=
point<
point<=
point>=
+ point/=
point-buffer
points-to-string
previous-line-command
prompt-for-character*
prompt-for-prefix
refresh-screen-command
+ regexp-forward-search-command
+ regexp-reverse-search-command
regular-expression-search
revert-buffer-command
same-line-p
save-all-files-command
- save-excursion
+ save-region-command
scroll-window-down-command
scroll-window-up-command
+ sentence-offset
set-current-mark
+ set-mark-command
top-of-window-command
+ undo-command
+ un-kill-command
update-buffer-window
- use-buffer
- with-point
)
Binary files old-lw-vim-mode/wrap-editor.ufasl and new-lw-vim-mode/wrap-editor.ufasl differ