aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kifer1995-10-14 02:27:42 +0000
committerMichael Kifer1995-10-14 02:27:42 +0000
commite0c82342d8242b50b8f98db67fa4dc01e3571ac4 (patch)
treebb9d77343b079ba85ecff691816191999acd9e86
parenta595547cc5d1b912543b866b1aaa9de741ec9aee (diff)
downloademacs-e0c82342d8242b50b8f98db67fa4dc01e3571ac4.tar.gz
emacs-e0c82342d8242b50b8f98db67fa4dc01e3571ac4.zip
(vip-leave-region-active): new function.
-rw-r--r--lisp/emulation/viper-util.el148
1 files changed, 148 insertions, 0 deletions
diff --git a/lisp/emulation/viper-util.el b/lisp/emulation/viper-util.el
index b951ee71a3c..3e3cd658e5a 100644
--- a/lisp/emulation/viper-util.el
+++ b/lisp/emulation/viper-util.el
@@ -859,6 +859,14 @@
859 ((vip-char-symbol-sequence-p event-seq) 859 ((vip-char-symbol-sequence-p event-seq)
860 (mapconcat 'symbol-name event-seq "")) 860 (mapconcat 'symbol-name event-seq ""))
861 (t (prin1-to-string event-seq))))) 861 (t (prin1-to-string event-seq)))))
862
863(defun vip-key-press-events-to-chars (events)
864 (mapconcat (if vip-emacs-p
865 'char-to-string
866 (function
867 (lambda (elt) (char-to-string (event-to-character elt)))))
868 events
869 ""))
862 870
863 871
864(defsubst vip-fast-keysequence-p () 872(defsubst vip-fast-keysequence-p ()
@@ -888,6 +896,146 @@ the `Local variables' section of a file."
888 other-files-or-buffers) 896 other-files-or-buffers)
889 (vip-ring-insert vip-related-files-and-buffers-ring (buffer-name)) 897 (vip-ring-insert vip-related-files-and-buffers-ring (buffer-name))
890 ) 898 )
899
900;;; Movement utilities
901
902(defvar vip-syntax-preference 'strict-vi
903 "*Syntax type characterizing Viper's alphanumeric symbols.
904`emacs' means only word constituents are considered to be alphanumeric.
905Word constituents are symbols specified as word constituents by the current
906syntax table.
907`extended' means word and symbol constituents.
908`reformed-vi' means Vi-ish behavior: word constituents and the symbol `_'.
909However, word constituents are determined according to Emacs syntax tables,
910which may be different from Vi in some major modes.
911`strict-vi' means Viper words are exactly as in Vi.")
912
913(vip-deflocalvar vip-ALPHA-char-class "w"
914 "String of syntax classes characterizing Viper's alphanumeric symbols.
915In addition, the symbol `_' may be considered alphanumeric if
916`vip-syntax-preference'is `reformed-vi'.")
917
918(vip-deflocalvar vip-strict-ALPHA-chars "a-zA-Z0-9_"
919 "Regexp matching the set of alphanumeric characters acceptable to strict
920Vi.")
921(vip-deflocalvar vip-strict-SEP-chars " \t\n"
922 "Regexp matching the set of alphanumeric characters acceptable to strict
923Vi.")
924
925(vip-deflocalvar vip-SEP-char-class " -"
926 "String of syntax classes for Vi separators.
927Usually contains ` ', linefeed, TAB or formfeed.")
928
929(defun vip-update-alphanumeric-class ()
930 "Set the syntactic class of Viper alphanumeric symbols according to
931the variable `vip-ALPHA-char-class'. Should be called in order for changes to
932`vip-ALPHA-char-class' to take effect."
933 (interactive)
934 (setq-default
935 vip-ALPHA-char-class
936 (cond ((eq vip-syntax-preference 'emacs) "w") ; only word constituents
937 ((eq vip-syntax-preference 'extended) "w_") ; word & symbol chars
938 (t "w")))) ; vi syntax: word constituents and the symbol `_'
939
940;; addl-chars are characters to be temporarily considered as alphanumerical
941(defun vip-looking-at-alpha (&optional addl-chars)
942 (or (stringp addl-chars) (setq addl-chars ""))
943 (if (eq vip-syntax-preference 'reformed-vi)
944 (setq addl-chars (concat addl-chars "_")))
945 (let ((char (char-after (point))))
946 (if char
947 (if (eq vip-syntax-preference 'strict-vi)
948 (looking-at (concat "[" vip-strict-ALPHA-chars addl-chars "]"))
949 (or (memq char
950 ;; convert string to list
951 (append (vconcat addl-chars) nil))
952 (memq (char-syntax char)
953 (append (vconcat vip-ALPHA-char-class) nil)))))
954 ))
955
956(defsubst vip-looking-at-separator ()
957 (let ((char (char-after (point))))
958 (if char
959 (or (eq char ?\n) ; RET is always a separator in Vi
960 (memq (char-syntax char)
961 (append (vconcat vip-SEP-char-class) nil))))))
962
963(defsubst vip-looking-at-alphasep (&optional addl-chars)
964 (or (vip-looking-at-separator) (vip-looking-at-alpha addl-chars)))
965
966(defsubst vip-skip-alpha-forward (&optional addl-chars)
967 (or (stringp addl-chars) (setq addl-chars ""))
968 (vip-skip-syntax
969 'forward
970 (cond ((eq vip-syntax-preference 'strict-vi)
971 "")
972 (t vip-ALPHA-char-class ))
973 (cond ((eq vip-syntax-preference 'strict-vi)
974 (concat vip-strict-ALPHA-chars addl-chars))
975 (t addl-chars))))
976
977(defsubst vip-skip-alpha-backward (&optional addl-chars)
978 (or (stringp addl-chars) (setq addl-chars ""))
979 (vip-skip-syntax
980 'backward
981 (cond ((eq vip-syntax-preference 'strict-vi)
982 "")
983 (t vip-ALPHA-char-class ))
984 (cond ((eq vip-syntax-preference 'strict-vi)
985 (concat vip-strict-ALPHA-chars addl-chars))
986 (t addl-chars))))
987
988;; weird syntax tables may confuse strict-vi style
989(defsubst vip-skip-all-separators-forward (&optional within-line)
990 (vip-skip-syntax 'forward
991 vip-SEP-char-class
992 (or within-line "\n")
993 (if within-line (vip-line-pos 'end))))
994(defsubst vip-skip-all-separators-backward (&optional within-line)
995 (vip-skip-syntax 'backward
996 vip-SEP-char-class
997 (or within-line "\n")
998 (if within-line (vip-line-pos 'start))))
999(defun vip-skip-nonseparators (direction)
1000 (let ((func (intern (format "skip-syntax-%S" direction))))
1001 (funcall func (concat "^" vip-SEP-char-class)
1002 (vip-line-pos (if (eq direction 'forward) 'end 'start)))))
1003
1004(defsubst vip-skip-nonalphasep-forward ()
1005 (if (eq vip-syntax-preference 'strict-vi)
1006 (skip-chars-forward
1007 (concat "^" vip-strict-SEP-chars vip-strict-ALPHA-chars))
1008 (skip-syntax-forward
1009 (concat
1010 "^" vip-ALPHA-char-class vip-SEP-char-class) (vip-line-pos 'end))))
1011(defsubst vip-skip-nonalphasep-backward ()
1012 (if (eq vip-syntax-preference 'strict-vi)
1013 (skip-chars-backward
1014 (concat "^" vip-strict-SEP-chars vip-strict-ALPHA-chars))
1015 (skip-syntax-backward
1016 (concat
1017 "^" vip-ALPHA-char-class vip-SEP-char-class) (vip-line-pos 'start))))
1018
1019;; Skip SYNTAX like skip-syntax-* and ADDL-CHARS like skip-chars-*
1020;; Return the number of chars traveled.
1021;; Either SYNTAX or ADDL-CHARS can be nil, in which case they are interpreted
1022;; as an empty string.
1023(defun vip-skip-syntax (direction syntax addl-chars &optional limit)
1024 (let ((total 0)
1025 (local 1)
1026 (skip-chars-func (intern (format "skip-chars-%S" direction)))
1027 (skip-syntax-func (intern (format "skip-syntax-%S" direction))))
1028 (or (stringp addl-chars) (setq addl-chars ""))
1029 (or (stringp syntax) (setq syntax ""))
1030 (while (and (not (= local 0)) (not (eobp)))
1031 (setq local
1032 (+ (funcall skip-syntax-func syntax limit)
1033 (funcall skip-chars-func addl-chars limit)))
1034 (setq total (+ total local)))
1035 total
1036 ))
1037
1038
891 1039
892 1040
893(provide 'viper-util) 1041(provide 'viper-util)