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