comparison lisp/viper/viper-cmd.el @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents bfd6434d15b3
children acd284d43ca1
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
14 (defvar viper-minibuffer-emacs-face) 14 (defvar viper-minibuffer-emacs-face)
15 (defvar viper-always) 15 (defvar viper-always)
16 (defvar viper-mode-string) 16 (defvar viper-mode-string)
17 (defvar viper-custom-file-name) 17 (defvar viper-custom-file-name)
18 (defvar iso-accents-mode) 18 (defvar iso-accents-mode)
19 (defvar quail-mode)
20 (defvar quail-current-str)
19 (defvar zmacs-region-stays) 21 (defvar zmacs-region-stays)
20 (defvar mark-even-if-inactive) 22 (defvar mark-even-if-inactive)
21 23
22 ;; loading happens only in non-interactive compilation 24 ;; loading happens only in non-interactive compilation
23 ;; in order to spare non-viperized emacs from being viperized 25 ;; in order to spare non-viperized emacs from being viperized
159 (if (stringp viper-saved-cursor-color) 161 (if (stringp viper-saved-cursor-color)
160 (viper-change-cursor-color viper-insert-state-cursor-color)) 162 (viper-change-cursor-color viper-insert-state-cursor-color))
161 )) 163 ))
162 (if (and (eq this-command 'dabbrev-expand) 164 (if (and (eq this-command 'dabbrev-expand)
163 (integerp viper-pre-command-point) 165 (integerp viper-pre-command-point)
166 (markerp viper-insert-point)
167 (marker-position viper-insert-point)
164 (> viper-insert-point viper-pre-command-point)) 168 (> viper-insert-point viper-pre-command-point))
165 (move-marker viper-insert-point viper-pre-command-point)) 169 (viper-move-marker-locally viper-insert-point viper-pre-command-point))
166 ) 170 )
167 171
168 (defsubst viper-insert-state-pre-command-sentinel () 172 (defsubst viper-insert-state-pre-command-sentinel ()
169 (or (memq this-command '(self-insert-command)) 173 (or (memq this-command '(self-insert-command))
170 (memq (viper-event-key last-command-event) 174 (memq (viper-event-key last-command-event)
215 ((eq viper-current-state 'replace-state) 219 ((eq viper-current-state 'replace-state)
216 ;; delete characters to compensate for inserted chars. 220 ;; delete characters to compensate for inserted chars.
217 (let ((replace-boundary (viper-replace-end))) 221 (let ((replace-boundary (viper-replace-end)))
218 (save-excursion 222 (save-excursion
219 (goto-char viper-last-posn-in-replace-region) 223 (goto-char viper-last-posn-in-replace-region)
224 (viper-trim-replace-chars-to-delete-if-necessary)
220 (delete-char viper-replace-chars-to-delete) 225 (delete-char viper-replace-chars-to-delete)
221 (setq viper-replace-chars-to-delete 0 226 (setq viper-replace-chars-to-delete 0)
222 viper-replace-chars-deleted 0)
223 ;; terminate replace mode if reached replace limit 227 ;; terminate replace mode if reached replace limit
224 (if (= viper-last-posn-in-replace-region 228 (if (= viper-last-posn-in-replace-region (viper-replace-end))
225 (viper-replace-end)) 229 (viper-finish-change)))
226 (viper-finish-change viper-last-posn-in-replace-region)))
227 230
228 (if (and (<= (viper-replace-start) (point)) 231 (if (viper-pos-within-region
229 (<= (point) replace-boundary)) 232 (point) (viper-replace-start) replace-boundary)
230 (progn 233 (progn
231 ;; the state may have changed in viper-finish-change above 234 ;; the state may have changed in viper-finish-change above
232 (if (eq viper-current-state 'replace-state) 235 (if (eq viper-current-state 'replace-state)
233 (viper-change-cursor-color viper-replace-overlay-cursor-color)) 236 (viper-change-cursor-color viper-replace-overlay-cursor-color))
234 (setq viper-last-posn-in-replace-region (point-marker)))) 237 (setq viper-last-posn-in-replace-region (point-marker))))
235 )) 238 ))
236 239 ;; terminate replace mode if changed Viper states.
237 (t ;; terminate replace mode if changed Viper states. 240 (t (viper-finish-change))))
238 (viper-finish-change viper-last-posn-in-replace-region))))
239 241
240 242
241 ;; changing mode 243 ;; changing mode
242 244
243 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. 245 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
284 286
285 (if (> (length viper-last-insertion) 0) 287 (if (> (length viper-last-insertion) 0)
286 (viper-push-onto-ring viper-last-insertion 288 (viper-push-onto-ring viper-last-insertion
287 'viper-insertion-ring)) 289 'viper-insertion-ring))
288 290
289 (if viper-ex-style-editing-in-insert 291 (if viper-ex-style-editing
290 (or (bolp) (backward-char 1)))) 292 (or (bolp) (backward-char 1))))
291 )) 293 ))
292 294
293 ;; insert or replace 295 ;; insert or replace
294 ((memq new-state '(insert-state replace-state)) 296 ((memq new-state '(insert-state replace-state))
303 ) ; outermost cond 305 ) ; outermost cond
304 306
305 ;; Nothing needs to be done to switch to emacs mode! Just set some 307 ;; Nothing needs to be done to switch to emacs mode! Just set some
306 ;; variables, which is already done in viper-change-state-to-emacs! 308 ;; variables, which is already done in viper-change-state-to-emacs!
307 309
310 ;; ISO accents
311 ;; always turn off iso-accents-mode in vi-state, or else we won't be able to
312 ;; use the keys `,',^ , as they will do accents instead of Vi actions.
313 (cond ((eq new-state 'vi-state) (viper-set-iso-accents-mode nil));accents off
314 (viper-automatic-iso-accents (viper-set-iso-accents-mode t));accents on
315 (t (viper-set-iso-accents-mode nil)))
316 ;; Always turn off quail mode in vi state
317 (cond ((eq new-state 'vi-state) (viper-set-input-method nil)) ;intl input off
318 (viper-special-input-method (viper-set-input-method t)) ;intl input on
319 (t (viper-set-input-method nil)))
320
308 (setq viper-current-state new-state) 321 (setq viper-current-state new-state)
322
323 (viper-update-syntax-classes)
309 (viper-normalize-minor-mode-map-alist) 324 (viper-normalize-minor-mode-map-alist)
310 (viper-adjust-keys-for new-state) 325 (viper-adjust-keys-for new-state)
311 (viper-set-mode-vars-for new-state) 326 (viper-set-mode-vars-for new-state)
312 (viper-refresh-mode-line) 327 (viper-refresh-mode-line)
313 ) 328 )
331 (setq viper-insert-diehard-minor-mode 346 (setq viper-insert-diehard-minor-mode
332 (not viper-want-emacs-keys-in-insert)) 347 (not viper-want-emacs-keys-in-insert))
333 348
334 (if viper-want-ctl-h-help 349 (if viper-want-ctl-h-help
335 (progn 350 (progn
351 (define-key viper-insert-basic-map [backspace] 'help-command)
352 (define-key viper-replace-map [backspace] 'help-command)
336 (define-key viper-insert-basic-map [(control h)] 'help-command) 353 (define-key viper-insert-basic-map [(control h)] 'help-command)
337 (define-key viper-replace-map [(control h)] 'help-command)) 354 (define-key viper-replace-map [(control h)] 'help-command))
355 (define-key viper-insert-basic-map
356 [backspace] 'viper-del-backward-char-in-insert)
357 (define-key viper-replace-map
358 [backspace] 'viper-del-backward-char-in-replace)
338 (define-key viper-insert-basic-map 359 (define-key viper-insert-basic-map
339 [(control h)] 'viper-del-backward-char-in-insert) 360 [(control h)] 'viper-del-backward-char-in-insert)
340 (define-key viper-replace-map 361 (define-key viper-replace-map
341 [(control h)] 'viper-del-backward-char-in-replace))) 362 [(control h)] 'viper-del-backward-char-in-replace)))
342 363
343 (t ; Vi state 364 (t ; Vi state
344 (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi)) 365 (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi))
345 (if viper-want-ctl-h-help 366 (if viper-want-ctl-h-help
346 (define-key viper-vi-basic-map [(control h)] 'help-command) 367 (progn
368 (define-key viper-vi-basic-map [backspace] 'help-command)
369 (define-key viper-vi-basic-map [(control h)] 'help-command))
370 (define-key viper-vi-basic-map [backspace] 'viper-backward-char)
347 (define-key viper-vi-basic-map [(control h)] 'viper-backward-char))) 371 (define-key viper-vi-basic-map [(control h)] 'viper-backward-char)))
348 )) 372 ))
349 373
350 374
351 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first. 375 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
535 viper-open-line viper-Open-line 559 viper-open-line viper-Open-line
536 viper-replace-state-exit-cmd)) 560 viper-replace-state-exit-cmd))
537 (viper-over-whitespace-line)) 561 (viper-over-whitespace-line))
538 (indent-to-left-margin)) 562 (indent-to-left-margin))
539 (viper-add-newline-at-eob-if-necessary) 563 (viper-add-newline-at-eob-if-necessary)
540 (if viper-undo-needs-adjustment (viper-adjust-undo)) 564 (viper-adjust-undo)
541 (viper-change-state 'vi-state) 565 (viper-change-state 'vi-state)
542
543 ;; always turn off iso-accents-mode, or else we won't be able to use the
544 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
545 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
546 (iso-accents-mode -1))
547 566
548 (viper-restore-cursor-color-after-insert) 567 (viper-restore-cursor-color-after-insert)
549 568
550 ;; Protection against user errors in hooks 569 ;; Protect against user errors in hooks
551 (condition-case conds 570 (condition-case conds
552 (run-hooks 'viper-vi-state-hook) 571 (run-hooks 'viper-vi-state-hook)
553 (error 572 (error
554 (viper-message-conditions conds))))) 573 (viper-message-conditions conds)))))
555 574
556 (defun viper-change-state-to-insert () 575 (defun viper-change-state-to-insert ()
557 "Change Viper state to Insert." 576 "Change Viper state to Insert."
558 (interactive) 577 (interactive)
559 (viper-change-state 'insert-state) 578 (viper-change-state 'insert-state)
560 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode))
561 (iso-accents-mode 1)) ; turn iso accents on
562 579
563 (or (stringp viper-saved-cursor-color) 580 (or (stringp viper-saved-cursor-color)
564 (string= (viper-get-cursor-color) viper-insert-state-cursor-color) 581 (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
565 (setq viper-saved-cursor-color (viper-get-cursor-color))) 582 (setq viper-saved-cursor-color (viper-get-cursor-color)))
566 ;; Commented out, because if viper-change-state-to-insert is executed 583 ;; Commented out, because if viper-change-state-to-insert is executed
567 ;; non-interactively then the old cursor color may get lost. Same old Emacs 584 ;; non-interactively then the old cursor color may get lost. Same old Emacs
568 ;; bug related to local variables? 585 ;; bug related to local variables?
569 ;;;(if (stringp viper-saved-cursor-color) 586 ;;;(if (stringp viper-saved-cursor-color)
570 ;;; (viper-change-cursor-color viper-insert-state-cursor-color)) 587 ;;; (viper-change-cursor-color viper-insert-state-cursor-color))
571 ;; Protection against user errors in hooks 588
589 ;; Protect against user errors in hooks
572 (condition-case conds 590 (condition-case conds
573 (run-hooks 'viper-insert-state-hook) 591 (run-hooks 'viper-insert-state-hook)
574 (error 592 (error
575 (viper-message-conditions conds)))) 593 (viper-message-conditions conds))))
576 594
582 600
583 ;; Change to replace state. When the end of replacement region is reached, 601 ;; Change to replace state. When the end of replacement region is reached,
584 ;; replace state changes to insert state. 602 ;; replace state changes to insert state.
585 (defun viper-change-state-to-replace (&optional non-R-cmd) 603 (defun viper-change-state-to-replace (&optional non-R-cmd)
586 (viper-change-state 'replace-state) 604 (viper-change-state 'replace-state)
587 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode))
588 (iso-accents-mode 1)) ; turn iso accents on
589 ;; Run insert-state-hook 605 ;; Run insert-state-hook
590 (condition-case conds 606 (condition-case conds
591 (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook) 607 (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook)
592 (error 608 (error
593 (viper-message-conditions conds))) 609 (viper-message-conditions conds)))
601 617
602 (defun viper-change-state-to-emacs () 618 (defun viper-change-state-to-emacs ()
603 "Change Viper state to Emacs." 619 "Change Viper state to Emacs."
604 (interactive) 620 (interactive)
605 (viper-change-state 'emacs-state) 621 (viper-change-state 'emacs-state)
606 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode)) 622
607 (iso-accents-mode 1)) ; turn iso accents on 623 ;; Protect agains user errors in hooks
608
609 ;; Protection agains user errors in hooks
610 (condition-case conds 624 (condition-case conds
611 (run-hooks 'viper-emacs-state-hook) 625 (run-hooks 'viper-emacs-state-hook)
612 (error 626 (error
613 (viper-message-conditions conds)))) 627 (viper-message-conditions conds))))
614 628
1123 (get-register reg) "") 1137 (get-register reg) "")
1124 (buffer-substring start end)))) 1138 (buffer-substring start end))))
1125 1139
1126 ;; Saves last inserted text for possible use by viper-repeat command. 1140 ;; Saves last inserted text for possible use by viper-repeat command.
1127 (defun viper-save-last-insertion (beg end) 1141 (defun viper-save-last-insertion (beg end)
1142 (condition-case nil
1143 (setq viper-last-insertion (buffer-substring beg end))
1144 (error
1145 ;; beg or end marker are somehow screwed up
1146 (setq viper-last-insertion nil)))
1128 (setq viper-last-insertion (buffer-substring beg end)) 1147 (setq viper-last-insertion (buffer-substring beg end))
1129 (or (< (length viper-d-com) 5) 1148 (or (< (length viper-d-com) 5)
1130 (setcar (nthcdr 4 viper-d-com) viper-last-insertion)) 1149 (setcar (nthcdr 4 viper-d-com) viper-last-insertion))
1131 (or (null viper-command-ring) 1150 (or (null viper-command-ring)
1132 (ring-empty-p viper-command-ring) 1151 (ring-empty-p viper-command-ring)
1393 (setq viper-last-insertion (nth 4 viper-d-com) 1412 (setq viper-last-insertion (nth 4 viper-d-com)
1394 viper-d-char (nth 4 viper-d-com))) 1413 viper-d-char (nth 4 viper-d-com)))
1395 (funcall m-com (cons val com)) 1414 (funcall m-com (cons val com))
1396 (cond ((and (< save-point (point)) viper-keep-point-on-repeat) 1415 (cond ((and (< save-point (point)) viper-keep-point-on-repeat)
1397 (goto-char save-point)) ; go back to before repeat. 1416 (goto-char save-point)) ; go back to before repeat.
1398 ((and (< save-point (point)) viper-ex-style-editing-in-insert) 1417 ((and (< save-point (point)) viper-ex-style-editing)
1399 (or (bolp) (backward-char 1)))) 1418 (or (bolp) (backward-char 1))))
1400 (if (and (eolp) (not (bolp))) 1419 (if (and (eolp) (not (bolp)))
1401 (backward-char 1)) 1420 (backward-char 1))
1402 )) 1421 ))
1403 (if viper-undo-needs-adjustment (viper-adjust-undo)) ; take care of undo 1422 (viper-adjust-undo) ; take care of undo
1404 ;; If the prev cmd was rotating the command ring, this means that `.' has 1423 ;; If the prev cmd was rotating the command ring, this means that `.' has
1405 ;; just executed a command from that ring. So, push it on the ring again. 1424 ;; just executed a command from that ring. So, push it on the ring again.
1406 ;; If we are just executing previous command , then don't push viper-d-com 1425 ;; If we are just executing previous command , then don't push viper-d-com
1407 ;; because viper-d-com is not fully constructed in this case (its keys and 1426 ;; because viper-d-com is not fully constructed in this case (its keys and
1408 ;; the inserted text may be nil). Besides, in this case, the command 1427 ;; the inserted text may be nil). Besides, in this case, the command
1493 (progn 1512 (progn
1494 (push-mark (point-marker) t) 1513 (push-mark (point-marker) t)
1495 (viper-sit-for-short 300) 1514 (viper-sit-for-short 300)
1496 (goto-char undo-end-posn) 1515 (goto-char undo-end-posn)
1497 (viper-sit-for-short 300) 1516 (viper-sit-for-short 300)
1498 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) 1517 (if (and (> (viper-chars-in-region undo-beg-posn before-undo-pt) 1)
1499 (> (abs (- undo-end-posn before-undo-pt)) 1)) 1518 (> (viper-chars-in-region undo-end-posn before-undo-pt) 1))
1500 (goto-char before-undo-pt) 1519 (goto-char before-undo-pt)
1501 (goto-char undo-beg-posn))) 1520 (goto-char undo-beg-posn)))
1502 (push-mark before-undo-pt t)) 1521 (push-mark before-undo-pt t))
1503 (if (and (eolp) (not (bolp))) (backward-char 1)) 1522 (if (and (eolp) (not (bolp))) (backward-char 1))
1504 (if (not modified) (set-buffer-modified-p t))) 1523 (if (not modified) (set-buffer-modified-p t)))
1516 1535
1517 ;; The following two functions are used to set up undo properly. 1536 ;; The following two functions are used to set up undo properly.
1518 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, 1537 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
1519 ;; they are undone all at once. 1538 ;; they are undone all at once.
1520 (defun viper-adjust-undo () 1539 (defun viper-adjust-undo ()
1521 (let ((inhibit-quit t) 1540 (if viper-undo-needs-adjustment
1522 tmp tmp2) 1541 (let ((inhibit-quit t)
1523 (setq viper-undo-needs-adjustment nil) 1542 tmp tmp2)
1524 (if (listp buffer-undo-list) 1543 (setq viper-undo-needs-adjustment nil)
1525 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list)) 1544 (if (listp buffer-undo-list)
1526 (progn 1545 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
1527 (setq tmp2 (cdr tmp)) ; the part after mark 1546 (progn
1528 1547 (setq tmp2 (cdr tmp)) ; the part after mark
1529 ;; cut tail from buffer-undo-list temporarily by direct 1548
1530 ;; manipulation with pointers in buffer-undo-list 1549 ;; cut tail from buffer-undo-list temporarily by direct
1531 (setcdr tmp nil) 1550 ;; manipulation with pointers in buffer-undo-list
1532 1551 (setcdr tmp nil)
1533 (setq buffer-undo-list (delq nil buffer-undo-list)) 1552
1534 (setq buffer-undo-list 1553 (setq buffer-undo-list (delq nil buffer-undo-list))
1535 (delq viper-buffer-undo-list-mark buffer-undo-list)) 1554 (setq buffer-undo-list
1536 ;; restore tail of buffer-undo-list 1555 (delq viper-buffer-undo-list-mark buffer-undo-list))
1537 (setq buffer-undo-list (nconc buffer-undo-list tmp2))) 1556 ;; restore tail of buffer-undo-list
1538 (setq buffer-undo-list (delq nil buffer-undo-list)))))) 1557 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
1558 (setq buffer-undo-list (delq nil buffer-undo-list)))))
1559 ))
1539 1560
1540 1561
1541 (defun viper-set-complex-command-for-undo () 1562 (defun viper-set-complex-command-for-undo ()
1542 (if (listp buffer-undo-list) 1563 (if (listp buffer-undo-list)
1543 (if (not viper-undo-needs-adjustment) 1564 (if (not viper-undo-needs-adjustment)
1558 1579
1559 (message " `.' runs %s%s" 1580 (message " `.' runs %s%s"
1560 (concat "`" (viper-array-to-string keys) "'") 1581 (concat "`" (viper-array-to-string keys) "'")
1561 (viper-abbreviate-string 1582 (viper-abbreviate-string
1562 (if viper-xemacs-p 1583 (if viper-xemacs-p
1563 (replace-in-string text "\n" "^J") 1584 (replace-in-string
1585 (cond ((characterp text) (char-to-string text))
1586 ((stringp text) text)
1587 (t ""))
1588 "\n" "^J")
1564 text) 1589 text)
1565 max-text-len 1590 max-text-len
1566 " inserting `" "'" " .......")) 1591 " inserting `" "'" " ......."))
1567 )) 1592 ))
1568 1593
1745 'viper-change-state-to-insert 1770 'viper-change-state-to-insert
1746 'viper-change-state-to-emacs))) 1771 'viper-change-state-to-emacs)))
1747 (funcall hook) 1772 (funcall hook)
1748 )) 1773 ))
1749 1774
1750 ;; Interpret last event in the local map 1775 ;; Interpret last event in the local map first; if fails, use exit-minibuffer.
1776 ;; Run viper-minibuffer-exit-hook before exiting.
1751 (defun viper-exit-minibuffer () 1777 (defun viper-exit-minibuffer ()
1778 "Exit minibuffer Viper way."
1752 (interactive) 1779 (interactive)
1753 (let (command) 1780 (let (command)
1754 (setq command (local-key-binding (char-to-string last-command-char))) 1781 (setq command (local-key-binding (char-to-string last-command-char)))
1782 (run-hooks 'viper-minibuffer-exit-hook)
1755 (if command 1783 (if command
1756 (command-execute command) 1784 (command-execute command)
1757 (exit-minibuffer)))) 1785 (exit-minibuffer))))
1758 1786
1787
1788 (defcustom viper-smart-suffix-list
1789 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
1790 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
1791 This is useful when you the current directory contains files with the same
1792 prefix and many different suffixes. Usually, only one of the suffixes
1793 represents an editable file. However, file completion will stop at the `.'
1794 The smart suffix feature lets you hit RET in such a case, and Viper will
1795 select the appropriate suffix.
1796
1797 Suffixes are tried in the order given and the first suffix for which a
1798 corresponding file exists is selected. If no file exists for any of the
1799 suffixes, the user is asked to confirm.
1800
1801 To turn this feature off, set this variable to nil."
1802 :type '(set string)
1803 :group 'viper)
1804
1805
1806 ;; Try to add a suitable suffix to files whose name ends with a `.'
1807 ;; Useful when the user hits RET on a non-completed file name.
1808 ;; Used as a minibuffer exit hook in read-file-name
1809 (defun viper-file-add-suffix ()
1810 (let ((count 0)
1811 (len (length viper-smart-suffix-list))
1812 (file (buffer-string))
1813 found key cmd suff)
1814 (goto-char (point-max))
1815 (if (and viper-smart-suffix-list (string-match "\\.$" file))
1816 (progn
1817 (while (and (not found) (< count len))
1818 (setq suff (nth count viper-smart-suffix-list)
1819 count (1+ count))
1820 (if (file-exists-p
1821 (format "%s%s" (substitute-in-file-name file) suff))
1822 (progn
1823 (setq found t)
1824 (insert suff))))
1825
1826 (if found
1827 ()
1828 (viper-tmp-insert-at-eob " [Please complete file name]")
1829 (unwind-protect
1830 (while (not (memq cmd
1831 '(exit-minibuffer viper-exit-minibuffer)))
1832 (setq cmd
1833 (key-binding (setq key (read-key-sequence nil))))
1834 (cond ((eq cmd 'self-insert-command)
1835 (if viper-xemacs-p
1836 (insert (events-to-keys key))
1837 (insert key)))
1838 ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
1839 nil)
1840 (t (command-execute cmd)))
1841 )))
1842 ))))
1843
1844
1845 (defun viper-minibuffer-trim-tail ()
1846 "Delete junk at the end of the first line of the minibuffer input.
1847 Remove this function from `viper-minibuffer-exit-hook', if this causes
1848 problems."
1849 (if (viper-is-in-minibuffer)
1850 (progn
1851 (goto-char (point-min))
1852 (end-of-line)
1853 (delete-region (point) (point-max)))))
1854
1759 1855
1760 ;;; Reading string with history 1856 ;;; Reading string with history
1761 1857
1762 (defun viper-read-string-with-history (prompt &optional initial 1858 (defun viper-read-string-with-history (prompt &optional initial
1763 history-var default keymap) 1859 history-var default keymap)
1890 (com (viper-getcom arg))) 1986 (com (viper-getcom arg)))
1891 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil)) 1987 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil))
1892 (let ((col (current-indentation))) 1988 (let ((col (current-indentation)))
1893 (if (equal com ?r) 1989 (if (equal com ?r)
1894 (viper-loop val 1990 (viper-loop val
1895 (progn
1896 (end-of-line) 1991 (end-of-line)
1897 (newline 1) 1992 (newline 1)
1898 (if viper-auto-indent 1993 (if viper-auto-indent
1899 (progn 1994 (progn
1900 (setq viper-cted t) 1995 (setq viper-cted t)
1901 (if viper-electric-mode 1996 (if viper-electric-mode
1902 (indent-according-to-mode) 1997 (indent-according-to-mode)
1903 (indent-to col)) 1998 (indent-to col))
1904 )) 1999 ))
1905 (viper-yank-last-insertion))) 2000 (viper-yank-last-insertion))
1906 (end-of-line) 2001 (end-of-line)
1907 (newline 1) 2002 (newline 1)
1908 (if viper-auto-indent 2003 (if viper-auto-indent
1909 (progn 2004 (progn
1910 (setq viper-cted t) 2005 (setq viper-cted t)
1921 (com (viper-getcom arg))) 2016 (com (viper-getcom arg)))
1922 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil)) 2017 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil))
1923 (let ((col (current-indentation))) 2018 (let ((col (current-indentation)))
1924 (if (equal com ?r) 2019 (if (equal com ?r)
1925 (viper-loop val 2020 (viper-loop val
1926 (progn
1927 (beginning-of-line) 2021 (beginning-of-line)
1928 (open-line 1) 2022 (open-line 1)
1929 (if viper-auto-indent 2023 (if viper-auto-indent
1930 (progn 2024 (progn
1931 (setq viper-cted t) 2025 (setq viper-cted t)
1932 (if viper-electric-mode 2026 (if viper-electric-mode
1933 (indent-according-to-mode) 2027 (indent-according-to-mode)
1934 (indent-to col)) 2028 (indent-to col))
1935 )) 2029 ))
1936 (viper-yank-last-insertion))) 2030 (viper-yank-last-insertion))
1937 (beginning-of-line) 2031 (beginning-of-line)
1938 (open-line 1) 2032 (open-line 1)
1939 (if viper-auto-indent 2033 (if viper-auto-indent
1940 (progn 2034 (progn
1941 (setq viper-cted t) 2035 (setq viper-cted t)
1953 (com (viper-getcom arg))) 2047 (com (viper-getcom arg)))
1954 (viper-set-destructive-command 2048 (viper-set-destructive-command
1955 (list 'viper-open-line-at-point val ?r nil nil nil)) 2049 (list 'viper-open-line-at-point val ?r nil nil nil))
1956 (if (equal com ?r) 2050 (if (equal com ?r)
1957 (viper-loop val 2051 (viper-loop val
1958 (progn
1959 (open-line 1) 2052 (open-line 1)
1960 (viper-yank-last-insertion))) 2053 (viper-yank-last-insertion))
1961 (open-line 1) 2054 (open-line 1)
1962 (viper-change-state-to-insert)))) 2055 (viper-change-state-to-insert))))
1963 2056
1964 (defun viper-substitute (arg) 2057 (defun viper-substitute (arg)
1965 "Substitute characters." 2058 "Substitute characters."
1983 2076
1984 ;; Prepare for replace 2077 ;; Prepare for replace
1985 (defun viper-start-replace () 2078 (defun viper-start-replace ()
1986 (setq viper-began-as-replace t 2079 (setq viper-began-as-replace t
1987 viper-sitting-in-replace t 2080 viper-sitting-in-replace t
1988 viper-replace-chars-to-delete 0 2081 viper-replace-chars-to-delete 0)
1989 viper-replace-chars-deleted 0)
1990 (viper-add-hook 2082 (viper-add-hook
1991 'viper-after-change-functions 'viper-replace-mode-spy-after t) 2083 'viper-after-change-functions 'viper-replace-mode-spy-after t)
1992 (viper-add-hook 2084 (viper-add-hook
1993 'viper-before-change-functions 'viper-replace-mode-spy-before t) 2085 'viper-before-change-functions 'viper-replace-mode-spy-before t)
1994 ;; this will get added repeatedly, but no harm 2086 ;; this will get added repeatedly, but no harm
2005 'viper-post-command-hooks 'viper-R-state-post-command-sentinel) 2097 'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
2006 (if overwrite-mode (overwrite-mode nil)) 2098 (if overwrite-mode (overwrite-mode nil))
2007 ) 2099 )
2008 2100
2009 2101
2010 ;; checks how many chars were deleted by the last change
2011 (defun viper-replace-mode-spy-before (beg end) 2102 (defun viper-replace-mode-spy-before (beg end)
2012 (setq viper-replace-chars-deleted 2103 (setq viper-replace-region-chars-deleted (viper-chars-in-region beg end))
2013 (- end beg 2104 )
2014 (max 0 (- end (viper-replace-end))) 2105
2015 (max 0 (- (viper-replace-start) beg)) 2106 ;; Invoked as an after-change-function to calculate how many chars have to be
2016 ))) 2107 ;; deleted. This function may be called several times within a single command,
2017 2108 ;; if this command performs several separate buffer changes. Therefore, if adds
2018 ;; Invoked as an after-change-function to set up parameters of the last change 2109 ;; up the number of chars inserted and subtracts the number of chars deleted.
2019 (defun viper-replace-mode-spy-after (beg end length) 2110 (defun viper-replace-mode-spy-after (beg end length)
2020 (if (memq viper-intermediate-command '(repeating-insertion-from-ring)) 2111 (if (memq viper-intermediate-command
2112 '(dabbrev-expand repeating-insertion-from-ring))
2113 ;; Take special care of text insertion from insertion ring inside
2114 ;; replacement overlays.
2021 (progn 2115 (progn
2022 (setq viper-replace-chars-to-delete 0) 2116 (setq viper-replace-chars-to-delete 0)
2023 (viper-move-marker-locally 2117 (viper-move-marker-locally
2024 'viper-last-posn-in-replace-region (point))) 2118 'viper-last-posn-in-replace-region (point)))
2025 2119
2026 (let (beg-col end-col real-end chars-to-delete) 2120 (let* ((real-end (min end (viper-replace-end)))
2027 (setq real-end (min end (viper-replace-end))) 2121 (column-shift (- (save-excursion (goto-char real-end)
2028 (save-excursion 2122 (current-column))
2029 (goto-char beg) 2123 (save-excursion (goto-char beg)
2030 (setq beg-col (current-column)) 2124 (current-column))))
2031 (goto-char real-end) 2125 (chars-deleted 0))
2032 (setq end-col (current-column))) 2126
2033 2127 (if (> length 0)
2034 ;; If beg of change is outside the replacement region, then don't 2128 (setq chars-deleted viper-replace-region-chars-deleted))
2035 ;; delete anything in the repl region (set chars-to-delete to 0). 2129 (setq viper-replace-region-chars-deleted 0)
2036 ;; 2130 (setq viper-replace-chars-to-delete
2037 ;; This works fine except that we have to take special care of 2131 (+ viper-replace-chars-to-delete
2038 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which 2132 (-
2039 ;; sometimes simply shifts the repl region rightwards, without 2133 ;; if column shift is bigger, due to a TAB insertion, take
2040 ;; deleting an equal amount of characters. 2134 ;; column-shift instead of the number of inserted chars
2041 ;; 2135 (max (viper-chars-in-region beg real-end)
2042 ;; The reason why new-dabbrev.el causes this are this: 2136 ;; This test accounts for Chinese/Japanese/... chars,
2043 ;; if one dinamically completes a partial word that starts before the 2137 ;; which occupy 2 columns instead of one. If we use
2044 ;; replacement region (but ends inside) then new-dabbrev.el first 2138 ;; column-shift here, we may delete two chars instead of
2045 ;; moves cursor backwards, to the beginning of the word to be 2139 ;; one when the user types one Chinese character. Deleting
2046 ;; completed (say, pt A). Then it inserts the 2140 ;; two would be OK, if they were European chars, but it is
2047 ;; completed word and then deletes the old, incomplete part. 2141 ;; not OK if they are Chinese chars. Since it is hard to
2048 ;; Since the complete word is inserted at position before the repl 2142 ;; figure out which characters are being deleted in any
2049 ;; region, the next If-statement would have set chars-to-delete to 0 2143 ;; given region, we decided to treat Eastern and European
2050 ;; unless we check for the current command, which must be 2144 ;; characters equally, even though Eastern chars may
2051 ;; dabbrev-expand. 2145 ;; occupy more columns.
2052 ;; 2146 (if (memq this-command '(self-insert-command
2053 ;; In fact, it might be also useful to have overlays for insert 2147 quoted-insert viper-insert-tab))
2054 ;; regions as well, since this will let us capture the situation when 2148 column-shift
2055 ;; dabbrev-expand goes back past the insertion point to find the 2149 0))
2056 ;; beginning of the word to be expanded. 2150 ;; the number of deleted chars
2057 (if (or (and (<= (viper-replace-start) beg) 2151 chars-deleted)))
2058 (<= beg (viper-replace-end))) 2152
2059 (and (= length 0) (eq this-command 'dabbrev-expand)))
2060 (setq chars-to-delete
2061 (max (- end-col beg-col) (- real-end beg) 0))
2062 (setq chars-to-delete 0))
2063
2064 ;; if beg = last change position, it means that we are within the
2065 ;; same command that does multiple changes. Moreover, it means
2066 ;; that we have two subsequent changes (insert/delete) that
2067 ;; complement each other.
2068 (if (= beg (marker-position viper-last-posn-in-replace-region))
2069 (setq viper-replace-chars-to-delete
2070 (- (+ chars-to-delete viper-replace-chars-to-delete)
2071 viper-replace-chars-deleted))
2072 (setq viper-replace-chars-to-delete chars-to-delete))
2073
2074 (viper-move-marker-locally 2153 (viper-move-marker-locally
2075 'viper-last-posn-in-replace-region 2154 'viper-last-posn-in-replace-region
2076 (max (if (> end (viper-replace-end)) (viper-replace-start) end) 2155 (max (if (> end (viper-replace-end)) (viper-replace-end) end)
2077 (or (marker-position viper-last-posn-in-replace-region) 2156 (or (marker-position viper-last-posn-in-replace-region)
2078 (viper-replace-start)) 2157 (viper-replace-start))
2079 )) 2158 ))
2080 2159
2081 (setq viper-replace-chars-to-delete
2082 (max 0
2083 (min viper-replace-chars-to-delete
2084 (- (viper-replace-end) viper-last-posn-in-replace-region)
2085 (- (viper-line-pos 'end)
2086 viper-last-posn-in-replace-region)
2087 )))
2088 ))) 2160 )))
2089 2161
2090 2162 ;; Make sure we don't delete more than needed.
2091 ;; Delete stuff between posn and the end of viper-replace-overlay-marker, if 2163 ;; This is executed at viper-last-posn-in-replace-region
2092 ;; posn is within the overlay. 2164 (defsubst viper-trim-replace-chars-to-delete-if-necessary ()
2093 (defun viper-finish-change (posn) 2165 (setq viper-replace-chars-to-delete
2166 (max 0
2167 (min viper-replace-chars-to-delete
2168 ;; Don't delete more than to the end of repl overlay
2169 (viper-chars-in-region
2170 (viper-replace-end) viper-last-posn-in-replace-region)
2171 ;; point is viper-last-posn-in-replace-region now
2172 ;; So, this limits deletion to the end of line
2173 (viper-chars-in-region (point) (viper-line-pos 'end))
2174 ))))
2175
2176
2177 ;; Delete stuff between viper-last-posn-in-replace-region and the end of
2178 ;; viper-replace-overlay-marker, if viper-last-posn-in-replace-region is within
2179 ;; the overlay and current point is before the end of the overlay.
2180 ;; Don't delete anything if current point is past the end of the overlay.
2181 (defun viper-finish-change ()
2094 (viper-remove-hook 2182 (viper-remove-hook
2095 'viper-after-change-functions 'viper-replace-mode-spy-after) 2183 'viper-after-change-functions 'viper-replace-mode-spy-after)
2096 (viper-remove-hook 2184 (viper-remove-hook
2097 'viper-before-change-functions 'viper-replace-mode-spy-before) 2185 'viper-before-change-functions 'viper-replace-mode-spy-before)
2098 (viper-remove-hook 2186 (viper-remove-hook
2100 (viper-remove-hook 2188 (viper-remove-hook
2101 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel) 2189 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
2102 (viper-restore-cursor-color-after-replace) 2190 (viper-restore-cursor-color-after-replace)
2103 (setq viper-sitting-in-replace nil) ; just in case we'll need to know it 2191 (setq viper-sitting-in-replace nil) ; just in case we'll need to know it
2104 (save-excursion 2192 (save-excursion
2105 (if (and 2193 (if (and viper-replace-overlay
2106 viper-replace-overlay 2194 (viper-pos-within-region viper-last-posn-in-replace-region
2107 (>= posn (viper-replace-start)) 2195 (viper-replace-start)
2108 (< posn (viper-replace-end))) 2196 (viper-replace-end))
2109 (delete-region posn (viper-replace-end))) 2197 (< (point) (viper-replace-end)))
2110 ) 2198 (delete-region
2199 viper-last-posn-in-replace-region (viper-replace-end))))
2111 2200
2112 (if (eq viper-current-state 'replace-state) 2201 (if (eq viper-current-state 'replace-state)
2113 (viper-downgrade-to-insert)) 2202 (viper-downgrade-to-insert))
2114 ;; replace mode ended => nullify viper-last-posn-in-replace-region 2203 ;; replace mode ended => nullify viper-last-posn-in-replace-region
2115 (viper-move-marker-locally 'viper-last-posn-in-replace-region nil) 2204 (viper-move-marker-locally 'viper-last-posn-in-replace-region nil)
2148 2237
2149 (defun viper-replace-state-exit-cmd () 2238 (defun viper-replace-state-exit-cmd ()
2150 "Binding for keys that cause Replace state to switch to Vi or to Insert. 2239 "Binding for keys that cause Replace state to switch to Vi or to Insert.
2151 These keys are ESC, RET, and LineFeed" 2240 These keys are ESC, RET, and LineFeed"
2152 (interactive) 2241 (interactive)
2153 (if overwrite-mode ;; If you are in replace mode invoked via 'R' 2242 (if overwrite-mode ; if in replace mode invoked via 'R'
2154 (viper-finish-R-mode) 2243 (viper-finish-R-mode)
2155 (viper-finish-change viper-last-posn-in-replace-region)) 2244 (viper-finish-change))
2156 (let (com) 2245 (let (com)
2157 (if (eq this-command 'viper-intercept-ESC-key) 2246 (if (eq this-command 'viper-intercept-ESC-key)
2158 (setq com 'viper-exit-insert-state) 2247 (setq com 'viper-exit-insert-state)
2159 (viper-set-unread-command-events last-input-char) 2248 (viper-set-unread-command-events last-input-char)
2160 (setq com (key-binding (read-key-sequence nil)))) 2249 (setq com (key-binding (read-key-sequence nil))))
2267 (if (and (eolp) (bolp)) (error "No character to replace here")) 2356 (if (and (eolp) (bolp)) (error "No character to replace here"))
2268 (let ((val (viper-p-val arg)) 2357 (let ((val (viper-p-val arg))
2269 (com (viper-getcom arg))) 2358 (com (viper-getcom arg)))
2270 (viper-replace-char-subr com val) 2359 (viper-replace-char-subr com val)
2271 (if (and (eolp) (not (bolp))) (forward-char 1)) 2360 (if (and (eolp) (not (bolp))) (forward-char 1))
2361 (setq viper-this-command-keys
2362 (format "%sr" (if (integerp arg) arg "")))
2272 (viper-set-destructive-command 2363 (viper-set-destructive-command
2273 (list 'viper-replace-char val ?r nil viper-d-char nil)) 2364 (list 'viper-replace-char val ?r nil viper-d-char nil))
2274 )) 2365 ))
2275 2366
2276 (defun viper-replace-char-subr (com arg) 2367 (defun viper-replace-char-subr (com arg)
2277 (let ((take-care-of-iso-accents 2368 (let (char)
2278 (and (boundp 'iso-accents-mode) viper-automatic-iso-accents))
2279 char)
2280 (setq char (if (equal com ?r) 2369 (setq char (if (equal com ?r)
2281 viper-d-char 2370 viper-d-char
2282 (read-char))) 2371 (read-char)))
2283 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~))) 2372 (let (inhibit-quit) ; preserve consistency of undo-list and iso-accents
2284 ;; get European characters 2373 (if (and viper-automatic-iso-accents (memq char '(?' ?\" ?^ ?~)))
2285 (progn 2374 ;; get European characters
2286 (iso-accents-mode 1) 2375 (progn
2287 (viper-set-unread-command-events char) 2376 (viper-set-iso-accents-mode t)
2288 (setq char (aref (read-key-sequence nil) 0)) 2377 (viper-set-unread-command-events char)
2289 (iso-accents-mode -1))) 2378 (setq char (aref (read-key-sequence nil) 0))
2290 (delete-char arg t) 2379 (viper-set-iso-accents-mode nil)))
2291 (setq viper-d-char char) 2380 (viper-set-complex-command-for-undo)
2292 (viper-loop (if (> arg 0) arg (- arg)) 2381 (if (eq char ?\C-m) (setq char ?\n))
2293 (if (eq char ?\C-m) (insert "\n") (insert char))) 2382 (if (and viper-special-input-method (fboundp 'quail-start-translation))
2294 (backward-char arg))) 2383 ;; get Intl. characters
2384 (progn
2385 (viper-set-input-method t)
2386 (setq last-command-event
2387 (viper-copy-event
2388 (if viper-xemacs-p (character-to-event char) char)))
2389 (delete-char 1 t)
2390 (condition-case nil
2391 (if com
2392 (insert char)
2393 (if viper-emacs-p
2394 (quail-start-translation 1)
2395 (quail-start-translation)))
2396 (error))
2397 ;; quail translation failed
2398 (if (and (not (stringp quail-current-str))
2399 (not (viper-characterp quail-current-str)))
2400 (progn
2401 (viper-adjust-undo)
2402 (undo-start)
2403 (undo-more 1)
2404 (viper-set-input-method nil)
2405 (error "Composing character failed, changes undone")))
2406 ;; quail translation seems ok
2407 (or com
2408 ;;(setq char quail-current-str))
2409 (setq char (viper-char-at-pos 'backward)))
2410 (setq viper-d-char char)
2411 (viper-loop (1- (if (> arg 0) arg (- arg)))
2412 (delete-char 1 t)
2413 (insert char))
2414 (viper-set-input-method nil))
2415 (delete-char arg t)
2416 (setq viper-d-char char)
2417 (viper-loop (if (> arg 0) arg (- arg))
2418 (insert char)))
2419 (viper-adjust-undo)
2420 (backward-char arg))))
2295 2421
2296 2422
2297 ;; basic cursor movement. j, k, l, h commands. 2423 ;; basic cursor movement. j, k, l, h commands.
2298 2424
2299 (defun viper-forward-char (arg) 2425 (defun viper-forward-char (arg)
2332 (if com (viper-execute-com 'viper-backward-char val com))) 2458 (if com (viper-execute-com 'viper-backward-char val com)))
2333 (backward-char val) 2459 (backward-char val)
2334 (if com (viper-execute-com 'viper-backward-char val com))))) 2460 (if com (viper-execute-com 'viper-backward-char val com)))))
2335 2461
2336 ;; Like forward-char, but doesn't move at end of buffer. 2462 ;; Like forward-char, but doesn't move at end of buffer.
2463 ;; Returns distance traveled
2464 ;; (positive or 0, if arg positive; negative if arg negative).
2337 (defun viper-forward-char-carefully (&optional arg) 2465 (defun viper-forward-char-carefully (&optional arg)
2338 (setq arg (or arg 1)) 2466 (setq arg (or arg 1))
2339 (if (>= (point-max) (+ (point) arg)) 2467 (let ((pt (point)))
2340 (forward-char arg) 2468 (condition-case nil
2341 (goto-char (point-max)))) 2469 (forward-char arg)
2470 (error))
2471 (if (< (point) pt) ; arg was negative
2472 (- (viper-chars-in-region pt (point)))
2473 (viper-chars-in-region pt (point)))))
2342 2474
2343 ;; Like backward-char, but doesn't move at end of buffer. 2475 ;; Like backward-char, but doesn't move at beg of buffer.
2476 ;; Returns distance traveled
2477 ;; (negative or 0, if arg positive; positive if arg negative).
2344 (defun viper-backward-char-carefully (&optional arg) 2478 (defun viper-backward-char-carefully (&optional arg)
2345 (setq arg (or arg 1)) 2479 (setq arg (or arg 1))
2346 (if (<= (point-min) (- (point) arg)) 2480 (let ((pt (point)))
2347 (backward-char arg) 2481 (condition-case nil
2348 (goto-char (point-min)))) 2482 (backward-char arg)
2483 (error))
2484 (if (> (point) pt) ; arg was negative
2485 (viper-chars-in-region pt (point))
2486 (- (viper-chars-in-region pt (point))))))
2349 2487
2350 (defun viper-next-line-carefully (arg) 2488 (defun viper-next-line-carefully (arg)
2351 (condition-case nil 2489 (condition-case nil
2352 (next-line arg) 2490 (next-line arg)
2353 (error nil))) 2491 (error nil)))
2370 (if (looking-at "\n") 2508 (if (looking-at "\n")
2371 (progn 2509 (progn
2372 (forward-char) 2510 (forward-char)
2373 (viper-skip-all-separators-forward 'within-line)))) 2511 (viper-skip-all-separators-forward 'within-line))))
2374 (viper-skip-all-separators-backward 'within-line) 2512 (viper-skip-all-separators-backward 'within-line)
2375 (backward-char) 2513 (viper-backward-char-carefully)
2376 (if (looking-at "\n") 2514 (if (looking-at "\n")
2377 (viper-skip-all-separators-backward 'within-line) 2515 (viper-skip-all-separators-backward 'within-line)
2378 (forward-char)))) 2516 (forward-char))))
2379 2517
2380 (defun viper-forward-word-kernel (val) 2518 (defun viper-forward-word-kernel (val)
2387 ((not (viper-looking-at-alphasep)) 2525 ((not (viper-looking-at-alphasep))
2388 (viper-skip-nonalphasep-forward) 2526 (viper-skip-nonalphasep-forward)
2389 (viper-skip-separators t))) 2527 (viper-skip-separators t)))
2390 (setq val (1- val)))) 2528 (setq val (1- val))))
2391 2529
2392 ;; first search backward for pat. Then skip chars backwards using aux-pat 2530 ;; first skip non-newline separators backward, then skip \n. Then, if TWICE is
2393 (defun viper-fwd-skip (pat aux-pat lim) 2531 ;; non-nil, skip non-\n back again, but don't overshoot the limit LIM.
2394 (if (and (save-excursion 2532 (defun viper-separator-skipback-special (twice lim)
2395 (re-search-backward pat lim t)) 2533 (let ((prev-char (viper-char-at-pos 'backward))
2396 (= (point) (match-end 0))) 2534 (saved-point (point)))
2397 (goto-char (match-beginning 0))) 2535 ;; skip non-newline separators backward
2398 (skip-chars-backward aux-pat lim) 2536 (while (and (not (memq prev-char '(nil \n)))
2399 (if (= (point) lim) 2537 (< lim (point))
2400 (viper-forward-char-carefully)) 2538 ;; must be non-newline separator
2401 ) 2539 (if (eq viper-syntax-preference 'strict-vi)
2540 (memq prev-char '(?\ ?\t))
2541 (memq (char-syntax prev-char) '(?\ ?-))))
2542 (viper-backward-char-carefully)
2543 (setq prev-char (viper-char-at-pos 'backward)))
2544
2545 (if (and (< lim (point)) (eq prev-char ?\n))
2546 (backward-char)
2547 ;; If we skipped to the next word and the prefix of this line doesn't
2548 ;; consist of separators preceded by a newline, then don't skip backwards
2549 ;; at all.
2550 (goto-char saved-point))
2551 (setq prev-char (viper-char-at-pos 'backward))
2552
2553 ;; skip again, but make sure we don't overshoot the limit
2554 (if twice
2555 (while (and (not (memq prev-char '(nil \n)))
2556 (< lim (point))
2557 ;; must be non-newline separator
2558 (if (eq viper-syntax-preference 'strict-vi)
2559 (memq prev-char '(?\ ?\t))
2560 (memq (char-syntax prev-char) '(?\ ?-))))
2561 (viper-backward-char-carefully)
2562 (setq prev-char (viper-char-at-pos 'backward))))
2563
2564 (if (= (point) lim)
2565 (viper-forward-char-carefully))
2566 ))
2402 2567
2403 2568
2404 (defun viper-forward-word (arg) 2569 (defun viper-forward-word (arg)
2405 "Forward word." 2570 "Forward word."
2406 (interactive "P") 2571 (interactive "P")
2409 (com (viper-getcom arg))) 2574 (com (viper-getcom arg)))
2410 (if com (viper-move-marker-locally 'viper-com-point (point))) 2575 (if com (viper-move-marker-locally 'viper-com-point (point)))
2411 (viper-forward-word-kernel val) 2576 (viper-forward-word-kernel val)
2412 (if com (progn 2577 (if com (progn
2413 (cond ((memq com (list ?c (- ?c))) 2578 (cond ((memq com (list ?c (- ?c)))
2414 (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point)) 2579 (viper-separator-skipback-special 'twice viper-com-point))
2415 ;; Yank words including the whitespace, but not newline 2580 ;; Yank words including the whitespace, but not newline
2416 ((memq com (list ?y (- ?y))) 2581 ((memq com (list ?y (- ?y)))
2417 (viper-fwd-skip "\n[ \t]*" "" viper-com-point)) 2582 (viper-separator-skipback-special nil viper-com-point))
2418 ((viper-dotable-command-p com) 2583 ((viper-dotable-command-p com)
2419 (viper-fwd-skip "\n[ \t]*" "" viper-com-point))) 2584 (viper-separator-skipback-special nil viper-com-point)))
2420 (viper-execute-com 'viper-forward-word val com))))) 2585 (viper-execute-com 'viper-forward-word val com)))))
2421 2586
2422 2587
2423 (defun viper-forward-Word (arg) 2588 (defun viper-forward-Word (arg)
2424 "Forward word delimited by white characters." 2589 "Forward word delimited by white characters."
2426 (viper-leave-region-active) 2591 (viper-leave-region-active)
2427 (let ((val (viper-p-val arg)) 2592 (let ((val (viper-p-val arg))
2428 (com (viper-getcom arg))) 2593 (com (viper-getcom arg)))
2429 (if com (viper-move-marker-locally 'viper-com-point (point))) 2594 (if com (viper-move-marker-locally 'viper-com-point (point)))
2430 (viper-loop val 2595 (viper-loop val
2431 (progn
2432 (viper-skip-nonseparators 'forward) 2596 (viper-skip-nonseparators 'forward)
2433 (viper-skip-separators t))) 2597 (viper-skip-separators t))
2434 (if com (progn 2598 (if com (progn
2435 (cond ((memq com (list ?c (- ?c))) 2599 (cond ((memq com (list ?c (- ?c)))
2436 (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point)) 2600 (viper-separator-skipback-special 'twice viper-com-point))
2437 ;; Yank words including the whitespace, but not newline 2601 ;; Yank words including the whitespace, but not newline
2438 ((memq com (list ?y (- ?y))) 2602 ((memq com (list ?y (- ?y)))
2439 (viper-fwd-skip "\n[ \t]*" "" viper-com-point)) 2603 (viper-separator-skipback-special nil viper-com-point))
2440 ((viper-dotable-command-p com) 2604 ((viper-dotable-command-p com)
2441 (viper-fwd-skip "\n[ \t]*" "" viper-com-point))) 2605 (viper-separator-skipback-special nil viper-com-point)))
2442 (viper-execute-com 'viper-forward-Word val com))))) 2606 (viper-execute-com 'viper-forward-Word val com)))))
2443 2607
2444 2608
2445 ;; this is a bit different from Vi, but Vi's end of word 2609 ;; this is a bit different from Vi, but Vi's end of word
2446 ;; makes no sense whatsoever 2610 ;; makes no sense whatsoever
2483 (viper-leave-region-active) 2647 (viper-leave-region-active)
2484 (let ((val (viper-p-val arg)) 2648 (let ((val (viper-p-val arg))
2485 (com (viper-getcom arg))) 2649 (com (viper-getcom arg)))
2486 (if com (viper-move-marker-locally 'viper-com-point (point))) 2650 (if com (viper-move-marker-locally 'viper-com-point (point)))
2487 (viper-loop val 2651 (viper-loop val
2488 (progn
2489 (viper-end-of-word-kernel) 2652 (viper-end-of-word-kernel)
2490 (viper-skip-nonseparators 'forward) 2653 (viper-skip-nonseparators 'forward)
2491 (backward-char))) 2654 (backward-char))
2492 (if com 2655 (if com
2493 (progn 2656 (progn
2494 (forward-char) 2657 (forward-char)
2495 (viper-execute-com 'viper-end-of-Word val com))))) 2658 (viper-execute-com 'viper-end-of-Word val com)))))
2496 2659
2497 (defun viper-backward-word-kernel (val) 2660 (defun viper-backward-word-kernel (val)
2498 (while (> val 0) 2661 (while (> val 0)
2499 (backward-char) 2662 (viper-backward-char-carefully)
2500 (cond ((viper-looking-at-alpha) 2663 (cond ((viper-looking-at-alpha)
2501 (viper-skip-alpha-backward "_")) 2664 (viper-skip-alpha-backward "_"))
2502 ((viper-looking-at-separator) 2665 ((viper-looking-at-separator)
2503 (forward-char) 2666 (forward-char)
2504 (viper-skip-separators nil) 2667 (viper-skip-separators nil)
2505 (backward-char) 2668 (viper-backward-char-carefully)
2506 (cond ((viper-looking-at-alpha) 2669 (cond ((viper-looking-at-alpha)
2507 (viper-skip-alpha-backward "_")) 2670 (viper-skip-alpha-backward "_"))
2508 ((not (viper-looking-at-alphasep)) 2671 ((not (viper-looking-at-alphasep))
2509 (viper-skip-nonalphasep-backward)) 2672 (viper-skip-nonalphasep-backward))
2673 ((bobp)) ; could still be at separator, but at beg of buffer
2510 (t (forward-char)))) 2674 (t (forward-char))))
2511 ((not (viper-looking-at-alphasep)) 2675 ((not (viper-looking-at-alphasep))
2512 (viper-skip-nonalphasep-backward))) 2676 (viper-skip-nonalphasep-backward)))
2513 (setq val (1- val)))) 2677 (setq val (1- val))))
2514 2678
2538 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) 2702 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
2539 (backward-char)) 2703 (backward-char))
2540 (viper-move-marker-locally 'viper-com-point (point)) 2704 (viper-move-marker-locally 'viper-com-point (point))
2541 (if i (forward-char)))) 2705 (if i (forward-char))))
2542 (viper-loop val 2706 (viper-loop val
2543 (progn 2707 (viper-skip-separators nil) ; nil means backward here
2544 (viper-skip-separators nil) 2708 (viper-skip-nonseparators 'backward))
2545 (viper-skip-nonseparators 'backward)))
2546 (if com (viper-execute-com 'viper-backward-Word val com)))) 2709 (if com (viper-execute-com 'viper-backward-Word val com))))
2547 2710
2548 2711
2549 2712
2550 ;; line commands 2713 ;; line commands
2591 (interactive "P") 2754 (interactive "P")
2592 (viper-leave-region-active) 2755 (viper-leave-region-active)
2593 (let ((val (viper-p-val arg)) 2756 (let ((val (viper-p-val arg))
2594 (com (viper-getcom arg)) 2757 (com (viper-getcom arg))
2595 line-len) 2758 line-len)
2596 (setq line-len (- (viper-line-pos 'end) (viper-line-pos 'start))) 2759 (setq line-len
2760 (viper-chars-in-region
2761 (viper-line-pos 'start) (viper-line-pos 'end)))
2597 (if com (viper-move-marker-locally 'viper-com-point (point))) 2762 (if com (viper-move-marker-locally 'viper-com-point (point)))
2598 (beginning-of-line) 2763 (beginning-of-line)
2599 (forward-char (1- (min line-len val))) 2764 (forward-char (1- (min line-len val)))
2600 (while (> (current-column) (1- val)) 2765 (while (> (current-column) (1- val))
2601 (backward-char 1)) 2766 (backward-char 1))
2731 (goto-char (point-max))) 2896 (goto-char (point-max)))
2732 (if (let ((case-fold-search nil)) 2897 (if (let ((case-fold-search nil))
2733 (search-forward (char-to-string char) nil 0 arg)) 2898 (search-forward (char-to-string char) nil 0 arg))
2734 (setq point (point)) 2899 (setq point (point))
2735 (error "Command `%s': `%c' not found" cmd char)))) 2900 (error "Command `%s': `%c' not found" cmd char))))
2736 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) 2901 (goto-char point)
2902 (if (> arg 0)
2903 (backward-char (if offset 2 1))
2904 (forward-char (if offset 1 0)))))
2737 2905
2738 (defun viper-find-char-forward (arg) 2906 (defun viper-find-char-forward (arg)
2739 "Find char on the line. 2907 "Find char on the line.
2740 If called interactively read the char to find from the terminal, and if 2908 If called interactively read the char to find from the terminal, and if
2741 called from viper-repeat, the char last used is used. This behaviour is 2909 called from viper-repeat, the char last used is used. This behaviour is
3544 "Buffer `%s' is modified, are you sure you want to kill it? " 3712 "Buffer `%s' is modified, are you sure you want to kill it? "
3545 buffer-name))) 3713 buffer-name)))
3546 (kill-buffer buffer) 3714 (kill-buffer buffer)
3547 (error "Buffer not killed")))) 3715 (error "Buffer not killed"))))
3548 3716
3549
3550 (defcustom viper-smart-suffix-list
3551 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
3552 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
3553 This is useful when you the current directory contains files with the same
3554 prefix and many different suffixes. Usually, only one of the suffixes
3555 represents an editable file. However, file completion will stop at the `.'
3556 The smart suffix feature lets you hit RET in such a case, and Viper will
3557 select the appropriate suffix.
3558
3559 Suffixes are tried in the order given and the first suffix for which a
3560 corresponding file exists is selected. If no file exists for any of the
3561 suffixes, the user is asked to confirm.
3562
3563 To turn this feature off, set this variable to nil."
3564 :type '(set string)
3565 :group 'viper)
3566
3567 ;; Try to add suffix to files ending with a `.'
3568 ;; Useful when the user hits RET on a non-completed file name.
3569 (defun viper-file-add-suffix ()
3570 (let ((count 0)
3571 (len (length viper-smart-suffix-list))
3572 (file (buffer-string))
3573 found key cmd suff)
3574 (goto-char (point-max))
3575 (if (and viper-smart-suffix-list (string-match "\\.$" file))
3576 (progn
3577 (while (and (not found) (< count len))
3578 (setq suff (nth count viper-smart-suffix-list)
3579 count (1+ count))
3580 (if (file-exists-p
3581 (format "%s%s" (substitute-in-file-name file) suff))
3582 (progn
3583 (setq found t)
3584 (insert suff))))
3585
3586 (if found
3587 ()
3588 (viper-tmp-insert-at-eob " [Please complete file name]")
3589 (unwind-protect
3590 (while (not (memq cmd
3591 '(exit-minibuffer viper-exit-minibuffer)))
3592 (setq cmd
3593 (key-binding (setq key (read-key-sequence nil))))
3594 (cond ((eq cmd 'self-insert-command)
3595 (if viper-xemacs-p
3596 (insert (events-to-keys key))
3597 (insert key)))
3598 ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
3599 nil)
3600 (t (command-execute cmd)))
3601 )))
3602 ))))
3603
3604
3605 3717
3606 3718
3607 ;; yank and pop 3719 ;; yank and pop
3608 3720
3609 (defsubst viper-yank (text) 3721 (defsubst viper-yank (text)
3694 (copy-region-as-kill beg end) 3806 (copy-region-as-kill beg end)
3695 (error (copy-region-as-kill beg beg)))) 3807 (error (copy-region-as-kill beg beg))))
3696 3808
3697 3809
3698 (defun viper-delete-char (arg) 3810 (defun viper-delete-char (arg)
3699 "Delete character." 3811 "Delete next character."
3700 (interactive "P") 3812 (interactive "P")
3701 (let ((val (viper-p-val arg))) 3813 (let ((val (viper-p-val arg))
3814 end-del-pos)
3702 (viper-set-destructive-command 3815 (viper-set-destructive-command
3703 (list 'viper-delete-char val nil nil nil nil)) 3816 (list 'viper-delete-char val nil nil nil nil))
3704 (if (> val 1) 3817 (if (and viper-ex-style-editing
3705 (save-excursion 3818 (> val (viper-chars-in-region (point) (viper-line-pos 'end))))
3706 (let ((here (point))) 3819 (setq val (viper-chars-in-region (point) (viper-line-pos 'end))))
3707 (end-of-line)
3708 (if (> val (- (point) here))
3709 (setq val (- (point) here))))))
3710 (if (and (eq val 0) (not viper-ex-style-motion)) (setq val 1))
3711 (if (and viper-ex-style-motion (eolp)) 3820 (if (and viper-ex-style-motion (eolp))
3712 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch 3821 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
3822 (save-excursion
3823 (viper-forward-char-carefully val)
3824 (setq end-del-pos (point)))
3713 (if viper-use-register 3825 (if viper-use-register
3714 (progn 3826 (progn
3715 (cond ((viper-valid-register viper-use-register '((Letter))) 3827 (cond ((viper-valid-register viper-use-register '((Letter)))
3716 (viper-append-to-register 3828 (viper-append-to-register
3717 (downcase viper-use-register) (point) (- (point) val))) 3829 (downcase viper-use-register) (point) end-del-pos))
3718 ((viper-valid-register viper-use-register) 3830 ((viper-valid-register viper-use-register)
3719 (copy-to-register 3831 (copy-to-register
3720 viper-use-register (point) (- (point) val) nil)) 3832 viper-use-register (point) end-del-pos nil))
3721 (t (error viper-InvalidRegister viper-use-register))) 3833 (t (error viper-InvalidRegister viper-use-register)))
3722 (setq viper-use-register nil))) 3834 (setq viper-use-register nil)))
3835
3836 (delete-char val t)
3723 (if viper-ex-style-motion 3837 (if viper-ex-style-motion
3724 (progn 3838 (if (and (eolp) (not (bolp))) (backward-char 1)))
3725 (delete-char val t) 3839 ))
3726 (if (and (eolp) (not (bolp))) (backward-char 1)))
3727 (if (eolp)
3728 (delete-backward-char val t)
3729 (delete-char val t)))))
3730 3840
3731 (defun viper-delete-backward-char (arg) 3841 (defun viper-delete-backward-char (arg)
3732 "Delete previous character. On reaching beginning of line, stop and beep." 3842 "Delete previous character. On reaching beginning of line, stop and beep."
3733 (interactive "P") 3843 (interactive "P")
3734 (let ((val (viper-p-val arg))) 3844 (let ((val (viper-p-val arg))
3845 end-del-pos)
3735 (viper-set-destructive-command 3846 (viper-set-destructive-command
3736 (list 'viper-delete-backward-char val nil nil nil nil)) 3847 (list 'viper-delete-backward-char val nil nil nil nil))
3737 (if (> val 1) 3848 (if (and
3738 (save-excursion 3849 viper-ex-style-editing
3739 (let ((here (point))) 3850 (> val (viper-chars-in-region (viper-line-pos 'start) (point))))
3740 (beginning-of-line) 3851 (setq val (viper-chars-in-region (viper-line-pos 'start) (point))))
3741 (if (> val (- here (point))) 3852 (save-excursion
3742 (setq val (- here (point))))))) 3853 (viper-backward-char-carefully val)
3854 (setq end-del-pos (point)))
3743 (if viper-use-register 3855 (if viper-use-register
3744 (progn 3856 (progn
3745 (cond ((viper-valid-register viper-use-register '(Letter)) 3857 (cond ((viper-valid-register viper-use-register '(Letter))
3746 (viper-append-to-register 3858 (viper-append-to-register
3747 (downcase viper-use-register) (point) (+ (point) val))) 3859 (downcase viper-use-register) end-del-pos (point)))
3748 ((viper-valid-register viper-use-register) 3860 ((viper-valid-register viper-use-register)
3749 (copy-to-register 3861 (copy-to-register
3750 viper-use-register (point) (+ (point) val) nil)) 3862 viper-use-register end-del-pos (point) nil))
3751 (t (error viper-InvalidRegister viper-use-register))) 3863 (t (error viper-InvalidRegister viper-use-register)))
3752 (setq viper-use-register nil))) 3864 (setq viper-use-register nil)))
3753 (if (bolp) (ding) 3865 (if (and (bolp) viper-ex-style-editing)
3754 (delete-backward-char val t)))) 3866 (ding))
3867 (delete-backward-char val t)))
3755 3868
3756 (defun viper-del-backward-char-in-insert () 3869 (defun viper-del-backward-char-in-insert ()
3757 "Delete 1 char backwards while in insert mode." 3870 "Delete 1 char backwards while in insert mode."
3758 (interactive) 3871 (interactive)
3759 (if (and viper-ex-style-editing-in-insert (bolp)) 3872 (if (and viper-ex-style-editing (bolp))
3760 (beep 1) 3873 (beep 1)
3761 (delete-backward-char 1 t))) 3874 (delete-backward-char 1 t)))
3762 3875
3763 (defun viper-del-backward-char-in-replace () 3876 (defun viper-del-backward-char-in-replace ()
3764 "Delete one character in replace mode. 3877 "Delete one character in replace mode.
3765 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes 3878 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes
3766 charecters. If it is nil, then the cursor just moves backwards, similarly 3879 charecters. If it is nil, then the cursor just moves backwards, similarly
3767 to Vi. The variable `viper-ex-style-editing-in-insert', if t, doesn't let the 3880 to Vi. The variable `viper-ex-style-editing', if t, doesn't let the
3768 cursor move past the beginning of line." 3881 cursor move past the beginning of line."
3769 (interactive) 3882 (interactive)
3770 (cond (viper-delete-backwards-in-replace 3883 (cond (viper-delete-backwards-in-replace
3771 (cond ((not (bolp)) 3884 (cond ((not (bolp))
3772 (delete-backward-char 1 t)) 3885 (delete-backward-char 1 t))
3773 (viper-ex-style-editing-in-insert 3886 (viper-ex-style-editing
3774 (beep 1)) 3887 (beep 1))
3775 ((bobp) 3888 ((bobp)
3776 (beep 1)) 3889 (beep 1))
3777 (t 3890 (t
3778 (delete-backward-char 1 t)))) 3891 (delete-backward-char 1 t))))
3779 (viper-ex-style-editing-in-insert 3892 (viper-ex-style-editing
3780 (if (bolp) 3893 (if (bolp)
3781 (beep 1) 3894 (beep 1)
3782 (backward-char 1))) 3895 (backward-char 1)))
3783 (t 3896 (t
3784 (backward-char 1)))) 3897 (backward-char 1))))
3792 (interactive "*P") 3905 (interactive "*P")
3793 (let ((val (viper-P-val arg))) 3906 (let ((val (viper-P-val arg)))
3794 (viper-set-destructive-command 3907 (viper-set-destructive-command
3795 (list 'viper-join-lines val nil nil nil nil)) 3908 (list 'viper-join-lines val nil nil nil nil))
3796 (viper-loop (if (null val) 1 (1- val)) 3909 (viper-loop (if (null val) 1 (1- val))
3797 (progn
3798 (end-of-line) 3910 (end-of-line)
3799 (if (not (eobp)) 3911 (if (not (eobp))
3800 (progn 3912 (progn
3801 (forward-line 1) 3913 (forward-line 1)
3802 (delete-region (point) (1- (point))) 3914 (delete-region (point) (1- (point)))
3804 ;; fixup-whitespace sometimes does not leave space 3916 ;; fixup-whitespace sometimes does not leave space
3805 ;; between objects, so we insert it as in Vi 3917 ;; between objects, so we insert it as in Vi
3806 (or (looking-at " ") 3918 (or (looking-at " ")
3807 (insert " ") 3919 (insert " ")
3808 (backward-char 1)) 3920 (backward-char 1))
3809 )))))) 3921 )))))
3810 3922
3811 3923
3812 ;; Replace state 3924 ;; Replace state
3813 3925
3814 (defun viper-change (beg end) 3926 (defun viper-change (beg end)
4260 ;; & dont-change-unless = t -- use it; else ask 4372 ;; & dont-change-unless = t -- use it; else ask
4261 (viper-ask-level dont-change-unless)) 4373 (viper-ask-level dont-change-unless))
4262 4374
4263 (setq viper-always t 4375 (setq viper-always t
4264 viper-ex-style-motion t 4376 viper-ex-style-motion t
4265 viper-ex-style-editing-in-insert t 4377 viper-ex-style-editing t
4266 viper-want-ctl-h-help nil) 4378 viper-want-ctl-h-help nil)
4267 4379
4268 (cond ((eq viper-expert-level 1) ; novice or beginner 4380 (cond ((eq viper-expert-level 1) ; novice or beginner
4269 (global-set-key ; in emacs-state 4381 (global-set-key ; in emacs-state
4270 viper-toggle-key 4382 viper-toggle-key
4287 4399
4288 (if (eq viper-expert-level 4) ; respect user's ex-style motion 4400 (if (eq viper-expert-level 4) ; respect user's ex-style motion
4289 ; and viper-no-multiple-ESC 4401 ; and viper-no-multiple-ESC
4290 (progn 4402 (progn
4291 (setq-default 4403 (setq-default
4292 viper-ex-style-editing-in-insert 4404 viper-ex-style-editing
4293 (viper-standard-value 'viper-ex-style-editing-in-insert) 4405 (viper-standard-value 'viper-ex-style-editing)
4294 viper-ex-style-motion 4406 viper-ex-style-motion
4295 (viper-standard-value 'viper-ex-style-motion)) 4407 (viper-standard-value 'viper-ex-style-motion))
4296 (setq viper-ex-style-motion 4408 (setq viper-ex-style-motion
4297 (viper-standard-value 'viper-ex-style-motion) 4409 (viper-standard-value 'viper-ex-style-motion)
4298 viper-ex-style-editing-in-insert 4410 viper-ex-style-editing
4299 (viper-standard-value 'viper-ex-style-editing-in-insert) 4411 (viper-standard-value 'viper-ex-style-editing)
4300 viper-re-search 4412 viper-re-search
4301 (viper-standard-value 'viper-re-search) 4413 (viper-standard-value 'viper-re-search)
4302 viper-no-multiple-ESC 4414 viper-no-multiple-ESC
4303 (viper-standard-value 'viper-no-multiple-ESC))))) 4415 (viper-standard-value 'viper-no-multiple-ESC)))))
4304 4416
4305 ;; A wizard!! 4417 ;; A wizard!!
4306 ;; Ideally, if 5 is selected, a buffer should pop up to let the 4418 ;; Ideally, if 5 is selected, a buffer should pop up to let the
4307 ;; user toggle the values of variables. 4419 ;; user toggle the values of variables.
4308 (t (setq-default viper-ex-style-editing-in-insert 4420 (t (setq-default viper-ex-style-editing
4309 (viper-standard-value 'viper-ex-style-editing-in-insert) 4421 (viper-standard-value 'viper-ex-style-editing)
4310 viper-ex-style-motion 4422 viper-ex-style-motion
4311 (viper-standard-value 'viper-ex-style-motion)) 4423 (viper-standard-value 'viper-ex-style-motion))
4312 (setq viper-want-ctl-h-help 4424 (setq viper-want-ctl-h-help
4313 (viper-standard-value 'viper-want-ctl-h-help) 4425 (viper-standard-value 'viper-want-ctl-h-help)
4314 viper-always 4426 viper-always
4315 (viper-standard-value 'viper-always) 4427 (viper-standard-value 'viper-always)
4316 viper-no-multiple-ESC 4428 viper-no-multiple-ESC
4317 (viper-standard-value 'viper-no-multiple-ESC) 4429 (viper-standard-value 'viper-no-multiple-ESC)
4318 viper-ex-style-motion 4430 viper-ex-style-motion
4319 (viper-standard-value 'viper-ex-style-motion) 4431 (viper-standard-value 'viper-ex-style-motion)
4320 viper-ex-style-editing-in-insert 4432 viper-ex-style-editing
4321 (viper-standard-value 'viper-ex-style-editing-in-insert) 4433 (viper-standard-value 'viper-ex-style-editing)
4322 viper-re-search 4434 viper-re-search
4323 (viper-standard-value 'viper-re-search) 4435 (viper-standard-value 'viper-re-search)
4324 viper-electric-mode 4436 viper-electric-mode
4325 (viper-standard-value 'viper-electric-mode) 4437 (viper-standard-value 'viper-electric-mode)
4326 viper-want-emacs-keys-in-vi 4438 viper-want-emacs-keys-in-vi
4364 so most Emacs commands can be used when Viper is in Vi state. 4476 so most Emacs commands can be used when Viper is in Vi state.
4365 Good progress---you are well on the way to level 3! 4477 Good progress---you are well on the way to level 3!
4366 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also 4478 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
4367 in Viper's insert state. 4479 in Viper's insert state.
4368 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC, 4480 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC,
4369 viper-ex-style-motion, viper-ex-style-editing-in-insert, and 4481 viper-ex-style-motion, viper-ex-style-editing, and
4370 viper-re-search variables. Adjust these settings to your taste. 4482 viper-re-search variables. Adjust these settings to your taste.
4371 5 -- WIZARD: Like 4, but user settings are also respected for viper-always, 4483 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
4372 viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi, 4484 viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
4373 and viper-want-emacs-keys-in-insert. Adjust these to your taste. 4485 and viper-want-emacs-keys-in-insert. Adjust these to your taste.
4374 4486
4485 'viper-emacs-local-user-minor-mode 4597 'viper-emacs-local-user-minor-mode
4486 'viper-emacs-kbd-minor-mode 4598 'viper-emacs-kbd-minor-mode
4487 'viper-emacs-global-user-minor-mode 4599 'viper-emacs-global-user-minor-mode
4488 'viper-emacs-state-modifier-minor-mode 4600 'viper-emacs-state-modifier-minor-mode
4489 'viper-automatic-iso-accents 4601 'viper-automatic-iso-accents
4602 'viper-special-input-method
4490 'viper-want-emacs-keys-in-insert 4603 'viper-want-emacs-keys-in-insert
4491 'viper-want-emacs-keys-in-vi 4604 'viper-want-emacs-keys-in-vi
4492 'viper-keep-point-on-undo 4605 'viper-keep-point-on-undo
4493 'viper-no-multiple-ESC 4606 'viper-no-multiple-ESC
4494 'viper-electric-mode 4607 'viper-electric-mode
4495 'viper-ESC-key 4608 'viper-ESC-key
4496 'viper-want-ctl-h-help 4609 'viper-want-ctl-h-help
4497 'viper-ex-style-editing-in-insert 4610 'viper-ex-style-editing
4498 'viper-delete-backwards-in-replace 4611 'viper-delete-backwards-in-replace
4499 'viper-vi-style-in-minibuffer 4612 'viper-vi-style-in-minibuffer
4500 'viper-vi-state-hook 4613 'viper-vi-state-hook
4501 'viper-insert-state-hook 4614 'viper-insert-state-hook
4502 'viper-replace-state-hook 4615 'viper-replace-state-hook