* net/ldap.el (ldap-search-internal): Tweak URL regexp.
[bpt/emacs.git] / lisp / emulation / viper-cmd.el
index 68116cd..18fa94d 100644 (file)
@@ -7,10 +7,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -41,7 +39,6 @@
 (defvar iso-accents-mode)
 (defvar quail-mode)
 (defvar quail-current-str)
-(defvar zmacs-region-stays)
 (defvar mark-even-if-inactive)
 (defvar init-message)
 (defvar initial)
        (viper-set-replace-overlay (point-min) (point-min))
        (viper-hide-replace-overlay)))
   (if (eq viper-current-state 'insert-state)
-      (let ((has-saved-cursor-color-in-insert-mode
-            (stringp (viper-get-saved-cursor-color-in-insert-mode))))
-       (or has-saved-cursor-color-in-insert-mode
-           (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
+      (let ((icolor (viper-frame-value viper-insert-state-cursor-color)))
+       (or (stringp (viper-get-saved-cursor-color-in-insert-mode))
+           (string= (viper-get-cursor-color) icolor)
            ;; save current color, if not already saved
            (viper-save-cursor-color 'before-insert-mode))
        ;; set insert mode cursor color
-       (viper-change-cursor-color viper-insert-state-cursor-color)))
-  (if (and viper-emacs-state-cursor-color (eq viper-current-state 'emacs-state))
-      (let ((has-saved-cursor-color-in-emacs-mode
-            (stringp (viper-get-saved-cursor-color-in-emacs-mode))))
-       (or has-saved-cursor-color-in-emacs-mode
-           (string= (viper-get-cursor-color) viper-emacs-state-cursor-color)
-           ;; save current color, if not already saved
-           (viper-save-cursor-color 'before-emacs-mode))
-       ;; set emacs mode cursor color
-       (viper-change-cursor-color viper-emacs-state-cursor-color)))
+       (viper-change-cursor-color icolor)))
+  (let ((ecolor (viper-frame-value viper-emacs-state-cursor-color)))
+    (when (and ecolor (eq viper-current-state 'emacs-state))
+      (or (stringp (viper-get-saved-cursor-color-in-emacs-mode))
+         (string= (viper-get-cursor-color) ecolor)
+         ;; save current color, if not already saved
+         (viper-save-cursor-color 'before-emacs-mode))
+      ;; set emacs mode cursor color
+      (viper-change-cursor-color ecolor)))
 
   (if (and (memq this-command '(dabbrev-expand hippie-expand))
           (integerp viper-pre-command-point)
           (markerp viper-insert-point)
           (marker-position viper-insert-point)
           (> viper-insert-point viper-pre-command-point))
-      (viper-move-marker-locally viper-insert-point viper-pre-command-point))
-  )
+      (viper-move-marker-locally viper-insert-point viper-pre-command-point)))
 
 (defsubst viper-preserve-cursor-color ()
   (or (memq this-command '(self-insert-command
   ;; will remain red.  Restoring the default, below, prevents this.
   (if (and (<= (viper-replace-start) (point))
           (<=  (point) (viper-replace-end)))
-      (viper-change-cursor-color viper-replace-overlay-cursor-color)
-    (viper-restore-cursor-color 'after-replace-mode)
-    ))
+      (viper-change-cursor-color
+       (viper-frame-value viper-replace-overlay-cursor-color))
+    (viper-restore-cursor-color 'after-replace-mode)))
 
 ;; to speed up, don't change cursor color before self-insert
 ;; and common move commands
        (if (= viper-last-posn-in-replace-region (viper-replace-end))
            (viper-finish-change)))
 
-      (if (viper-pos-within-region
-          (point) (viper-replace-start) replace-boundary)
-         (progn
-           ;; the state may have changed in viper-finish-change above
-           (if (eq viper-current-state 'replace-state)
-               (viper-change-cursor-color viper-replace-overlay-cursor-color))
-           (setq viper-last-posn-in-replace-region (point-marker))))
-      ))
+      (when (viper-pos-within-region
+            (point) (viper-replace-start) replace-boundary)
+       ;; the state may have changed in viper-finish-change above
+       (if (eq viper-current-state 'replace-state)
+           (viper-change-cursor-color
+            (viper-frame-value viper-replace-overlay-cursor-color)))
+       (setq viper-last-posn-in-replace-region (point-marker)))))
    ;; terminate replace mode if changed Viper states.
    (t (viper-finish-change))))
 
   ;; desirable that viper-pre-command-sentinel is the last hook and
   ;; viper-post-command-sentinel is the first hook.
 
-  (viper-cond-compile-for-xemacs-or-emacs
-   ;; xemacs
-   (progn
-     (make-local-hook 'viper-after-change-functions)
-     (make-local-hook 'viper-before-change-functions)
-     (make-local-hook 'viper-post-command-hooks)
-     (make-local-hook 'viper-pre-command-hooks))
-   nil ; emacs
-   )
+  (when (featurep 'xemacs)
+    (make-local-hook 'viper-after-change-functions)
+    (make-local-hook 'viper-before-change-functions)
+    (make-local-hook 'viper-post-command-hooks)
+    (make-local-hook 'viper-pre-command-hooks))
 
   (remove-hook 'post-command-hook 'viper-post-command-sentinel)
   (add-hook 'post-command-hook 'viper-post-command-sentinel)
       (viper-set-replace-overlay (point-min) (point-min)))
   (viper-hide-replace-overlay)
 
-  (let ((has-saved-cursor-color-in-insert-mode
-        (stringp (viper-get-saved-cursor-color-in-insert-mode))))
-    (or has-saved-cursor-color-in-insert-mode
-       (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
+  (let ((icolor (viper-frame-value viper-insert-state-cursor-color)))
+    (or (stringp (viper-get-saved-cursor-color-in-insert-mode))
+       (string= (viper-get-cursor-color) icolor)
        (viper-save-cursor-color 'before-insert-mode))
-    (viper-change-cursor-color viper-insert-state-cursor-color))
+    (viper-change-cursor-color icolor))
 
   ;; Protect against user errors in hooks
   (condition-case conds
       (viper-set-replace-overlay (point-min) (point-min)))
   (viper-hide-replace-overlay)
 
-  (if viper-emacs-state-cursor-color
-      (let ((has-saved-cursor-color-in-emacs-mode
-            (stringp (viper-get-saved-cursor-color-in-emacs-mode))))
-       (or has-saved-cursor-color-in-emacs-mode
-           (string= (viper-get-cursor-color) viper-emacs-state-cursor-color)
-           (viper-save-cursor-color 'before-emacs-mode))
-       (viper-change-cursor-color viper-emacs-state-cursor-color)))
+  (let ((ecolor (viper-frame-value viper-emacs-state-cursor-color)))
+    (when ecolor
+      (or (stringp (viper-get-saved-cursor-color-in-emacs-mode))
+         (string= (viper-get-cursor-color) ecolor)
+         (viper-save-cursor-color 'before-emacs-mode))
+      (viper-change-cursor-color ecolor)))
 
   (viper-change-state 'emacs-state)
 
@@ -779,16 +766,15 @@ Vi's prefix argument will be used.  Otherwise, the prefix argument passed to
 
          ;; this-command, last-command-char, last-command-event
          (setq this-command com)
-         (viper-cond-compile-for-xemacs-or-emacs
-          ;; XEmacs represents key sequences as vectors
-          (setq last-command-event
-                (viper-copy-event (viper-seq-last-elt key))
-                last-command-char (event-to-character last-command-event))
-          ;; Emacs represents them as sequences (str or vec)
-          (setq last-command-event
-                (viper-copy-event (viper-seq-last-elt key))
-                last-command-char last-command-event)
-          )
+         (if (featurep 'xemacs)
+             ;; XEmacs represents key sequences as vectors
+             (setq last-command-event
+                   (viper-copy-event (viper-seq-last-elt key))
+                   last-command-char (event-to-character last-command-event))
+           ;; Emacs represents them as sequences (str or vec)
+           (setq last-command-event
+                 (viper-copy-event (viper-seq-last-elt key))
+                 last-command-char last-command-event))
 
          (if (commandp com)
              ;; pretend that current state is the state we excaped to
@@ -1850,14 +1836,14 @@ invokes the command before that, etc."
     (message " `.' runs  %s%s"
             (concat "`" (viper-array-to-string keys) "'")
             (viper-abbreviate-string
-             (viper-cond-compile-for-xemacs-or-emacs
-              (replace-in-string ; xemacs
-               (cond ((characterp text) (char-to-string text))
-                     ((stringp text) text)
-                     (t ""))
-               "\n" "^J")
-              text ; emacs
-              )
+             (if (featurep 'xemacs)
+                 (replace-in-string ; xemacs
+                  (cond ((characterp text) (char-to-string text))
+                        ((stringp text) text)
+                        (t ""))
+                  "\n" "^J")
+               text ; emacs
+               )
              max-text-len
              "  inserting  `" "'" "    ......."))
     ))
@@ -2170,10 +2156,10 @@ To turn this feature off, set this variable to nil."
                  (setq cmd
                        (key-binding (setq key (read-key-sequence nil))))
                  (cond ((eq cmd 'self-insert-command)
-                        (viper-cond-compile-for-xemacs-or-emacs
-                         (insert (events-to-keys key)) ; xemacs
-                         (insert key) ; emacs
-                         ))
+                        (if (featurep 'xemacs)
+                            (insert (events-to-keys key)) ; xemacs
+                          (insert key) ; emacs
+                          ))
                        ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
                         nil)
                        (t (command-execute cmd)))
@@ -3462,11 +3448,9 @@ controlled by the sign of prefix numeric value."
 ;; (which is called from viper-search-forward/backward/next).  If the value of
 ;; viper-search-scroll-threshold is negative - don't scroll.
 (defun viper-adjust-window ()
-  (let ((win-height (viper-cond-compile-for-xemacs-or-emacs
-                    (window-displayed-height) ; xemacs
-                    ;; emacs
-                    (1- (window-height)) ; adjust for modeline
-                    ))
+  (let ((win-height (if (featurep 'xemacs)
+                       (window-displayed-height)
+                     (1- (window-height)))) ; adjust for modeline
        (pt (point))
        at-top-p at-bottom-p
        min-scroll direction)
@@ -3477,8 +3461,7 @@ controlled by the sign of prefix numeric value."
                viper-search-scroll-threshold))
       (move-to-window-line -1) ; bottom
       (setq at-bottom-p
-           (<= (count-lines pt (point)) viper-search-scroll-threshold))
-      )
+           (<= (count-lines pt (point)) viper-search-scroll-threshold)))
     (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold)
                          direction  1))
          (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold)
@@ -3913,7 +3896,7 @@ Null string will repeat previous search."
                (if (not (equal start-point (point)))
                    (push-mark start-point t)))
            (search-failed
-            (if (and (not fail-if-not-found) viper-search-wrap-around-t)
+            (if (and (not fail-if-not-found) viper-search-wrap-around)
                 (progn
                   (message "Search wrapped around BOTTOM of buffer")
                   (goto-char (point-min))
@@ -3942,7 +3925,7 @@ Null string will repeat previous search."
              (if (not (equal start-point (point)))
                  (push-mark start-point t)))
          (search-failed
-          (if (and (not fail-if-not-found) viper-search-wrap-around-t)
+          (if (and (not fail-if-not-found) viper-search-wrap-around)
               (progn
                 (message "Search wrapped around TOP of buffer")
                 (goto-char (point-max))
@@ -4790,7 +4773,7 @@ sensitive for VI-style look-and-feel."
         (setq viper-no-multiple-ESC           t
               viper-re-search                 t
               viper-vi-style-in-minibuffer    t
-              viper-search-wrap-around-t      t
+              viper-search-wrap-around        t
               viper-electric-mode             nil
               viper-want-emacs-keys-in-vi     nil
               viper-want-emacs-keys-in-insert nil))