Mercurial > emacs
comparison lisp/emulation/viper.el @ 14014:d9ead59e15fa
(vip-insert-diehard-minor-mode, vip-toggle-search-style,
vip-del-backward-char-in-replace, vip-query-replace): Doc fix.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 04 Jan 1996 23:52:13 +0000 |
parents | ab4917aacf37 |
children | 83f275dcd93a |
comparison
equal
deleted
inserted
replaced
14013:5eeb4ca55f3d | 14014:d9ead59e15fa |
---|---|
369 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil | 369 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil |
370 "Minor mode used to make major-mode-specific modification to Insert state.") | 370 "Minor mode used to make major-mode-specific modification to Insert state.") |
371 | 371 |
372 (vip-deflocalvar vip-insert-diehard-minor-mode nil | 372 (vip-deflocalvar vip-insert-diehard-minor-mode nil |
373 "Minor mode that simulates Vi very closely. | 373 "Minor mode that simulates Vi very closely. |
374 Not recommened, except for the novice user.") | 374 Not recommended, except for the novice user.") |
375 | 375 |
376 (vip-deflocalvar vip-insert-kbd-minor-mode nil | 376 (vip-deflocalvar vip-insert-kbd-minor-mode nil |
377 "Minor mode for Ex command macros Insert state. | 377 "Minor mode for Ex command macros Insert state. |
378 The corresponding keymap stores key bindings of Vi macros defined with | 378 The corresponding keymap stores key bindings of Vi macros defined with |
379 the Ex command :map!.") | 379 the Ex command :map!.") |
613 ;; If vip-insert-point turns out to be bigger than that, it is reset | 613 ;; If vip-insert-point turns out to be bigger than that, it is reset |
614 ;; back to vip-pre-command-point. | 614 ;; back to vip-pre-command-point. |
615 ;; The reason this is needed is because dabbrev-expand (and possibly | 615 ;; The reason this is needed is because dabbrev-expand (and possibly |
616 ;; others) may jump to before the insertion point, delete something and | 616 ;; others) may jump to before the insertion point, delete something and |
617 ;; then reinsert a bigger piece. For instance: bla^blo | 617 ;; then reinsert a bigger piece. For instance: bla^blo |
618 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point, | 618 ;; If dabbrev-expand is called after `blo' and ^ indicates vip-insert-point, |
619 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' | 619 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' |
620 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand | 620 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand |
621 ;; will insert the expansion, and we get: blablo^ | 621 ;; will insert the expansion, and we get: blablo^ |
622 ;; Whatever we insert next goes before the ^, i.e., before the | 622 ;; Whatever we insert next goes before the ^, i.e., before the |
623 ;; vip-insert-point marker. So, Viper will think that nothing was | 623 ;; vip-insert-point marker. So, Viper will think that nothing was |
935 | 935 |
936 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | 936 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. |
937 (defun vip-change-state (new-state) | 937 (defun vip-change-state (new-state) |
938 ;; Keep vip-post/pre-command-hooks fresh. | 938 ;; Keep vip-post/pre-command-hooks fresh. |
939 ;; We remove then add vip-post/pre-command-sentinel since it is very | 939 ;; We remove then add vip-post/pre-command-sentinel since it is very |
940 ;; desirable that noone gets in-between | 940 ;; desirable that no one gets in-between |
941 (remove-hook 'post-command-hook 'vip-post-command-sentinel) | 941 (remove-hook 'post-command-hook 'vip-post-command-sentinel) |
942 (add-hook 'post-command-hook 'vip-post-command-sentinel) | 942 (add-hook 'post-command-hook 'vip-post-command-sentinel) |
943 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) | 943 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) |
944 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) | 944 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) |
945 ;; These hooks will be added back if switching to insert/replace mode | 945 ;; These hooks will be added back if switching to insert/replace mode |
1359 (condition-case conds | 1359 (condition-case conds |
1360 (run-hooks 'vip-emacs-state-hook) | 1360 (run-hooks 'vip-emacs-state-hook) |
1361 (error | 1361 (error |
1362 (vip-message-conditions conds)))) | 1362 (vip-message-conditions conds)))) |
1363 | 1363 |
1364 ;; escape to emacs mode termporarily | 1364 ;; escape to emacs mode temporarily |
1365 (defun vip-escape-to-emacs (arg &optional events) | 1365 (defun vip-escape-to-emacs (arg &optional events) |
1366 "Escape to Emacs state from Vi state for one Emacs command. | 1366 "Escape to Emacs state from Vi state for one Emacs command. |
1367 ARG is used as the prefix value for the executed command. If | 1367 ARG is used as the prefix value for the executed command. If |
1368 EVENTS is a list of events, which become the beginning of the command." | 1368 EVENTS is a list of events, which become the beginning of the command." |
1369 (interactive "P") | 1369 (interactive "P") |
1370 (vip-escape-to-state arg events 'emacs-state)) | 1370 (vip-escape-to-state arg events 'emacs-state)) |
1371 | 1371 |
1372 ;; escape to Vi mode termporarily | 1372 ;; escape to Vi mode temporarily |
1373 (defun vip-escape-to-vi () | 1373 (defun vip-escape-to-vi () |
1374 "Escape from Emacs state to Vi state for one Vi 1-character command. | 1374 "Escape from Emacs state to Vi state for one Vi 1-character command. |
1375 This doesn't work with prefix arguments or most complex commands like | 1375 This doesn't work with prefix arguments or most complex commands like |
1376 cw, dw, etc. But it does work with some 2-character commands, | 1376 cw, dw, etc. But it does work with some 2-character commands, |
1377 like dd or dr." | 1377 like dd or dr." |
1698 (setq char (read-char))) | 1698 (setq char (read-char))) |
1699 (vip-set-unread-command-events char) | 1699 (vip-set-unread-command-events char) |
1700 ) | 1700 ) |
1701 ;; as com is non-nil, this means that we have a command to execute | 1701 ;; as com is non-nil, this means that we have a command to execute |
1702 (if (memq (car com) '(?r ?R)) | 1702 (if (memq (car com) '(?r ?R)) |
1703 ;; execute apropriate region command. | 1703 ;; execute appropriate region command. |
1704 (let ((char (car com)) (com (cdr com))) | 1704 (let ((char (car com)) (com (cdr com))) |
1705 (setq prefix-arg (cons value com)) | 1705 (setq prefix-arg (cons value com)) |
1706 (if (= char ?r) (vip-region prefix-arg) | 1706 (if (= char ?r) (vip-region prefix-arg) |
1707 (vip-Region prefix-arg)) | 1707 (vip-Region prefix-arg)) |
1708 ;; reset prefix-arg | 1708 ;; reset prefix-arg |
2367 (let ((hook (if vip-vi-style-in-minibuffer | 2367 (let ((hook (if vip-vi-style-in-minibuffer |
2368 'vip-change-state-to-insert | 2368 'vip-change-state-to-insert |
2369 'vip-change-state-to-emacs))) | 2369 'vip-change-state-to-emacs))) |
2370 (funcall hook) | 2370 (funcall hook) |
2371 | 2371 |
2372 ;; Make sure the minibufer overlay is kept up-to-date. In XEmacs also | 2372 ;; Make sure the minibuffer overlay is kept up-to-date. In XEmacs also |
2373 ;; guards against the possibility of detaching this overlay. | 2373 ;; guards against the possibility of detaching this overlay. |
2374 (vip-add-hook 'vip-post-command-hooks 'vip-move-minibuffer-overlay) | 2374 (vip-add-hook 'vip-post-command-hooks 'vip-move-minibuffer-overlay) |
2375 )) | 2375 )) |
2376 | 2376 |
2377 ;; Interpret last event in the local map | 2377 ;; Interpret last event in the local map |
2829 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which | 2829 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which |
2830 ;; sometimes simply shifts the repl region rightwards, without | 2830 ;; sometimes simply shifts the repl region rightwards, without |
2831 ;; deleting an equal amount of characters. | 2831 ;; deleting an equal amount of characters. |
2832 ;; | 2832 ;; |
2833 ;; The reason why new-dabbrev.el causes this are this: | 2833 ;; The reason why new-dabbrev.el causes this are this: |
2834 ;; if one dinamically completes a partial word that starts before the | 2834 ;; if one dynamically completes a partial word that starts before the |
2835 ;; replacement region (but ends inside)then new-dabbrev.el first | 2835 ;; replacement region (but ends inside)then new-dabbrev.el first |
2836 ;; moves cursor backwards, to the beginning of the word to be | 2836 ;; moves cursor backwards, to the beginning of the word to be |
2837 ;; completed (say, pt A). Then it inserts the | 2837 ;; completed (say, pt A). Then it inserts the |
2838 ;; completed word and then deletes the old, incomplete part. | 2838 ;; completed word and then deletes the old, incomplete part. |
2839 ;; Since the complete word is inserted at position before the repl | 2839 ;; Since the complete word is inserted at position before the repl |
3884 | 3884 |
3885 Although this function is bound to \\[vip-toggle-search-style], the most | 3885 Although this function is bound to \\[vip-toggle-search-style], the most |
3886 convenient way to use it is to bind `//' to the macro | 3886 convenient way to use it is to bind `//' to the macro |
3887 `1 M-x vip-toggle-search-style' and `///' to | 3887 `1 M-x vip-toggle-search-style' and `///' to |
3888 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will | 3888 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will |
3889 toggle case-fold-search and hitting `/' three times witth toggle regexp | 3889 toggle case-fold-search and hitting `/' three times with toggle regexp |
3890 search. Macros are more convenient in this case because they don't affect | 3890 search. Macros are more convenient in this case because they don't affect |
3891 the Emacs binding of `/'." | 3891 the Emacs binding of `/'." |
3892 (interactive "P") | 3892 (interactive "P") |
3893 (let (msg) | 3893 (let (msg) |
3894 (cond ((or (eq arg 1) | 3894 (cond ((or (eq arg 1) |
4070 (define-key vip-vi-basic-map | 4070 (define-key vip-vi-basic-map |
4071 (char-to-string vip-buffer-search-char) 'vip-command-argument) | 4071 (char-to-string vip-buffer-search-char) 'vip-command-argument) |
4072 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | 4072 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) |
4073 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | 4073 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) |
4074 | 4074 |
4075 ;; This is a Viper wraper for isearch-forward. | 4075 ;; This is a Viper wrapper for isearch-forward. |
4076 (defun vip-isearch-forward (arg) | 4076 (defun vip-isearch-forward (arg) |
4077 "Do incremental search forward." | 4077 "Do incremental search forward." |
4078 (interactive "P") | 4078 (interactive "P") |
4079 ;; emacs bug workaround | 4079 ;; emacs bug workaround |
4080 (if (listp arg) (setq arg (car arg))) | 4080 (if (listp arg) (setq arg (car arg))) |
4081 (vip-exec-form-in-emacs (list 'isearch-forward arg))) | 4081 (vip-exec-form-in-emacs (list 'isearch-forward arg))) |
4082 | 4082 |
4083 ;; This is a Viper wraper for isearch-backward." | 4083 ;; This is a Viper wrapper for isearch-backward." |
4084 (defun vip-isearch-backward (arg) | 4084 (defun vip-isearch-backward (arg) |
4085 "Do incremental search backward." | 4085 "Do incremental search backward." |
4086 (interactive "P") | 4086 (interactive "P") |
4087 ;; emacs bug workaround | 4087 ;; emacs bug workaround |
4088 (if (listp arg) (setq arg (car arg))) | 4088 (if (listp arg) (setq arg (car arg))) |
4386 (delete-backward-char 1 t))) | 4386 (delete-backward-char 1 t))) |
4387 | 4387 |
4388 (defun vip-del-backward-char-in-replace () | 4388 (defun vip-del-backward-char-in-replace () |
4389 "Delete one character in replace mode. | 4389 "Delete one character in replace mode. |
4390 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes | 4390 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes |
4391 charecters. If it is nil, then the cursor just moves backwards, similarly | 4391 characters. If it is nil, then the cursor just moves backwards, similarly |
4392 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the | 4392 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the |
4393 cursor move past the beginning of line." | 4393 cursor move past the beginning of line." |
4394 (interactive) | 4394 (interactive) |
4395 (cond (vip-delete-backwards-in-replace | 4395 (cond (vip-delete-backwards-in-replace |
4396 (cond ((not (bolp)) | 4396 (cond ((not (bolp)) |
4514 | 4514 |
4515 ;; query replace | 4515 ;; query replace |
4516 | 4516 |
4517 (defun vip-query-replace () | 4517 (defun vip-query-replace () |
4518 "Query replace. | 4518 "Query replace. |
4519 If a null string is suplied as the string to be replaced, | 4519 If a null string is supplied as the string to be replaced, |
4520 the query replace mode will toggle between string replace | 4520 the query replace mode will toggle between string replace |
4521 and regexp replace." | 4521 and regexp replace." |
4522 (interactive) | 4522 (interactive) |
4523 (let (str) | 4523 (let (str) |
4524 (setq str (vip-read-string-with-history | 4524 (setq str (vip-read-string-with-history |
5440 | 5440 |
5441 ;; toggle case sensitivity in search | 5441 ;; toggle case sensitivity in search |
5442 (vip-record-kbd-macro | 5442 (vip-record-kbd-macro |
5443 "//" 'vi-state | 5443 "//" 'vi-state |
5444 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) | 5444 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
5445 ;; toggle regexp/vanila search | 5445 ;; toggle regexp/vanilla search |
5446 (vip-record-kbd-macro | 5446 (vip-record-kbd-macro |
5447 "///" 'vi-state | 5447 "///" 'vi-state |
5448 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) | 5448 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
5449 | 5449 |
5450 | 5450 |
5458 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | 5458 (vip-add-keymap vip-mode-map vip-vi-global-user-map) |
5459 | 5459 |
5460 | 5460 |
5461 ;; Applying Viper customization -- runs after (load .vip) | 5461 ;; Applying Viper customization -- runs after (load .vip) |
5462 | 5462 |
5463 ;; Save user settings or Viper defaults for vars controled by vip-expert-level | 5463 ;; Save user settings or Viper defaults for vars controlled by vip-expert-level |
5464 (setq vip-saved-user-settings | 5464 (setq vip-saved-user-settings |
5465 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) | 5465 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) |
5466 (cons 'vip-always vip-always) | 5466 (cons 'vip-always vip-always) |
5467 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) | 5467 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) |
5468 (cons 'vip-ex-style-motion vip-ex-style-motion) | 5468 (cons 'vip-ex-style-motion vip-ex-style-motion) |