aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/emulation
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emulation')
-rw-r--r--lisp/emulation/viper-cmd.el81
-rw-r--r--lisp/emulation/viper-ex.el8
-rw-r--r--lisp/emulation/viper-init.el5
-rw-r--r--lisp/emulation/viper-util.el27
-rw-r--r--lisp/emulation/viper.el19
5 files changed, 84 insertions, 56 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index 0dce3b94ff0..af757a2a55c 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -46,6 +46,8 @@
46(defvar mark-even-if-inactive) 46(defvar mark-even-if-inactive)
47(defvar init-message) 47(defvar init-message)
48(defvar initial) 48(defvar initial)
49(defvar undo-beg-posn)
50(defvar undo-end-posn)
49 51
50;; loading happens only in non-interactive compilation 52;; loading happens only in non-interactive compilation
51;; in order to spare non-viperized emacs from being viperized 53;; in order to spare non-viperized emacs from being viperized
@@ -196,7 +198,7 @@
196 (viper-save-cursor-color 'before-insert-mode)) 198 (viper-save-cursor-color 'before-insert-mode))
197 ;; set insert mode cursor color 199 ;; set insert mode cursor color
198 (viper-change-cursor-color viper-insert-state-cursor-color))) 200 (viper-change-cursor-color viper-insert-state-cursor-color)))
199 (if (eq viper-current-state 'emacs-state) 201 (if (and viper-emacs-state-cursor-color (eq viper-current-state 'emacs-state))
200 (let ((has-saved-cursor-color-in-emacs-mode 202 (let ((has-saved-cursor-color-in-emacs-mode
201 (stringp (viper-get-saved-cursor-color-in-emacs-mode)))) 203 (stringp (viper-get-saved-cursor-color-in-emacs-mode))))
202 (or has-saved-cursor-color-in-emacs-mode 204 (or has-saved-cursor-color-in-emacs-mode
@@ -722,12 +724,13 @@
722 (viper-set-replace-overlay (point-min) (point-min))) 724 (viper-set-replace-overlay (point-min) (point-min)))
723 (viper-hide-replace-overlay) 725 (viper-hide-replace-overlay)
724 726
725 (let ((has-saved-cursor-color-in-emacs-mode 727 (if viper-emacs-state-cursor-color
726 (stringp (viper-get-saved-cursor-color-in-emacs-mode)))) 728 (let ((has-saved-cursor-color-in-emacs-mode
727 (or has-saved-cursor-color-in-emacs-mode 729 (stringp (viper-get-saved-cursor-color-in-emacs-mode))))
728 (string= (viper-get-cursor-color) viper-emacs-state-cursor-color) 730 (or has-saved-cursor-color-in-emacs-mode
729 (viper-save-cursor-color 'before-emacs-mode)) 731 (string= (viper-get-cursor-color) viper-emacs-state-cursor-color)
730 (viper-change-cursor-color viper-emacs-state-cursor-color)) 732 (viper-save-cursor-color 'before-emacs-mode))
733 (viper-change-cursor-color viper-emacs-state-cursor-color)))
731 734
732 (viper-change-state 'emacs-state) 735 (viper-change-state 'emacs-state)
733 736
@@ -1030,10 +1033,13 @@ as a Meta key and any number of multiple escapes is allowed."
1030 (inhibit-quit t)) 1033 (inhibit-quit t))
1031 (if (viper-ESC-event-p event) 1034 (if (viper-ESC-event-p event)
1032 (progn 1035 (progn
1033 ;; Emacs 22.50.8 introduced a bug, which makes even a single ESC into 1036 ;; Some versions of Emacs (eg., 22.50.8 have a bug, which makes even
1034 ;; a fast keyseq. To guard against this, we added a check if there 1037 ;; a single ESC into ;; a fast keyseq. To guard against this, we
1035 ;; are other events as well 1038 ;; added a check if there are other events as well. Keep the next
1036 (if (and (viper-fast-keysequence-p) unread-command-events) 1039 ;; line for the next time the bug reappears, so that will remember to
1040 ;; report it.
1041 ;;(if (and (viper-fast-keysequence-p) unread-command-events)
1042 (if (viper-fast-keysequence-p) ;; for Emacsen without the above bug
1037 (progn 1043 (progn
1038 (let (minor-mode-map-alist emulation-mode-map-alists) 1044 (let (minor-mode-map-alist emulation-mode-map-alists)
1039 (viper-set-unread-command-events event) 1045 (viper-set-unread-command-events event)
@@ -1744,12 +1750,14 @@ invokes the command before that, etc."
1744 1750
1745;; Hook used in viper-undo 1751;; Hook used in viper-undo
1746(defun viper-after-change-undo-hook (beg end len) 1752(defun viper-after-change-undo-hook (beg end len)
1747 (setq undo-beg-posn beg 1753 (if undo-in-progress
1748 undo-end-posn (or end beg)) 1754 (setq undo-beg-posn beg
1749 ;; some other hooks may be changing various text properties in 1755 undo-end-posn (or end beg))
1750 ;; the buffer in response to 'undo'; so remove this hook to avoid 1756 ;; some other hooks may be changing various text properties in
1751 ;; its repeated invocation 1757 ;; the buffer in response to 'undo'; so remove this hook to avoid
1752 (remove-hook 'viper-undo-functions 'viper-after-change-undo-hook 'local)) 1758 ;; its repeated invocation
1759 (remove-hook 'viper-undo-functions 'viper-after-change-undo-hook 'local)
1760 ))
1753 1761
1754(defun viper-undo () 1762(defun viper-undo ()
1755 "Undo previous change." 1763 "Undo previous change."
@@ -1764,25 +1772,29 @@ invokes the command before that, etc."
1764 1772
1765 (undo-start) 1773 (undo-start)
1766 (undo-more 2) 1774 (undo-more 2)
1767 (setq undo-beg-posn (or undo-beg-posn before-undo-pt) 1775 ;;(setq undo-beg-posn (or undo-beg-posn (point))
1768 undo-end-posn (or undo-end-posn undo-beg-posn)) 1776 ;; undo-end-posn (or undo-end-posn (point)))
1777 ;;(setq undo-beg-posn (or undo-beg-posn before-undo-pt)
1778 ;; undo-end-posn (or undo-end-posn undo-beg-posn))
1769 1779
1770 (goto-char undo-beg-posn) 1780 (if (and undo-beg-posn undo-end-posn)
1771 (sit-for 0)
1772 (if (and viper-keep-point-on-undo
1773 (pos-visible-in-window-p before-undo-pt))
1774 (progn 1781 (progn
1775 (push-mark (point-marker) t) 1782 (goto-char undo-beg-posn)
1776 (viper-sit-for-short 300) 1783 (sit-for 0)
1777 (goto-char undo-end-posn) 1784 (if (and viper-keep-point-on-undo
1778 (viper-sit-for-short 300) 1785 (pos-visible-in-window-p before-undo-pt))
1779 (if (and (> (viper-chars-in-region undo-beg-posn before-undo-pt) 1) 1786 (progn
1780 (> (viper-chars-in-region undo-end-posn before-undo-pt) 1)) 1787 (push-mark (point-marker) t)
1781 (goto-char before-undo-pt) 1788 (viper-sit-for-short 300)
1782 (goto-char undo-beg-posn))) 1789 (goto-char undo-end-posn)
1783 (push-mark before-undo-pt t)) 1790 (viper-sit-for-short 300)
1791 (if (pos-visible-in-window-p undo-beg-posn)
1792 (goto-char before-undo-pt)
1793 (goto-char undo-beg-posn)))
1794 (push-mark before-undo-pt t))
1795 ))
1796
1784 (if (and (eolp) (not (bolp))) (backward-char 1)) 1797 (if (and (eolp) (not (bolp))) (backward-char 1))
1785 ;;(if (not modified) (set-buffer-modified-p t))
1786 ) 1798 )
1787 (setq this-command 'viper-undo)) 1799 (setq this-command 'viper-undo))
1788 1800
@@ -3952,7 +3964,8 @@ Null string will repeat previous search."
3952 (let ((val (viper-p-val arg)) 3964 (let ((val (viper-p-val arg))
3953 (com (viper-getcom arg)) 3965 (com (viper-getcom arg))
3954 debug-on-error) 3966 debug-on-error)
3955 (if (null viper-s-string) (error viper-NoPrevSearch)) 3967 (if (or (null viper-s-string) (string= viper-s-string ""))
3968 (error viper-NoPrevSearch))
3956 (viper-search viper-s-string viper-s-forward arg) 3969 (viper-search viper-s-string viper-s-forward arg)
3957 (if com 3970 (if com
3958 (progn 3971 (progn
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index e2824246fad..f9f08034582 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -208,12 +208,12 @@
208 208
209;; If this is a one-letter magic command, splice in args. 209;; If this is a one-letter magic command, splice in args.
210(defun ex-splice-args-in-1-letr-cmd (key list) 210(defun ex-splice-args-in-1-letr-cmd (key list)
211 (let ((onelet (ex-cmd-is-one-letter (assoc (substring key 0 1) list)))) 211 (let ((oneletter (ex-cmd-is-one-letter (assoc (substring key 0 1) list))))
212 (if onelet 212 (if oneletter
213 (list key 213 (list key
214 (append (cadr onelet) 214 (append (cadr oneletter)
215 (if (< 1 (length key)) (list (substring key 1)))) 215 (if (< 1 (length key)) (list (substring key 1))))
216 (caddr onelet))) 216 (car (cdr (cdr oneletter))) ))
217 )) 217 ))
218 218
219 219
diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el
index 80938b0282a..465f6e5cfb8 100644
--- a/lisp/emulation/viper-init.el
+++ b/lisp/emulation/viper-init.el
@@ -434,7 +434,10 @@ delete the text being replaced, as in standard Vi."
434(if (fboundp 'make-variable-frame-local) 434(if (fboundp 'make-variable-frame-local)
435 (make-variable-frame-local 'viper-insert-state-cursor-color)) 435 (make-variable-frame-local 'viper-insert-state-cursor-color))
436 436
437(defcustom viper-emacs-state-cursor-color "Magenta" 437;; viper-emacs-state-cursor-color doesn't work well. Causes cursor colors to be
438;; confused in some cases. So, this var is nulled for now.
439;; (defcustom viper-emacs-state-cursor-color "Magenta"
440(defcustom viper-emacs-state-cursor-color nil
438 "Cursor color when Viper is in emacs state." 441 "Cursor color when Viper is in emacs state."
439 :type 'string 442 :type 'string
440 :group 'viper) 443 :group 'viper)
diff --git a/lisp/emulation/viper-util.el b/lisp/emulation/viper-util.el
index 252088a476d..fe179be9cd1 100644
--- a/lisp/emulation/viper-util.el
+++ b/lisp/emulation/viper-util.el
@@ -137,10 +137,10 @@
137 (x-display-color-p) ; emacs 137 (x-display-color-p) ; emacs
138 )) 138 ))
139 139
140(defsubst viper-get-cursor-color () 140(defun viper-get-cursor-color (&optional frame)
141 (viper-cond-compile-for-xemacs-or-emacs 141 (viper-cond-compile-for-xemacs-or-emacs
142 (color-instance-name 142 (color-instance-name
143 (frame-property (selected-frame) 'cursor-color)) ; xemacs 143 (frame-property (or frame (selected-frame)) 'cursor-color)) ; xemacs
144 (cdr (assoc 'cursor-color (frame-parameters))) ; emacs 144 (cdr (assoc 'cursor-color (frame-parameters))) ; emacs
145 )) 145 ))
146 146
@@ -152,18 +152,31 @@
152 152
153 153
154;; cursor colors 154;; cursor colors
155(defun viper-change-cursor-color (new-color) 155(defun viper-change-cursor-color (new-color &optional frame)
156 (if (and (viper-window-display-p) (viper-color-display-p) 156 (if (and (viper-window-display-p) (viper-color-display-p)
157 (stringp new-color) (viper-color-defined-p new-color) 157 (stringp new-color) (viper-color-defined-p new-color)
158 (not (string= new-color (viper-get-cursor-color)))) 158 (not (string= new-color (viper-get-cursor-color))))
159 (viper-cond-compile-for-xemacs-or-emacs 159 (viper-cond-compile-for-xemacs-or-emacs
160 (set-frame-property 160 (set-frame-property
161 (selected-frame) 'cursor-color (make-color-instance new-color)) 161 (or frame (selected-frame))
162 'cursor-color (make-color-instance new-color))
162 (modify-frame-parameters 163 (modify-frame-parameters
163 (selected-frame) (list (cons 'cursor-color new-color))) 164 (or frame (selected-frame))
165 (list (cons 'cursor-color new-color)))
164 ) 166 )
165 )) 167 ))
166 168
169(defun viper-set-cursor-color-according-to-state (&optional frame)
170 (cond ((eq viper-current-state 'replace-state)
171 (viper-change-cursor-color viper-replace-state-cursor-color frame))
172 ((and (eq viper-current-state 'emacs-state)
173 viper-emacs-state-cursor-color)
174 (viper-change-cursor-color viper-emacs-state-cursor-color frame))
175 ((eq viper-current-state 'insert-state)
176 (viper-change-cursor-color viper-insert-state-cursor-color frame))
177 (t
178 (viper-change-cursor-color viper-vi-state-cursor-color frame))))
179
167;; By default, saves current frame cursor color in the 180;; By default, saves current frame cursor color in the
168;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay 181;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay
169(defun viper-save-cursor-color (before-which-mode) 182(defun viper-save-cursor-color (before-which-mode)
@@ -191,7 +204,7 @@
191 (if viper-emacs-p 'frame-parameter 'frame-property) 204 (if viper-emacs-p 'frame-parameter 'frame-property)
192 (selected-frame) 205 (selected-frame)
193 'viper-saved-cursor-color-in-replace-mode) 206 'viper-saved-cursor-color-in-replace-mode)
194 (if (eq viper-current-state 'emacs-mode) 207 (if (and (eq viper-current-state 'emacs-mode) viper-emacs-state-cursor-color)
195 viper-emacs-state-cursor-color 208 viper-emacs-state-cursor-color
196 viper-vi-state-cursor-color))) 209 viper-vi-state-cursor-color)))
197 210
@@ -201,7 +214,7 @@
201 (if viper-emacs-p 'frame-parameter 'frame-property) 214 (if viper-emacs-p 'frame-parameter 'frame-property)
202 (selected-frame) 215 (selected-frame)
203 'viper-saved-cursor-color-in-insert-mode) 216 'viper-saved-cursor-color-in-insert-mode)
204 (if (eq viper-current-state 'emacs-mode) 217 (if (and (eq viper-current-state 'emacs-mode) viper-emacs-state-cursor-color)
205 viper-emacs-state-cursor-color 218 viper-emacs-state-cursor-color
206 viper-vi-state-cursor-color))) 219 viper-vi-state-cursor-color)))
207 220
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index 8f858526da3..0ba7bdd041a 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -534,10 +534,6 @@ If Viper is enabled, turn it off. Otherwise, turn it on."
534(defun viper-mode () 534(defun viper-mode ()
535 "Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Viper'." 535 "Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Viper'."
536 (interactive) 536 (interactive)
537 (if (null viper-vi-state-cursor-color)
538 (modify-frame-parameters
539 (selected-frame)
540 (list (cons 'viper-vi-state-cursor-color (viper-get-cursor-color)))))
541 (if (not noninteractive) 537 (if (not noninteractive)
542 (progn 538 (progn
543 ;; if the user requested viper-mode explicitly 539 ;; if the user requested viper-mode explicitly
@@ -618,7 +614,8 @@ This startup message appears whenever you load Viper, unless you type `y' now."
618 614
619 (or (memq major-mode viper-emacs-state-mode-list) ; don't switch to Vi 615 (or (memq major-mode viper-emacs-state-mode-list) ; don't switch to Vi
620 (memq major-mode viper-insert-state-mode-list) ; don't switch 616 (memq major-mode viper-insert-state-mode-list) ; don't switch
621 (viper-change-state-to-vi))))) 617 (viper-change-state-to-vi))
618 )))
622 619
623 620
624;; Apply a little heuristic to invoke vi state on major-modes 621;; Apply a little heuristic to invoke vi state on major-modes
@@ -862,8 +859,11 @@ It also can't undo some Viper settings."
862 ;; info about the display and windows until emacs initialization is complete 859 ;; info about the display and windows until emacs initialization is complete
863 ;; So do it via the window-setup-hook 860 ;; So do it via the window-setup-hook
864 (add-hook 'window-setup-hook 861 (add-hook 'window-setup-hook
865 '(lambda () 862 '(lambda ()
866 (setq viper-vi-state-cursor-color (viper-get-cursor-color)))) 863 (modify-frame-parameters
864 (selected-frame)
865 (list (cons 'viper-vi-state-cursor-color
866 (viper-get-cursor-color))))))
867 867
868 ;; Tell vc-diff to put *vc* in Vi mode 868 ;; Tell vc-diff to put *vc* in Vi mode
869 (if (featurep 'vc) 869 (if (featurep 'vc)
@@ -903,7 +903,6 @@ It also can't undo some Viper settings."
903 903
904 (defadvice set-cursor-color (after viper-set-cursor-color-ad activate) 904 (defadvice set-cursor-color (after viper-set-cursor-color-ad activate)
905 "Change cursor color in VI state." 905 "Change cursor color in VI state."
906 ;;(setq viper-vi-state-cursor-color (ad-get-arg 0))
907 (modify-frame-parameters 906 (modify-frame-parameters
908 (selected-frame) 907 (selected-frame)
909 (list (cons 'viper-vi-state-cursor-color (ad-get-arg 0)))) 908 (list (cons 'viper-vi-state-cursor-color (ad-get-arg 0))))
@@ -1008,8 +1007,8 @@ It also can't undo some Viper settings."
1008;; these are primarily advices and Vi-ish variable settings 1007;; these are primarily advices and Vi-ish variable settings
1009(defun viper-non-hook-settings () 1008(defun viper-non-hook-settings ()
1010 1009
1011 ;; Viper changes the default mode-line-buffer-identification 1010 ;;;; Viper changes the default mode-line-buffer-identification
1012 (setq-default mode-line-buffer-identification '(" %b")) 1011 ;;(setq-default mode-line-buffer-identification '(" %b"))
1013 1012
1014 ;; setup emacs-supported vi-style feel 1013 ;; setup emacs-supported vi-style feel
1015 (setq next-line-add-newlines nil 1014 (setq next-line-add-newlines nil