annotate lisp/emulation/viper-util.el @ 110383:e1094870ea06

ftfont.c (ftfont_check_otf): Fix previous change.
author Kenichi Handa <handa@m17n.org>
date Fri, 17 Sep 2010 13:57:58 +0900
parents 280c8ae2476d
children 515d80e174ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
1 ;;; viper-util.el --- Utilities used by viper.el
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14040
diff changeset
2
64701
34bd8e434dd7 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64215
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106192
diff changeset
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
11288
d1f620273acb Add copyright.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
5
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
7 ;; Package: viper
39215
8dccf2552307 2001-09-09 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38723
diff changeset
8
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10
94658
eb7b2376cae5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94658
eb7b2376cae5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
eb7b2376cae5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94658
eb7b2376cae5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36857
diff changeset
24 ;;; Commentary:
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
25
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36857
diff changeset
26 ;;; Code:
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
27
93652
6523ed37006c 2008-04-04 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 93615
diff changeset
28 (provide 'viper-util)
6523ed37006c 2008-04-04 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 93615
diff changeset
29
6523ed37006c 2008-04-04 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 93615
diff changeset
30
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
31 ;; Compiler pacifier
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
32 (defvar viper-overriding-map)
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
33 (defvar pm-color-alist)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
34 (defvar viper-minibuffer-current-face)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
35 (defvar viper-minibuffer-insert-face)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
36 (defvar viper-minibuffer-vi-face)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
37 (defvar viper-minibuffer-emacs-face)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
38 (defvar viper-replace-overlay-face)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
39 (defvar viper-fast-keyseq-timeout)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
40 (defvar ex-unix-type-shell)
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
41 (defvar ex-unix-type-shell-options)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
42 (defvar viper-ex-tmp-buf-name)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
43 (defvar viper-syntax-preference)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
44 (defvar viper-saved-mark)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
45
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
46 (require 'ring)
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
47
87691
f2c8fd594360 2008-01-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 87678
diff changeset
48 (eval-and-compile
f2c8fd594360 2008-01-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 87678
diff changeset
49 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
f2c8fd594360 2008-01-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 87678
diff changeset
50
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
51 ;; end pacifier
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
53 (require 'viper-init)
15747
a0933adcee9e (vip-ms-style-os-p, vip-vms-os-p): Moved here from viper.el.
Karl Heuer <kwzh@gnu.org>
parents: 15728
diff changeset
54
14581
4951b11970a1 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14384
diff changeset
55
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
57 (defalias 'viper-overlay-p
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
58 (if (featurep 'xemacs) 'extentp 'overlayp))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
59 (defalias 'viper-make-overlay
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
60 (if (featurep 'xemacs) 'make-extent 'make-overlay))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
61 (defalias 'viper-overlay-live-p
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
62 (if (featurep 'xemacs) 'extent-live-p 'overlayp))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
63 (defalias 'viper-move-overlay
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
64 (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
65 (defalias 'viper-overlay-start
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
66 (if (featurep 'xemacs) 'extent-start-position 'overlay-start))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
67 (defalias 'viper-overlay-end
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
68 (if (featurep 'xemacs) 'extent-end-position 'overlay-end))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
69 (defalias 'viper-overlay-get
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
70 (if (featurep 'xemacs) 'extent-property 'overlay-get))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
71 (defalias 'viper-overlay-put
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
72 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
73 (defalias 'viper-read-event
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
74 (if (featurep 'xemacs) 'next-command-event 'read-event))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
75 (defalias 'viper-characterp
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
76 (if (featurep 'xemacs) 'characterp 'integerp))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
77 (defalias 'viper-int-to-char
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
78 (if (featurep 'xemacs) 'int-to-char 'identity))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
79 (defalias 'viper-get-face
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
80 (if (featurep 'xemacs) 'get-face 'internal-get-face))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
81 (defalias 'viper-color-defined-p
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
82 (if (featurep 'xemacs) 'valid-color-name-p 'x-color-defined-p))
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
83 (defalias 'viper-iconify
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
84 (if (featurep 'xemacs) 'iconify-frame 'iconify-or-deiconify-frame))
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
85
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
86
33842
f6a67d77484a * ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33742
diff changeset
87 ;; CHAR is supposed to be a char or an integer (positive or negative)
f6a67d77484a * ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33742
diff changeset
88 ;; LIST is a list of chars, nil, and negative numbers
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
89 ;; Check if CHAR is a member by trying to convert in characters, if necessary.
33842
f6a67d77484a * ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33742
diff changeset
90 ;; Introduced for compatibility with XEmacs, where integers are not the same as
f6a67d77484a * ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33742
diff changeset
91 ;; chars.
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
92 (defun viper-memq-char (char list)
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
93 (cond ((and (integerp char) (>= char 0))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
94 (memq (viper-int-to-char char) list))
33842
f6a67d77484a * ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33742
diff changeset
95 ((memq char list))))
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
96
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
97 ;; Check if char-or-int and char are the same as characters
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
98 (defun viper-char-equal (char-or-int char)
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
99 (cond ((and (integerp char-or-int) (>= char-or-int 0))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
100 (= (viper-int-to-char char-or-int) char))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
101 ((eq char-or-int char))))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
102
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
103 ;; Like =, but accommodates null and also is t for eq-objects
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
104 (defun viper= (char char1)
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
105 (cond ((eq char char1) t)
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
106 ((and (viper-characterp char) (viper-characterp char1))
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
107 (= char char1))
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
108 (t nil)))
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
109
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
110 (defsubst viper-color-display-p ()
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
111 (if (featurep 'xemacs) (eq (device-class (selected-device)) 'color)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
112 (x-display-color-p)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
113
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
114 (defun viper-get-cursor-color (&optional frame)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
115 (if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
116 (color-instance-name
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
117 (frame-property (or frame (selected-frame)) 'cursor-color))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
118 (cdr (assoc 'cursor-color (frame-parameters)))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
119
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
120 (defmacro viper-frame-value (variable)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
121 "Return the value of VARIABLE local to the current frame, if there is one.
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
122 Otherwise return the normal value."
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
123 `(if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
124 ,variable
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
125 ;; Frame-local variables are obsolete from Emacs 22.2 onwards,
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
126 ;; so we do it by hand instead.
92422
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
127 ;; Buffer-local values take precedence over frame-local ones.
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
128 (if (local-variable-p ',variable)
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
129 ,variable
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
130 ;; Distinguish between no frame parameter and a frame parameter
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
131 ;; with a value of nil.
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
132 (let ((fp (assoc ',variable (frame-parameters))))
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
133 (if fp (cdr fp)
f3c93a3ef0d5 (viper-frame-value): Prefer buffer-local value, if set, over frame value.
Glenn Morris <rgm@gnu.org>
parents: 92380
diff changeset
134 ,variable)))))
16136
de1340e6ddb4 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15747
diff changeset
135
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 ;; OS/2
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
137 (cond ((eq (viper-device-type) 'pm)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
138 (fset 'viper-color-defined-p
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
139 (lambda (color) (assoc color pm-color-alist)))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
140
14233
396316e5fbe6 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14169
diff changeset
141
396316e5fbe6 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14169
diff changeset
142 ;; cursor colors
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
143 (defun viper-change-cursor-color (new-color &optional frame)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
144 (if (and (viper-window-display-p) (viper-color-display-p)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
145 (stringp new-color) (viper-color-defined-p new-color)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
146 (not (string= new-color (viper-get-cursor-color))))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
147 (if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
148 (set-frame-property
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
149 (or frame (selected-frame))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
150 'cursor-color (make-color-instance new-color))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
151 (modify-frame-parameters
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
152 (or frame (selected-frame))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
153 (list (cons 'cursor-color new-color))))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
154
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
155 ;; Note that the colors this function uses might not be those
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
156 ;; associated with FRAME, if there are frame-local values.
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
157 ;; This was equally true before the advent of viper-frame-value.
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
158 ;; Now it could be changed by passing frame to v-f-v.
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
159 (defun viper-set-cursor-color-according-to-state (&optional frame)
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
160 (cond ((eq viper-current-state 'replace-state)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
161 (viper-change-cursor-color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
162 (viper-frame-value viper-replace-overlay-cursor-color)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
163 frame))
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
164 ((and (eq viper-current-state 'emacs-state)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
165 (viper-frame-value viper-emacs-state-cursor-color))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
166 (viper-change-cursor-color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
167 (viper-frame-value viper-emacs-state-cursor-color)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
168 frame))
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
169 ((eq viper-current-state 'insert-state)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
170 (viper-change-cursor-color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
171 (viper-frame-value viper-insert-state-cursor-color)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
172 frame))
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
173 (t
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
174 (viper-change-cursor-color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
175 (viper-frame-value viper-vi-state-cursor-color)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
176 frame))))
72516
aba79a1f03ed 2006-08-25 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 71382
diff changeset
177
106192
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
178 ;; By default, saves current frame cursor color before changing viper state
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
179 (defun viper-save-cursor-color (before-which-mode)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
180 (if (and (viper-window-display-p) (viper-color-display-p))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
181 (let ((color (viper-get-cursor-color)))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
182 (if (and (stringp color) (viper-color-defined-p color)
106192
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
183 ;; there is something fishy in that the color is not saved if
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
184 ;; it is the same as frames default cursor color. need to be
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
185 ;; checked.
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
186 (not (string= color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
187 (viper-frame-value
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
188 viper-replace-overlay-cursor-color))))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
189 (modify-frame-parameters
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
190 (selected-frame)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
191 (list
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
192 (cons
68997
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
193 (cond ((eq before-which-mode 'before-replace-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
194 'viper-saved-cursor-color-in-replace-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
195 ((eq before-which-mode 'before-emacs-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
196 'viper-saved-cursor-color-in-emacs-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
197 (t
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
198 'viper-saved-cursor-color-in-insert-mode))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
199 color)))))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
200
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
201
99595
eb7532b56b78 2008-11-16 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 97142
diff changeset
202 (defun viper-get-saved-cursor-color-in-replace-mode ()
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
203 (or
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
204 (funcall
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
205 (if (featurep 'emacs) 'frame-parameter 'frame-property)
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
206 (selected-frame)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
207 'viper-saved-cursor-color-in-replace-mode)
93615
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
208 (or (and (eq viper-current-state 'emacs-mode)
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
209 (viper-frame-value viper-emacs-state-cursor-color))
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
210 (viper-frame-value viper-vi-state-cursor-color))))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
211
99595
eb7532b56b78 2008-11-16 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 97142
diff changeset
212 (defun viper-get-saved-cursor-color-in-insert-mode ()
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
213 (or
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
214 (funcall
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
215 (if (featurep 'emacs) 'frame-parameter 'frame-property)
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
216 (selected-frame)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
217 'viper-saved-cursor-color-in-insert-mode)
93615
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
218 (or (and (eq viper-current-state 'emacs-mode)
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
219 (viper-frame-value viper-emacs-state-cursor-color))
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
220 (viper-frame-value viper-vi-state-cursor-color))))
68997
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
221
99595
eb7532b56b78 2008-11-16 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 97142
diff changeset
222 (defun viper-get-saved-cursor-color-in-emacs-mode ()
68997
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
223 (or
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
224 (funcall
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
225 (if (featurep 'emacs) 'frame-parameter 'frame-property)
68997
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
226 (selected-frame)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
227 'viper-saved-cursor-color-in-emacs-mode)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
228 (viper-frame-value viper-vi-state-cursor-color)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
229
16766
beb94a5271e2 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16329
diff changeset
230 ;; restore cursor color from replace overlay
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
231 (defun viper-restore-cursor-color(after-which-mode)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
232 (if (viper-overlay-p viper-replace-overlay)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
233 (viper-change-cursor-color
68997
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
234 (cond ((eq after-which-mode 'after-replace-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
235 (viper-get-saved-cursor-color-in-replace-mode))
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
236 ((eq after-which-mode 'after-emacs-mode)
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
237 (viper-get-saved-cursor-color-in-emacs-mode))
6169b51037af 2006-02-19 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 68648
diff changeset
238 (t (viper-get-saved-cursor-color-in-insert-mode)))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
239 )))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
240
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
241
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 ;; Check the current version against the major and minor version numbers
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 ;; using op: cur-vers op major.minor If emacs-major-version or
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 ;; emacs-minor-version are not defined, we assume that the current version
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 ;; is hopelessly outdated. We assume that emacs-major-version and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
249 ;; incorrect. However, this gives correct result in our cases, since we are
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250 ;; testing for sufficiently high Emacs versions.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
251 (defun viper-check-version (op major minor &optional type-of-emacs)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
253 (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
254 ((eq type-of-emacs 'emacs) (featurep 'emacs))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 (t t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 (cond ((eq op '=) (and (= emacs-minor-version minor)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 (= emacs-major-version major)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 ((memq op '(> >= < <=))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 (and (or (funcall op emacs-major-version major)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 (= emacs-major-version major))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 (if (= emacs-major-version major)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262 (funcall op emacs-minor-version minor)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263 t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 (t
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
265 (error "%S: Invalid op in viper-check-version" op))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266 (cond ((memq op '(= > >=)) nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
267 ((memq op '(< <=)) t))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
268
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
270 (defun viper-get-visible-buffer-window (wind)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
271 (if (featurep 'xemacs)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 (get-buffer-window wind t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 (get-buffer-window wind 'visible)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
274
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
275
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
276 ;; Return line position.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
277 ;; If pos is 'start then returns position of line start.
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
278 ;; If pos is 'end, returns line end. If pos is 'mid, returns line center.
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
279 ;; Pos = 'indent returns beginning of indentation.
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
280 ;; Otherwise, returns point. Current point is not moved in any case."
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
281 (defun viper-line-pos (pos)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 (let ((cur-pos (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 (result))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284 (cond
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 ((equal pos 'start)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 (beginning-of-line))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 ((equal pos 'end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288 (end-of-line))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289 ((equal pos 'mid)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
290 (goto-char (+ (viper-line-pos 'start) (viper-line-pos 'end) 2)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 ((equal pos 'indent)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 (back-to-indentation))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 (t nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 (setq result (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295 (goto-char cur-pos)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296 result))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297
47520
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
298 ;; Emacs used to count each multibyte character as several positions in the buffer,
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
299 ;; so we had to use Emacs' chars-in-region to count characters. Since 20.3,
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
300 ;; Emacs counts multibyte characters as 1 position. XEmacs has always been
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
301 ;; counting each char as just one pos. So, now we can simply subtract beg from
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
302 ;; end to determine the number of characters in a region.
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
303 (defun viper-chars-in-region (beg end &optional preserve-sign)
47520
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
304 ;;(let ((count (abs (if (fboundp 'chars-in-region)
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
305 ;; (chars-in-region beg end)
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
306 ;; (- end beg)))))
a37b476e1aec 2002-09-18 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 43220
diff changeset
307 (let ((count (abs (- end beg))))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
308 (if (and (< end beg) preserve-sign)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
309 (- count)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
310 count)))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
311
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
312 ;; Test if POS is between BEG and END
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
313 (defsubst viper-pos-within-region (pos beg end)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
314 (and (>= pos (min beg end)) (>= (max beg end) pos)))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
315
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
317 ;; Like move-marker but creates a virgin marker if arg isn't already a marker.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
318 ;; The first argument must eval to a variable name.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
319 ;; Arguments: (var-name position &optional buffer).
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
320 ;;
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
321 ;; This is useful for moving markers that are supposed to be local.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
322 ;; For this, VAR-NAME should be made buffer-local with nil as a default.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
323 ;; Then, each time this var is used in `viper-move-marker-locally' in a new
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
324 ;; buffer, a new marker will be created.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
325 (defun viper-move-marker-locally (var pos &optional buffer)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326 (if (markerp (eval var))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328 (set var (make-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 (move-marker (eval var) pos buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
332 ;; Print CONDITIONS as a message.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
333 (defun viper-message-conditions (conditions)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 (let ((case (car conditions)) (msg (cdr conditions)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 (if (null msg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 (message "%s" case)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337 (message "%s: %s" case (mapconcat 'prin1-to-string msg " ")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 (beep 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
340
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 ;;; List/alist utilities
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
343
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
344 ;; Convert LIST to an alist
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
345 (defun viper-list-to-alist (lst)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346 (let ((alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347 (while lst
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 (setq alist (cons (list (car lst)) alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349 (setq lst (cdr lst)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
350 alist))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
352 ;; Convert ALIST to a list.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
353 (defun viper-alist-to-list (alst)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354 (let ((lst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
355 (while alst
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356 (setq lst (cons (car (car alst)) lst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357 (setq alst (cdr alst)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358 lst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
360 ;; Filter ALIST using REGEXP. Return alist whose elements match the regexp.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
361 (defun viper-filter-alist (regexp alst)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 (interactive "s x")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 (let ((outalst) (inalst alst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 (while (car inalst)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 (if (string-match regexp (car (car inalst)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 (setq outalst (cons (car inalst) outalst)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 (setq inalst (cdr inalst)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
368 outalst))
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
369
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
370 ;; Filter LIST using REGEXP. Return list whose elements match the regexp.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
371 (defun viper-filter-list (regexp lst)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372 (interactive "s x")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 (let ((outlst) (inlst lst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 (while (car inlst)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375 (if (string-match regexp (car inlst))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 (setq outlst (cons (car inlst) outlst)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 (setq inlst (cdr inlst)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
378 outlst))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
380
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 ;; LIS2 is modified by filtering it: deleting its members of the form
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 ;; \(car elt\) such that (car elt') is in LIS1.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
384 (defun viper-append-filter-alist (lis1 lis2)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 (let ((temp lis1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 elt)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 ;;filter-append the second list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 (while temp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 ;; delete all occurrences
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 (while (setq elt (assoc (car (car temp)) lis2))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 (setq lis2 (delq elt lis2)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 (setq temp (cdr temp)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
393
64750
fbdb9482b6fc 2005-08-06 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64701
diff changeset
394 (append lis1 lis2)))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
395
36857
f6386773ce30 2001-03-17 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 33842
diff changeset
396
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
397
87691
f2c8fd594360 2008-01-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 87678
diff changeset
398 (declare-function viper-forward-Word "viper-cmd" (arg))
86243
4d615a83cee2 * progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents: 85972
diff changeset
399
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
400 ;;; Support for :e, :r, :w file globbing
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
401
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
402 ;; Glob the file spec.
97142
c3512b2085a0 * bitmaps/README:
Dan Nicolaescu <dann@ics.uci.edu>
parents: 96675
diff changeset
403 ;; This function is designed to work under Unix.
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
404 (defun viper-glob-unix-files (filespec)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
405 (let ((gshell
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
406 (cond (ex-unix-type-shell shell-file-name)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
407 (t "sh"))) ; probably Unix anyway
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
408 (gshell-options
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
409 ;; using cond in anticipation of further additions
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
410 (cond (ex-unix-type-shell-options)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
411 ))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
412 (command (cond (viper-ms-style-os-p (format "\"ls -1 -d %s\"" filespec))
16136
de1340e6ddb4 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15747
diff changeset
413 (t (format "ls -1 -d %s" filespec))))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
414 status)
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
415 (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
416 (erase-buffer)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
417 (setq status
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
418 (if gshell-options
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
419 (call-process gshell nil t nil
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
420 gshell-options
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
421 "-c"
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
422 command)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
423 (call-process gshell nil t nil
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
424 "-c"
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
425 command)))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
426 (goto-char (point-min))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
427 ;; Issue an error, if no match.
53477
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
428 (unless (eq 0 status)
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
429 (save-excursion
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
430 (skip-chars-forward " \t\n\j")
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
431 (if (looking-at "ls:")
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
432 (viper-forward-Word 1))
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
433 (error "%s: %s"
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
434 (if (stringp gshell)
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
435 gshell
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
436 "shell")
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
437 (buffer-substring (point) (viper-line-pos 'end)))
79093b308520 * progmodes/idlwave.el (idlwave-make-tags):
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52401
diff changeset
438 ))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
439 (goto-char (point-min))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
440 (viper-get-filenames-from-buffer 'one-per-line))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
441 ))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
442
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
443
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
444 ;; Interpret the stuff in the buffer as a list of file names
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
445 ;; return a list of file names listed in the buffer beginning at point
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
446 ;; If optional arg is supplied, assume each filename is listed on a separate
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
447 ;; line
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
448 (defun viper-get-filenames-from-buffer (&optional one-per-line)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
449 (let ((skip-chars (if one-per-line "\t\n" " \t\n"))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
450 result fname delim)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
451 (skip-chars-forward skip-chars)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
452 (while (not (eobp))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
453 (if (cond ((looking-at "\"")
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
454 (setq delim ?\")
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
455 (re-search-forward "[^\"]+" nil t)) ; noerror
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
456 ((looking-at "'")
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
457 (setq delim ?')
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
458 (re-search-forward "[^']+" nil t)) ; noerror
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
459 (t
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
460 (re-search-forward
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
461 (concat "[^" skip-chars "]+") nil t))) ;noerror
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
462 (setq fname
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
463 (buffer-substring (match-beginning 0) (match-end 0))))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
464 (if delim
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
465 (forward-char 1))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
466 (skip-chars-forward " \t\n")
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
467 (setq result (cons fname result)))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
468 result))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
469
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
470 ;; convert MS-DOS wildcards to regexp
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
471 (defun viper-wildcard-to-regexp (wcard)
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
472 (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
473 (erase-buffer)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
474 (insert wcard)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
475 (goto-char (point-min))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
476 (while (not (eobp))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
477 (skip-chars-forward "^*?.\\\\")
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
478 (cond ((eq (char-after (point)) ?*) (insert ".")(forward-char 1))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
479 ((eq (char-after (point)) ?.) (insert "\\")(forward-char 1))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
480 ((eq (char-after (point)) ?\\) (insert "\\")(forward-char 1))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
481 ((eq (char-after (point)) ??) (delete-char 1)(insert ".")))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
482 )
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
483 (buffer-string)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
484 ))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
485
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
486
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
487 ;; glob windows files
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
488 ;; LIST is expected to be in reverse order
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
489 (defun viper-glob-mswindows-files (filespec)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
490 (let ((case-fold-search t)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
491 tmp tmp2)
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
492 (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
493 (erase-buffer)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
494 (insert filespec)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
495 (goto-char (point-min))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
496 (setq tmp (viper-get-filenames-from-buffer))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
497 (while tmp
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
498 (setq tmp2 (cons (directory-files
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
499 ;; the directory part
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
500 (or (file-name-directory (car tmp))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
501 "")
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
502 t ; return full names
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
503 ;; the regexp part: globs the file names
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
504 (concat "^"
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
505 (viper-wildcard-to-regexp
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
506 (file-name-nondirectory (car tmp)))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
507 "$"))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
508 tmp2))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
509 (setq tmp (cdr tmp)))
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
510 (reverse (apply 'append tmp2)))))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
511
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 ;;; Insertion ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
515 ;; Rotate RING's index. DIRection can be positive or negative.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
516 (defun viper-ring-rotate1 (ring dir)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 (if (and (ring-p ring) (> (ring-length ring) 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
519 (setcar ring (cond ((> dir 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 (ring-plus1 (car ring) (ring-length ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
521 ((< dir 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
522 (ring-minus1 (car ring) (ring-length ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
523 ;; don't rotate if dir = 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
524 (t (car ring))))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
525 (viper-current-ring-item ring)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
526 )))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
527
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
528 (defun viper-special-ring-rotate1 (ring dir)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
529 (if (memq viper-intermediate-command
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530 '(repeating-display-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 repeating-insertion-from-ring))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
532 (viper-ring-rotate1 ring dir)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 ;; don't rotate otherwise
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
534 (viper-ring-rotate1 ring 0)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
535
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 ;; current ring item; if N is given, then so many items back from the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 ;; current
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
538 (defun viper-current-ring-item (ring &optional n)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 (setq n (or n 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540 (if (and (ring-p ring) (> (ring-length ring) 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring)))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
542
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
543 ;; Push item onto ring. The second argument is a ring-variable, not value.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
544 (defun viper-push-onto-ring (item ring-var)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545 (or (ring-p (eval ring-var))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547 (or (null item) ; don't push nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548 (and (stringp item) (string= item "")) ; or empty strings
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
549 (equal item (viper-current-ring-item (eval ring-var))) ; or old stuff
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
550 ;; Since viper-set-destructive-command checks if we are inside
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
551 ;; viper-repeat, we don't check whether this-command-keys is a `.'. The
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
552 ;; cmd viper-repeat makes a call to the current function only if `.' is
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
553 ;; executing a command from the command history. It doesn't call the
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
554 ;; push-onto-ring function if `.' is simply repeating the last
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
555 ;; destructive command. We only check for ESC (which happens when we do
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
556 ;; insert with a prefix argument, or if this-command-keys doesn't give
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
557 ;; anything meaningful (in that case we don't know what to show to the
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
558 ;; user).
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
559 (and (eq ring-var 'viper-command-ring)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
560 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)"
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
561 (viper-array-to-string (this-command-keys))))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
562 (viper-ring-insert (eval ring-var) item))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 )
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
564
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
566 ;; removing elts from ring seems to break it
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
567 (defun viper-cleanup-ring (ring)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
568 (or (< (ring-length ring) 2)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
569 (null (viper-current-ring-item ring))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 ;; last and previous equal
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
571 (if (equal (viper-current-ring-item ring)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
572 (viper-current-ring-item ring 1))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
573 (viper-ring-pop ring))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
574
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
575 ;; ring-remove seems to be buggy, so we concocted this for our purposes.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
576 (defun viper-ring-pop (ring)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
577 (let* ((ln (ring-length ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
578 (vec (cdr (cdr ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
579 (veclen (length vec))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
580 (hd (car ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
581 (idx (max 0 (ring-minus1 hd ln)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
582 (top-elt (aref vec idx)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
583
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
584 ;; shift elements
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585 (while (< (1+ idx) veclen)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586 (aset vec idx (aref vec (1+ idx)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 (setq idx (1+ idx)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588 (aset vec idx nil)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
589
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 (setq hd (max 0 (ring-minus1 hd ln)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591 (if (= hd (1- ln)) (setq hd 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 (setcar ring hd) ; move head
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594 top-elt
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
595 ))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
596
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
597 (defun viper-ring-insert (ring item)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 (let* ((ln (ring-length ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 (vec (cdr (cdr ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
600 (veclen (length vec))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601 (hd (car ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 (vecpos-after-hd (if (= hd 0) ln hd))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603 (idx ln))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
604
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605 (if (= ln veclen)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 (aset vec hd item) ; hd is always 1+ the actual head index in vec
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 (setcar ring (ring-plus1 hd ln)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 (setcar (cdr ring) (1+ ln))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 (setcar ring (ring-plus1 vecpos-after-hd (1+ ln)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 (while (and (>= idx vecpos-after-hd) (> ln 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612 (aset vec idx (aref vec (1- idx)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 (setq idx (1- idx)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 (aset vec vecpos-after-hd item))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
615 item))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
616
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 ;;; String utilities
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
619
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
620 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
621 ;; PRE-STRING is a string to prepend to the abbrev string.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 ;; POST-STRING is a string to append to the abbrev string.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623 ;; ABBREV_SIGN is a string to be inserted before POST-STRING
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
624 ;; if the orig string was truncated.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
625 (defun viper-abbreviate-string (string max-len
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
626 pre-string post-string abbrev-sign)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
627 (let (truncated-str)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
628 (setq truncated-str
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
629 (if (stringp string)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
630 (substring string 0 (min max-len (length string)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
631 (cond ((null truncated-str) "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
632 ((> (length string) max-len)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
633 (format "%s%s%s%s"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
634 pre-string truncated-str abbrev-sign post-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
635 (t (format "%s%s%s" pre-string truncated-str post-string)))))
12204
a7bd91d4af97 (vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents: 12139
diff changeset
636
a7bd91d4af97 (vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents: 12139
diff changeset
637 ;; tells if we are over a whitespace-only line
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
638 (defsubst viper-over-whitespace-line ()
12204
a7bd91d4af97 (vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents: 12139
diff changeset
639 (save-excursion
a7bd91d4af97 (vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents: 12139
diff changeset
640 (beginning-of-line)
a7bd91d4af97 (vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents: 12139
diff changeset
641 (looking-at "^[ \t]*$")))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
642
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
643
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
644 ;;; Saving settings in custom file
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
645
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
646 ;; Save the current setting of VAR in CUSTOM-FILE.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
647 ;; If given, MESSAGE is a message to be displayed after that.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
648 ;; This message is erased after 2 secs, if erase-msg is non-nil.
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
649 ;; Arguments: var message custom-file &optional erase-message
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
650 (defun viper-save-setting (var message custom-file &optional erase-msg)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
651 (let* ((var-name (symbol-name var))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
652 (var-val (if (boundp var) (eval var)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
653 (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
654 (buf (find-file-noselect (substitute-in-file-name custom-file)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
655 )
87170
e50a2e215441 * erc-stamp.el (erc-echo-timestamp):
David Kastrup <dak@gnu.org>
parents: 86977
diff changeset
656 (message "%s" (or message ""))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
657 (with-current-buffer buf
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
658 (goto-char (point-min))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659 (if (re-search-forward regexp nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660 (let ((reg-end (1- (match-end 0))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661 (search-backward var-name)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 (delete-region (match-beginning 0) reg-end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663 (goto-char (match-beginning 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 (insert (format "%s '%S" var-name var-val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 (goto-char (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666 (if (not (bolp)) (insert "\n"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 (insert (format "(setq %s '%S)\n" var-name var-val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668 (save-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669 (kill-buffer buf)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 (if erase-msg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
672 (sit-for 2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673 (message "")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674 ))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
675
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
676 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
677 ;; match this pattern.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
678 (defun viper-save-string-in-file (string custom-file &optional pattern)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 (let ((buf (find-file-noselect (substitute-in-file-name custom-file))))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
680 (with-current-buffer buf
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
681 (let (buffer-read-only)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
682 (goto-char (point-min))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
683 (if pattern (delete-matching-lines pattern))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
684 (goto-char (point-max))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
685 (if string (insert string))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
686 (save-buffer)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687 (kill-buffer buf)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 ))
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
689
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
690
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
691 ;; This is a simple-minded check for whether a file is under version control.
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
692 ;; If file,v exists but file doesn't, this file is considered to be not checked
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
693 ;; in and not checked out for the purpose of patching (since patch won't be
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
694 ;; able to read such a file anyway).
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
695 ;; FILE is a string representing file name
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
696 ;;(defun viper-file-under-version-control (file)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
697 ;; (let* ((filedir (file-name-directory file))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
698 ;; (file-nondir (file-name-nondirectory file))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
699 ;; (trial (concat file-nondir ",v"))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
700 ;; (full-trial (concat filedir trial))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
701 ;; (full-rcs-trial (concat filedir "RCS/" trial)))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
702 ;; (and (stringp file)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
703 ;; (file-exists-p file)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
704 ;; (or
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
705 ;; (and
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
706 ;; (file-exists-p full-trial)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
707 ;; ;; in FAT FS, `file,v' and `file' may turn out to be the same!
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
708 ;; ;; don't be fooled by this!
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
709 ;; (not (equal (file-attributes file)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
710 ;; (file-attributes full-trial))))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
711 ;; ;; check if a version is in RCS/ directory
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
712 ;; (file-exists-p full-rcs-trial)))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
713 ;; ))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
714
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
715
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
716 (defsubst viper-file-checked-in-p (file)
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
717 (and (featurep 'vc-hooks)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
718 ;; CVS files are considered not checked in
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
719 ;; FIXME: Should this deal with more than CVS?
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
720 (not (memq (vc-backend file) '(nil CVS)))
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
721 (if (fboundp 'vc-state)
38723
3a1c2213b3d2 (viper-file-checked-in-p): Use `and'
Gerd Moellmann <gerd@gnu.org>
parents: 38514
diff changeset
722 (and
38514
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
723 (not (memq (vc-state file) '(edited needs-merge)))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
724 (not (stringp (vc-state file))))
10482dd382e7 * viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 38414
diff changeset
725 ;; XEmacs has no vc-state
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
726 (if (featurep 'xemacs) (not (vc-locking-user file))))))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
727
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
728 ;; checkout if visited file is checked in
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
729 (defun viper-maybe-checkout (buf)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
730 (let ((file (expand-file-name (buffer-file-name buf)))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
731 (checkout-function (key-binding "\C-x\C-q")))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
732 (if (and (viper-file-checked-in-p file)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
733 (or (beep 1) t)
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
734 (y-or-n-p
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
735 (format
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
736 "File %s is checked in. Check it out? "
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
737 (viper-abbreviate-file-name file))))
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
738 (with-current-buffer buf
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
739 (command-execute checkout-function)))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
740
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
741
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
742
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
743
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
744 ;;; Overlays
28510
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
745 (defun viper-put-on-search-overlay (beg end)
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
746 (if (viper-overlay-p viper-search-overlay)
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
747 (viper-move-overlay viper-search-overlay beg end)
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
748 (setq viper-search-overlay (viper-make-overlay beg end (current-buffer)))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
749 (viper-overlay-put
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
750 viper-search-overlay 'priority viper-search-overlay-priority))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
751 (viper-overlay-put viper-search-overlay 'face viper-search-face))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
752
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
753 ;; Search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
754
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
755 (defun viper-flash-search-pattern ()
28510
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
756 (if (not (viper-has-face-support-p))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
757 nil
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
758 (viper-put-on-search-overlay (match-beginning 0) (match-end 0))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
759 (sit-for 2)
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
760 (viper-overlay-put viper-search-overlay 'face nil)))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
761
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
762 (defun viper-hide-search-overlay ()
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
763 (if (not (viper-overlay-p viper-search-overlay))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
764 (progn
28510
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
765 (setq viper-search-overlay
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
766 (viper-make-overlay (point-min) (point-min) (current-buffer)))
28510
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
767 (viper-overlay-put
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
768 viper-search-overlay 'priority viper-search-overlay-priority)))
6fb7a3864791 2000-04-07 Mikio Nakajima <minakaji@osaka.email.ne.jp>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 27899
diff changeset
769 (viper-overlay-put viper-search-overlay 'face nil))
16136
de1340e6ddb4 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15747
diff changeset
770
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
771 ;; Replace state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
772
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
773 (defsubst viper-move-replace-overlay (beg end)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
774 (viper-move-overlay viper-replace-overlay beg end))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
775
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
776 (defun viper-set-replace-overlay (beg end)
27899
42f9a58e0fc4 * viper-cmd.el (viper-envelop-ESC-key): added the option to
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 26263
diff changeset
777 (if (viper-overlay-live-p viper-replace-overlay)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
778 (viper-move-replace-overlay beg end)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
779 (setq viper-replace-overlay (viper-make-overlay beg end (current-buffer)))
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
780 ;; never detach
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
781 (viper-overlay-put
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
782 viper-replace-overlay (if (featurep 'emacs) 'evaporate 'detachable) nil)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
783 (viper-overlay-put
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
784 viper-replace-overlay 'priority viper-replace-overlay-priority)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
785 ;; If Emacs will start supporting overlay maps, as it currently supports
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
786 ;; text-property maps, we could do away with viper-replace-minor-mode and
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
787 ;; just have keymap attached to replace overlay.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
788 ;;(viper-overlay-put
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
789 ;; viper-replace-overlay
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
790 ;; (if (featurep 'xemacs) 'keymap 'local-map)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
791 ;; viper-replace-map)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
792 )
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
793 (if (viper-has-face-support-p)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
794 (viper-overlay-put
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
795 viper-replace-overlay 'face viper-replace-overlay-face))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
796 (viper-save-cursor-color 'before-replace-mode)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
797 (viper-change-cursor-color
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
798 (viper-frame-value viper-replace-overlay-cursor-color)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
799
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
800
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
801 (defun viper-set-replace-overlay-glyphs (before-glyph after-glyph)
27899
42f9a58e0fc4 * viper-cmd.el (viper-envelop-ESC-key): added the option to
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 26263
diff changeset
802 (or (viper-overlay-live-p viper-replace-overlay)
42f9a58e0fc4 * viper-cmd.el (viper-envelop-ESC-key): added the option to
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 26263
diff changeset
803 (viper-set-replace-overlay (point-min) (point-min)))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
804 (if (or (not (viper-has-face-support-p))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
805 viper-use-replace-region-delimiters)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
806 (let ((before-name (if (featurep 'xemacs) 'begin-glyph 'before-string))
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
807 (after-name (if (featurep 'xemacs) 'end-glyph 'after-string)))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
808 (viper-overlay-put viper-replace-overlay before-name before-glyph)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
809 (viper-overlay-put viper-replace-overlay after-name after-glyph))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
810
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
811 (defun viper-hide-replace-overlay ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
812 (viper-set-replace-overlay-glyphs nil nil)
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
813 (viper-restore-cursor-color 'after-replace-mode)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
814 (viper-restore-cursor-color 'after-insert-mode)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
815 (if (viper-has-face-support-p)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
816 (viper-overlay-put viper-replace-overlay 'face nil)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
817
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
818
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
819 (defsubst viper-replace-start ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
820 (viper-overlay-start viper-replace-overlay))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
821 (defsubst viper-replace-end ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
822 (viper-overlay-end viper-replace-overlay))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
823
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
824
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
825 ;; Minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
826
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
827 (defun viper-set-minibuffer-overlay ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
828 (viper-check-minibuffer-overlay)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
829 (when (viper-has-face-support-p)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
830 (viper-overlay-put
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
831 viper-minibuffer-overlay 'face viper-minibuffer-current-face)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
832 (viper-overlay-put
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
833 viper-minibuffer-overlay 'priority viper-minibuffer-overlay-priority)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
834 ;; never detach
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
835 (viper-overlay-put
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
836 viper-minibuffer-overlay
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
837 (if (featurep 'emacs) 'evaporate 'detachable)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
838 nil)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
839 ;; make viper-minibuffer-overlay open-ended
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
840 ;; In emacs, it is made open ended at creation time
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
841 (when (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
842 (viper-overlay-put viper-minibuffer-overlay 'start-open nil)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
843 (viper-overlay-put viper-minibuffer-overlay 'end-open nil))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
844
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
845 (defun viper-check-minibuffer-overlay ()
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
846 (if (viper-overlay-live-p viper-minibuffer-overlay)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
847 (viper-move-overlay
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
848 viper-minibuffer-overlay
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
849 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
850 (1+ (buffer-size)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
851 (setq viper-minibuffer-overlay
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
852 (if (featurep 'xemacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
853 (viper-make-overlay 1 (1+ (buffer-size)) (current-buffer))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
854 ;; make overlay open-ended
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
855 (viper-make-overlay
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
856 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
857 (1+ (buffer-size))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
858 (current-buffer) nil 'rear-advance)))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
859
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
860
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
861 (defsubst viper-is-in-minibuffer ()
21940
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
862 (save-match-data
f7e788ea680b new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19462
diff changeset
863 (string-match "\*Minibuf-" (buffer-name))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
864
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
865
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
866
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
867 ;;; XEmacs compatibility
14581
4951b11970a1 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14384
diff changeset
868
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
869 (defun viper-abbreviate-file-name (file)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
870 (if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
871 (abbreviate-file-name file t) ; XEmacs requires addl argument
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
872 (abbreviate-file-name file)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
873
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
874 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
875 ;; in sit-for, so this function smoothes out the differences.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
876 (defsubst viper-sit-for-short (val &optional nodisp)
81331
c3779fe5830e 2007-06-12 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 75346
diff changeset
877 (sit-for (/ val 1000.0) nodisp))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
878
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
879 ;; EVENT may be a single event of a sequence of events
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
880 (defsubst viper-ESC-event-p (event)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
881 (let ((ESC-keys '(?\e (control \[) escape))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
882 (key (viper-event-key event)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
883 (member key ESC-keys)))
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
884
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
885 ;; checks if object is a marker, has a buffer, and points to within that buffer
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
886 (defun viper-valid-marker (marker)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
887 (if (and (markerp marker) (marker-buffer marker))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
888 (let ((buf (marker-buffer marker))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
889 (pos (marker-position marker)))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101721
diff changeset
890 (with-current-buffer buf
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
891 (and (<= pos (point-max)) (<= (point-min) pos))))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
892
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
893 (defsubst viper-mark-marker ()
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
894 (if (featurep 'xemacs) (mark-marker t)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
895 (mark-marker)))
14909
7ff1df13b124 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14588
diff changeset
896
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
897 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
898 ;; is the same as (mark t).
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
899 (defsubst viper-set-mark-if-necessary ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
900 (setq mark-ring (delete (viper-mark-marker) mark-ring))
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
901 (set-mark-command nil)
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
902 (setq viper-saved-mark (point)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
903
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
904 ;; In transient mark mode (zmacs mode), it is annoying when regions become
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
905 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
906 ;; the user explicitly wants highlighting, e.g., by hitting '' or ``
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
907 (defun viper-deactivate-mark ()
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
908 (if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
909 (zmacs-deactivate-region)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
910 (deactivate-mark)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
911
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
912 (defsubst viper-leave-region-active ()
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
913 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
12899
e0dfd3c3837e (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12693
diff changeset
914
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
915 ;; Check if arg is a valid character for register
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
916 ;; TYPE is a list that can contain `letter', `Letter', and `digit'.
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
917 ;; Letter means lowercase letters, Letter means uppercase letters, and
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
918 ;; digit means digits from 1 to 9.
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
919 ;; If TYPE is nil, then down/uppercase letters and digits are allowed.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
920 (defun viper-valid-register (reg &optional type)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
921 (or type (setq type '(letter Letter digit)))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
922 (or (if (memq 'letter type)
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
923 (and (<= ?a reg) (<= reg ?z)))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
924 (if (memq 'digit type)
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
925 (and (<= ?1 reg) (<= reg ?9)))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
926 (if (memq 'Letter type)
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
927 (and (<= ?A reg) (<= reg ?Z)))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
928 ))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
929
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
930
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
931
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
932 ;; it is suggested that an event must be copied before it is assigned to
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
933 ;; last-command-event in XEmacs
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
934 (defun viper-copy-event (event)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
935 (if (featurep 'xemacs) (copy-event event)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
936 event))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
937
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
938 ;; Uses different timeouts for ESC-sequences and others
99595
eb7532b56b78 2008-11-16 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 97142
diff changeset
939 (defun viper-fast-keysequence-p ()
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
940 (not (viper-sit-for-short
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
941 (if (viper-ESC-event-p last-input-event)
99595
eb7532b56b78 2008-11-16 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 97142
diff changeset
942 (viper-ESC-keyseq-timeout)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
943 viper-fast-keyseq-timeout)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
944 t)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
945
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
946 ;; like read-event, but in XEmacs also try to convert to char, if possible
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
947 (defun viper-read-event-convert-to-char ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
948 (let (event)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
949 (if (featurep 'xemacs)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
950 (progn
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
951 (setq event (next-command-event))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
952 (or (event-to-character event)
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
953 event))
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
954 (read-event))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
955
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
956 ;; Viperized read-key-sequence
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
957 (defun viper-read-key-sequence (prompt &optional continue-echo)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
958 (let (inhibit-quit event keyseq)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
959 (setq keyseq (read-key-sequence prompt continue-echo))
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
960 (setq event (if (featurep 'xemacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
961 (elt keyseq 0) ; XEmacs returns vector of events
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
962 (elt (listify-key-sequence keyseq) 0)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
963 (if (viper-ESC-event-p event)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
964 (let (unread-command-events)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
965 (if (viper-fast-keysequence-p)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
966 (let ((viper-vi-global-user-minor-mode nil)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
967 (viper-vi-local-user-minor-mode nil)
43220
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
968 (viper-vi-intercept-minor-mode nil)
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
969 (viper-insert-intercept-minor-mode nil)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
970 (viper-replace-minor-mode nil) ; actually unnecessary
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
971 (viper-insert-global-user-minor-mode nil)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
972 (viper-insert-local-user-minor-mode nil))
43220
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
973 ;; Note: set unread-command-events only after testing for fast
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
974 ;; keysequence. Otherwise, viper-fast-keysequence-p will be
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
975 ;; always t -- whether there is anything after ESC or not
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
976 (viper-set-unread-command-events keyseq)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
977 (setq keyseq (read-key-sequence nil)))
43220
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
978 (viper-set-unread-command-events keyseq)
69c91aaa067a 2002-02-10 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 42602
diff changeset
979 (setq keyseq (read-key-sequence nil)))))
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
980 keyseq))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
981
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
982
12693
321b2ad48a9c (vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12212
diff changeset
983 ;; This function lets function-key-map convert key sequences into logical
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
984 ;; keys. This does a better job than viper-read-event when it comes to kbd
15578
fadc581e380e (vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15480
diff changeset
985 ;; macros, since it enables certain macros to be shared between X and TTY modes
93615
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
986 ;; by correctly mapping key sequences for Left/Right/... (on an ascii
15578
fadc581e380e (vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15480
diff changeset
987 ;; terminal) into logical keys left, right, etc.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
988 (defun viper-read-key ()
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
989 (let ((overriding-local-map viper-overriding-map)
15578
fadc581e380e (vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15480
diff changeset
990 (inhibit-quit t)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
991 help-char key)
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
992 (use-global-map viper-overriding-map)
19203
58c50205001d new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19079
diff changeset
993 (unwind-protect
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
994 (setq key (elt (viper-read-key-sequence nil) 0))
19203
58c50205001d new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19079
diff changeset
995 (use-global-map global-map))
15578
fadc581e380e (vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 15480
diff changeset
996 key))
12693
321b2ad48a9c (vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12212
diff changeset
997
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
998
12139
e16c06646396 (vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents: 11288
diff changeset
999 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil)
14584
6674e3119d9e (vip-event-key): ignore consp events.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14581
diff changeset
1000 ;; instead of nil, if '(nil) was previously inadvertently assigned to
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1001 ;; unread-command-events
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1002 (defun viper-event-key (event)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1003 (or (and event (eventp event))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1004 (error "viper-event-key: Wrong type argument, eventp, %S" event))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
1005 (when (if (featurep 'xemacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1006 (or (key-press-event-p event) (mouse-event-p event)) ; xemacs
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1007 t ; emacs
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1008 )
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1009 (let ((mod (event-modifiers event))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1010 basis)
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1011 (setq basis
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
1012 (if (featurep 'xemacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1013 ;; XEmacs
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1014 (cond ((key-press-event-p event)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1015 (event-key event))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1016 ((button-event-p event)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1017 (concat "mouse-" (prin1-to-string (event-button event))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1018 (t
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1019 (error "viper-event-key: Unknown event, %S" event)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1020 ;; Emacs doesn't handle capital letters correctly, since
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1021 ;; \S-a isn't considered the same as A (it behaves as
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1022 ;; plain `a' instead). So we take care of this here
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1023 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1024 (setq mod nil
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1025 event event))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1026 ;; Emacs has the oddity whereby characters 128+char
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1027 ;; represent M-char *if* this appears inside a string.
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1028 ;; So, we convert them manually to (meta char).
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1029 ((and (viper-characterp event)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1030 (< ?\C-? event) (<= event 255))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1031 (setq mod '(meta)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1032 event (- event ?\C-? 1)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1033 ((and (null mod) (eq event 'return))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1034 (setq event ?\C-m))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1035 ((and (null mod) (eq event 'space))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1036 (setq event ?\ ))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1037 ((and (null mod) (eq event 'delete))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1038 (setq event ?\C-?))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1039 ((and (null mod) (eq event 'backspace))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1040 (setq event ?\C-h))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1041 (t (event-basic-type event)))
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
1042 ) ; (featurep 'xemacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1043 )
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1044 (if (viper-characterp basis)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1045 (setq basis
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1046 (if (viper= basis ?\C-?)
18047
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1047 (list 'control '\?) ; taking care of an emacs bug
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1048 (intern (char-to-string basis)))))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1049 (if mod
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1050 (append mod (list basis))
1b06411ccc04 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 16766
diff changeset
1051 basis))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1052
106192
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
1053 (defun viper-last-command-char ()
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
1054 (if (featurep 'xemacs)
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
1055 (event-to-character last-command-event)
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
1056 last-command-event))
a2ee981efbec 2009-11-22 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 105829
diff changeset
1057
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1058 (defun viper-key-to-emacs-key (key)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1059 (let (key-name char-p modifiers mod-char-list base-key base-key-name)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1060 (cond ((featurep 'xemacs) key)
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1061
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1062 ((symbolp key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1063 (setq key-name (symbol-name key))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1064 (cond ((= (length key-name) 1) ; character event
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1065 (string-to-char key-name))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1066 ;; Emacs doesn't recognize `return' and `escape' as events on
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1067 ;; dumb terminals, so we translate them into characters
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1068 ((and (featurep 'emacs) (not (viper-window-display-p))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1069 (string= key-name "return"))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1070 ?\C-m)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1071 ((and (featurep 'emacs) (not (viper-window-display-p))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1072 (string= key-name "escape"))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1073 ?\e)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1074 ;; pass symbol-event as is
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1075 (t key)))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
1076
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1077 ((listp key)
64215
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1078 (setq modifiers (viper-subseq key 0 (1- (length key)))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1079 base-key (viper-seq-last-elt key)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1080 base-key-name (symbol-name base-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1081 char-p (= (length base-key-name) 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1082 (setq mod-char-list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1083 (mapcar
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1084 '(lambda (elt) (upcase (substring (symbol-name elt) 0 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1085 modifiers))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1086 (if char-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1087 (setq key-name
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1088 (car (read-from-string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1089 (concat
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1090 "?\\"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1091 (mapconcat 'identity mod-char-list "-\\")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1092 "-"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1093 base-key-name))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1094 (setq key-name
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1095 (intern
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1096 (concat
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1097 (mapconcat 'identity mod-char-list "-")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1098 "-"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1099 base-key-name))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1100 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1101
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1102
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1103 ;; LIS is assumed to be a list of events of characters
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1104 (defun viper-eventify-list-xemacs (lis)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1105 (if (featurep 'xemacs)
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1106 (mapcar
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1107 (lambda (elt)
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1108 (cond ((viper-characterp elt) (character-to-event elt))
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1109 ((eventp elt) elt)
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1110 (t (error
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1111 "viper-eventify-list-xemacs: can't convert to event, %S"
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1112 elt))))
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1113 lis)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1114
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1115
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1116 ;; Smoothes out the difference between Emacs' unread-command-events
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1117 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1118 ;; events or a sequence of keys.
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1119 ;;
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1120 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1121 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1122 ;; into an event. Below, we delete nil from event lists, since nil is the most
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1123 ;; common symbol that might appear in this wrong context.
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1124 (defun viper-set-unread-command-events (arg)
85972
51aa47312c4b * ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 84908
diff changeset
1125 (if (featurep 'emacs)
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1126 (setq
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1127 unread-command-events
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1128 (let ((new-events
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1129 (cond ((eventp arg) (list arg))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1130 ((listp arg) arg)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1131 ((sequencep arg)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1132 (listify-key-sequence arg))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1133 (t (error
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1134 "viper-set-unread-command-events: Invalid argument, %S"
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1135 arg)))))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1136 (if (not (eventp nil))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1137 (setq new-events (delq nil new-events)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1138 (append new-events unread-command-events)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1139 ;; XEmacs
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1140 (setq
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1141 unread-command-events
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1142 (append
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1143 (cond ((viper-characterp arg) (list (character-to-event arg)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1144 ((eventp arg) (list arg))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1145 ((stringp arg) (mapcar 'character-to-event arg))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1146 ((vectorp arg) (append arg nil)) ; turn into list
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1147 ((listp arg) (viper-eventify-list-xemacs arg))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1148 (t (error
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1149 "viper-set-unread-command-events: Invalid argument, %S" arg)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1150 unread-command-events))))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1151
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1152
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1153 ;; Check if vec is a vector of key-press events representing characters
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1154 ;; XEmacs only
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1155 (defun viper-event-vector-p (vec)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1156 (and (vectorp vec)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1157 (eval (cons 'and (mapcar '(lambda (elt) (if (eventp elt) t)) vec)))))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1158
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1159
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1160 ;; check if vec is a vector of character symbols
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1161 (defun viper-char-symbol-sequence-p (vec)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1162 (and
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1163 (sequencep vec)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1164 (eval
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1165 (cons 'and
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1166 (mapcar (lambda (elt)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1167 (and (symbolp elt) (= (length (symbol-name elt)) 1)))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1168 vec)))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1169
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1170
42602
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1171 (defun viper-char-array-p (array)
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1172 (eval (cons 'and (mapcar 'viper-characterp array))))
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1173
633233bf2bbf 2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 39215
diff changeset
1174
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1175 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1176 ;; convert events to keys and, if all keys are regular printable
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
1177 ;; characters, will return a string. Otherwise, will return a string
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
1178 ;; representing a vector of converted events. If the input was a Viper macro,
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1179 ;; will return a string that represents this macro as a vector.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1180 (defun viper-array-to-string (event-seq)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1181 (let (temp temp2)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1182 (cond ((stringp event-seq) event-seq)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1183 ((viper-event-vector-p event-seq)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1184 (setq temp (mapcar 'viper-event-key event-seq))
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1185 (cond ((viper-char-symbol-sequence-p temp)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1186 (mapconcat 'symbol-name temp ""))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1187 ((and (viper-char-array-p
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1188 (setq temp2 (mapcar 'viper-key-to-character temp))))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1189 (mapconcat 'char-to-string temp2 ""))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1190 (t (prin1-to-string (vconcat temp)))))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1191 ((viper-char-symbol-sequence-p event-seq)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1192 (mapconcat 'symbol-name event-seq ""))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1193 ((and (vectorp event-seq)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1194 (viper-char-array-p
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1195 (setq temp (mapcar 'viper-key-to-character event-seq))))
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1196 (mapconcat 'char-to-string temp ""))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197 (t (prin1-to-string event-seq)))))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1198
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1199 (defun viper-key-press-events-to-chars (events)
92380
8ee8aa679c74 (zmacs-region-stays): No need to define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 87691
diff changeset
1200 (mapconcat (if (featurep 'xemacs)
93615
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
1201 (lambda (elt) (char-to-string (event-to-character elt))) ; xemacs
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
1202 'char-to-string ; emacs
34417c118a39 2008-04-03 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 92766
diff changeset
1203 )
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1204 events
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1205 ""))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1206
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1207
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1208 (defun viper-read-char-exclusive ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1209 (let (char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1210 (echo-keystrokes 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1211 (while (null char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1212 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1213 (setq char (read-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1214 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215 ;; skip event if not char
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1216 (viper-read-event))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1217 char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1218
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1219 ;; key is supposed to be in viper's representation, e.g., (control l), a
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1220 ;; character, etc.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1221 (defun viper-key-to-character (key)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1222 (cond ((eq key 'space) ?\ )
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1223 ((eq key 'delete) ?\C-?)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1224 ((eq key 'return) ?\C-m)
15480
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1225 ((eq key 'backspace) ?\C-h)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1226 ((and (symbolp key)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1227 (= 1 (length (symbol-name key))))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1228 (string-to-char (symbol-name key)))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1229 ((and (listp key)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1230 (eq (car key) 'control)
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1231 (symbol-name (nth 1 key))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1232 (= 1 (length (symbol-name (nth 1 key)))))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1233 (read (format "?\\C-%s" (symbol-name (nth 1 key)))))
43a3308fcf61 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 14909
diff changeset
1234 (t key)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1235
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1236
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1237 (defun viper-setup-master-buffer (&rest other-files-or-buffers)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1238 "Set up the current buffer as a master buffer.
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
1239 Arguments become related buffers. This function should normally be used in
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1240 the `Local variables' section of a file."
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1241 (setq viper-related-files-and-buffers-ring
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242 (make-ring (1+ (length other-files-or-buffers))))
84908
862e65546389 (viper-setup-master-buffer): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82140
diff changeset
1243 (mapc '(lambda (elt)
862e65546389 (viper-setup-master-buffer): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82140
diff changeset
1244 (viper-ring-insert viper-related-files-and-buffers-ring elt))
862e65546389 (viper-setup-master-buffer): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82140
diff changeset
1245 other-files-or-buffers)
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1246 (viper-ring-insert viper-related-files-and-buffers-ring (buffer-name))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1247 )
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1248
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1249 ;;; Movement utilities
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1250
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1251 ;; Characters that should not be considered as part of the word, in reformed-vi
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1252 ;; syntax mode.
66893
7c76da84383b 2005-11-15 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 65627
diff changeset
1253 ;; Note: \\ (quoted \) must appear before `-' because this string is listified
7c76da84383b 2005-11-15 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 65627
diff changeset
1254 ;; into characters at some point and then put back to string. The result is
7c76da84383b 2005-11-15 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 65627
diff changeset
1255 ;; used in skip-chars-forward, which treats - specially. Here we achieve the
7c76da84383b 2005-11-15 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 65627
diff changeset
1256 ;; effect of quoting - and preventing it from being special.
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1257 (defconst viper-non-word-characters-reformed-vi
66893
7c76da84383b 2005-11-15 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 65627
diff changeset
1258 "!@#$%^&*()\\-+=|\\~`{}[];:'\",<.>/?")
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1259 ;; These are characters that are not to be considered as parts of a word in
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1260 ;; Viper.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1261 ;; Set each time state changes and at loading time
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1262 (viper-deflocalvar viper-non-word-characters nil)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1263
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1264 ;; must be buffer-local
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1265 (viper-deflocalvar viper-ALPHA-char-class "w"
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1266 "String of syntax classes characterizing Viper's alphanumeric symbols.
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1267 In addition, the symbol `_' may be considered alphanumeric if
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1268 `viper-syntax-preference' is `strict-vi' or `reformed-vi'.")
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1269
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1270 (defconst viper-strict-ALPHA-chars "a-zA-Z0-9_"
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1271 "Regexp matching the set of alphanumeric characters acceptable to strict
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1272 Vi.")
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1273 (defconst viper-strict-SEP-chars " \t\n"
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1274 "Regexp matching the set of alphanumeric characters acceptable to strict
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1275 Vi.")
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1276 (defconst viper-strict-SEP-chars-sans-newline " \t"
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1277 "Regexp matching the set of alphanumeric characters acceptable to strict
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1278 Vi.")
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1279
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1280 (defconst viper-SEP-char-class " -"
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1281 "String of syntax classes for Vi separators.
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1282 Usually contains ` ', linefeed, TAB or formfeed.")
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1283
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1284
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1285 ;; Set Viper syntax classes and related variables according to
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1286 ;; `viper-syntax-preference'.
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1287 (defun viper-update-syntax-classes (&optional set-default)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1288 (let ((preference (cond ((eq viper-syntax-preference 'emacs)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1289 "w") ; Viper words have only Emacs word chars
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1290 ((eq viper-syntax-preference 'extended)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1291 "w_") ; Viper words have Emacs word & symbol chars
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1292 (t "w"))) ; Viper words are Emacs words plus `_'
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1293 (non-word-chars (cond ((eq viper-syntax-preference 'reformed-vi)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1294 (viper-string-to-list
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1295 viper-non-word-characters-reformed-vi))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1296 (t nil))))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1297 (if set-default
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1298 (setq-default viper-ALPHA-char-class preference
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1299 viper-non-word-characters non-word-chars)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1300 (setq viper-ALPHA-char-class preference
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1301 viper-non-word-characters non-word-chars))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1302 ))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1303
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1304 ;; SYMBOL is used because customize requires it, but it is ignored, unless it
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
1305 ;; is `nil'. If nil, use setq.
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1306 (defun viper-set-syntax-preference (&optional symbol value)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1307 "Set Viper syntax preference.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1308 If called interactively or if SYMBOL is nil, sets syntax preference in current
26263
4f315ca65976 *** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 22284
diff changeset
1309 buffer. If called non-interactively, preferably via the customization widget,
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1310 sets the default value."
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1311 (interactive)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1312 (or value
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1313 (setq value
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1314 (completing-read
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1315 "Viper syntax preference: "
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1316 '(("strict-vi") ("reformed-vi") ("extended") ("emacs"))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1317 nil 'require-match)))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1318 (if (stringp value) (setq value (intern value)))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1319 (or (memq value '(strict-vi reformed-vi extended emacs))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1320 (error "Invalid Viper syntax preference, %S" value))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1321 (if symbol
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1322 (setq-default viper-syntax-preference value)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1323 (setq viper-syntax-preference value))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1324 (viper-update-syntax-classes))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1325
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1326 (defcustom viper-syntax-preference 'reformed-vi
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1327 "*Syntax type characterizing Viper's alphanumeric symbols.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1328 Affects movement and change commands that deal with Vi-style words.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1329 Works best when set in the hooks to various major modes.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1330
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1331 `strict-vi' means Viper words are (hopefully) exactly as in Vi.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1332
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1333 `reformed-vi' means Viper words are like Emacs words \(as determined using
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1334 Emacs syntax tables, which are different for different major modes\) with two
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1335 exceptions: the symbol `_' is always part of a word and typical Vi non-word
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1336 symbols, such as `,',:,\",),{, etc., are excluded.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1337 This behaves very close to `strict-vi', but also works well with non-ASCII
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1338 characters from various alphabets.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1339
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1340 `extended' means Viper word constituents are symbols that are marked as being
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1341 parts of words OR symbols in Emacs syntax tables.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1342 This is most appropriate for major modes intended for editing programs.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1343
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1344 `emacs' means Viper words are the same as Emacs words as specified by Emacs
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1345 syntax tables.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1346 This option is appropriate if you like Emacs-style words."
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1347 :type '(radio (const strict-vi) (const reformed-vi)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1348 (const extended) (const emacs))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1349 :set 'viper-set-syntax-preference
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1350 :group 'viper)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1351 (make-variable-buffer-local 'viper-syntax-preference)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1352
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1353
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1354 ;; addl-chars are characters to be temporarily considered as alphanumerical
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1355 (defun viper-looking-at-alpha (&optional addl-chars)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1356 (or (stringp addl-chars) (setq addl-chars ""))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1357 (if (eq viper-syntax-preference 'reformed-vi)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1358 (setq addl-chars (concat addl-chars "_")))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1359 (let ((char (char-after (point))))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1360 (if char
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1361 (if (eq viper-syntax-preference 'strict-vi)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1362 (looking-at (concat "[" viper-strict-ALPHA-chars addl-chars "]"))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1363 (or
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1364 ;; or one of the additional chars being asked to include
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1365 (viper-memq-char char (viper-string-to-list addl-chars))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1366 (and
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1367 ;; not one of the excluded word chars (note:
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1368 ;; viper-non-word-characters is a list)
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1369 (not (viper-memq-char char viper-non-word-characters))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1370 ;; char of the Viper-word syntax class
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1371 (viper-memq-char (char-syntax char)
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1372 (viper-string-to-list viper-ALPHA-char-class))))))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1373 ))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1374
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1375 (defun viper-looking-at-separator ()
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1376 (let ((char (char-after (point))))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1377 (if char
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1378 (if (eq viper-syntax-preference 'strict-vi)
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1379 (viper-memq-char char (viper-string-to-list viper-strict-SEP-chars))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1380 (or (eq char ?\n) ; RET is always a separator in Vi
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1381 (viper-memq-char (char-syntax char)
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1382 (viper-string-to-list viper-SEP-char-class)))))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1383 ))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1384
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1385 (defsubst viper-looking-at-alphasep (&optional addl-chars)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1386 (or (viper-looking-at-separator) (viper-looking-at-alpha addl-chars)))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1387
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1388 (defun viper-skip-alpha-forward (&optional addl-chars)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1389 (or (stringp addl-chars) (setq addl-chars ""))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1390 (viper-skip-syntax
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1391 'forward
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1392 (cond ((eq viper-syntax-preference 'strict-vi)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1393 "")
19241
eb1cef5fa337 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19203
diff changeset
1394 (t viper-ALPHA-char-class))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1395 (cond ((eq viper-syntax-preference 'strict-vi)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1396 (concat viper-strict-ALPHA-chars addl-chars))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1397 (t addl-chars))))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1398
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1399 (defun viper-skip-alpha-backward (&optional addl-chars)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1400 (or (stringp addl-chars) (setq addl-chars ""))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1401 (viper-skip-syntax
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1402 'backward
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1403 (cond ((eq viper-syntax-preference 'strict-vi)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1404 "")
19241
eb1cef5fa337 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19203
diff changeset
1405 (t viper-ALPHA-char-class))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1406 (cond ((eq viper-syntax-preference 'strict-vi)
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1407 (concat viper-strict-ALPHA-chars addl-chars))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1408 (t addl-chars))))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1409
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1410 ;; weird syntax tables may confuse strict-vi style
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1411 (defsubst viper-skip-all-separators-forward (&optional within-line)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1412 (if (eq viper-syntax-preference 'strict-vi)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1413 (if within-line
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1414 (skip-chars-forward viper-strict-SEP-chars-sans-newline)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1415 (skip-chars-forward viper-strict-SEP-chars))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1416 (viper-skip-syntax 'forward
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1417 viper-SEP-char-class
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1418 (or within-line "\n")
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1419 (if within-line (viper-line-pos 'end)))))
65627
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1420
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1421 (defsubst viper-skip-all-separators-backward (&optional within-line)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1422 (if (eq viper-syntax-preference 'strict-vi)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1423 (if within-line
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1424 (skip-chars-backward viper-strict-SEP-chars-sans-newline)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1425 (skip-chars-backward viper-strict-SEP-chars))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1426 (viper-skip-syntax 'backward
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1427 viper-SEP-char-class
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1428 (or within-line "\n")
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1429 (if within-line (viper-line-pos 'start)))))
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1430 (defun viper-skip-nonseparators (direction)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1431 (viper-skip-syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1432 direction
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1433 (concat "^" viper-SEP-char-class)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1434 nil
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1435 (viper-line-pos (if (eq direction 'forward) 'end 'start))))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1436
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1437
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1438 ;; skip over non-word constituents and non-separators
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1439 (defun viper-skip-nonalphasep-forward ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1440 (if (eq viper-syntax-preference 'strict-vi)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1441 (skip-chars-forward
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1442 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1443 (viper-skip-syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1444 'forward
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1445 (concat "^" viper-ALPHA-char-class viper-SEP-char-class)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1446 ;; Emacs may consider some of these as words, but we don't want them
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1447 viper-non-word-characters
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1448 (viper-line-pos 'end))))
65627
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1449
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1450 (defun viper-skip-nonalphasep-backward ()
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1451 (if (eq viper-syntax-preference 'strict-vi)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1452 (skip-chars-backward
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1453 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1454 (viper-skip-syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1455 'backward
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1456 (concat "^" viper-ALPHA-char-class viper-SEP-char-class)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1457 ;; Emacs may consider some of these as words, but we don't want them
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1458 viper-non-word-characters
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1459 (viper-line-pos 'start))))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1460
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1461 ;; Skip SYNTAX like skip-syntax-* and ADDL-CHARS like skip-chars-*
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1462 ;; Return the number of chars traveled.
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1463 ;; Both SYNTAX or ADDL-CHARS can be strings or lists of characters.
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1464 ;; When SYNTAX is "w", then viper-non-word-characters are not considered to be
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1465 ;; words, even if Emacs syntax table says they are.
19079
dfbef8117c6a new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
1466 (defun viper-skip-syntax (direction syntax addl-chars &optional limit)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1467 (let ((total 0)
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1468 (local 1)
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1469 (skip-chars-func
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1470 (if (eq direction 'forward)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1471 'skip-chars-forward 'skip-chars-backward))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1472 (skip-syntax-func
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1473 (if (eq direction 'forward)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1474 'viper-forward-char-carefully 'viper-backward-char-carefully))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1475 char-looked-at syntax-of-char-looked-at negated-syntax)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1476 (setq addl-chars
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1477 (cond ((listp addl-chars) (viper-charlist-to-string addl-chars))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1478 ((stringp addl-chars) addl-chars)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1479 (t "")))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1480 (setq syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1481 (cond ((listp syntax) syntax)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1482 ((stringp syntax) (viper-string-to-list syntax))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1483 (t nil)))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1484 (if (memq ?^ syntax) (setq negated-syntax t))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1485
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1486 (while (and (not (= local 0))
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1487 (cond ((eq direction 'forward)
22284
7c92be9aea04 (viper-skip-syntax): Bug fix for eob/bob cases.
Karl Heuer <kwzh@gnu.org>
parents: 21940
diff changeset
1488 (not (eobp)))
7c92be9aea04 (viper-skip-syntax): Bug fix for eob/bob cases.
Karl Heuer <kwzh@gnu.org>
parents: 21940
diff changeset
1489 (t (not (bobp)))))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1490 (setq char-looked-at (viper-char-at-pos direction)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1491 ;; if outside the range, set to nil
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1492 syntax-of-char-looked-at (if char-looked-at
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1493 (char-syntax char-looked-at)))
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1494 (setq local
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1495 (+ (if (and
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1496 (cond ((and limit (eq direction 'forward))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1497 (< (point) limit))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1498 (limit ; backward & limit
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1499 (> (point) limit))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1500 (t t)) ; no limit
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1501 ;; char under/before cursor has appropriate syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1502 (if negated-syntax
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1503 (not (memq syntax-of-char-looked-at syntax))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1504 (memq syntax-of-char-looked-at syntax))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1505 ;; if char-syntax class is "word", make sure it is not one
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1506 ;; of the excluded characters
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1507 (if (and (eq syntax-of-char-looked-at ?w)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1508 (not negated-syntax))
33019
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1509 (not (viper-memq-char
6306740f6938 2000-10-29 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 28510
diff changeset
1510 char-looked-at viper-non-word-characters))
19462
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1511 t))
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1512 (funcall skip-syntax-func 1)
a3240ad2e954 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 19241
diff changeset
1513 0)
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1514 (funcall skip-chars-func addl-chars limit)))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1515 (setq total (+ total local)))
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1516 total
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1517 ))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1518
65627
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1519 ;; tells when point is at the beginning of field
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1520 (defun viper-beginning-of-field ()
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1521 (or (bobp)
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1522 (not (eq (get-char-property (point) 'field)
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1523 (get-char-property (1- (point)) 'field)))))
511f8e9d22ca 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64750
diff changeset
1524
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47520
diff changeset
1525
64215
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1526 ;; this is copied from cl-extra.el
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1527 ;; Return the subsequence of SEQ from START to END.
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1528 ;; If END is omitted, it defaults to the length of the sequence.
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1529 ;; If START or END is negative, it counts from the end.
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1530 (defun viper-subseq (seq start &optional end)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1531 (if (stringp seq) (substring seq start end)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1532 (let (len)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1533 (and end (< end 0) (setq end (+ end (setq len (length seq)))))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1534 (if (< start 0) (setq start (+ start (or len (setq len (length seq))))))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1535 (cond ((listp seq)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1536 (if (> start 0) (setq seq (nthcdr start seq)))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1537 (if end
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1538 (let ((res nil))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1539 (while (>= (setq end (1- end)) start)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1540 (push (pop seq) res))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1541 (nreverse res))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1542 (copy-sequence seq)))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1543 (t
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1544 (or end (setq end (or len (length seq))))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1545 (let ((res (make-vector (max (- end start) 0) nil))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1546 (i 0))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1547 (while (< start end)
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1548 (aset res i (aref seq start))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1549 (setq i (1+ i) start (1+ start)))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1550 res))))))
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1551
a4c59075cac8 * viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 64085
diff changeset
1552
13213
68b3f6d9156f (vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12899
diff changeset
1553
101721
c55394eee0de Follow commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
1554 ;; Local Variables:
c55394eee0de Follow commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
1555 ;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
c55394eee0de Follow commenting conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
1556 ;; End:
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1557
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93652
diff changeset
1558 ;; arch-tag: 7f023fd5-dd9e-4378-a397-9c179553b0e3
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36857
diff changeset
1559 ;;; viper-util.el ends here