4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: ex_map.c,v 10.11 2001/06/25 15:19:17 skimo Exp (Berkeley) Date: 2001/06/25 15:19:17";
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <bitstring.h>
28 #include "../common/common.h"
31 * ex_map -- :map[!] [input] [replacement]
32 * Map a key/string or display mapped keys.
35 * Historic vi maps were fairly bizarre, and likely to differ in
36 * very subtle and strange ways from this implementation. Two
37 * things worth noting are that vi would often hang or drop core
38 * if the map was strange enough (ex: map X "xy$@x^V), or, simply
39 * not work. One trick worth remembering is that if you put a
40 * mark at the start of the map, e.g. map X mx"xy ...), or if you
41 * put the map in a .exrc file, things would often work much better.
44 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
47 ex_map(SCR
*sp
, EXCMD
*cmdp
)
52 stype
= FL_ISSET(cmdp
->iflags
, E_C_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
;
56 if (seq_dump(sp
, stype
, 1) == 0)
57 msgq(sp
, M_INFO
, stype
== SEQ_INPUT
?
58 "132|No input map entries" :
59 "133|No command map entries");
62 input
= cmdp
->argv
[0]->bp
;
69 * If the mapped string is #[0-9]* (and wasn't quoted) then store the
70 * function key mapping. If the screen specific routine has been set,
71 * call it as well. Note, the SEQ_FUNCMAP type is persistent across
72 * screen types, maybe the next screen type will get it right.
74 if (input
[0] == '#' && isdigit(input
[1])) {
75 for (p
= input
+ 2; isdigit(*p
); ++p
);
79 if (seq_set(sp
, NULL
, 0, input
, cmdp
->argv
[0]->len
,
80 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, stype
,
81 SEQ_FUNCMAP
| SEQ_USERDEF
))
83 return (sp
->gp
->scr_fmap
== NULL
? 0 :
84 sp
->gp
->scr_fmap(sp
, stype
, input
, cmdp
->argv
[0]->len
,
85 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
));
88 /* Some single keys may not be remapped in command mode. */
89 nofunc
: if (stype
== SEQ_COMMAND
&& input
[1] == '\0')
90 switch (KEY_VAL(sp
, input
[0])) {
95 "134|The %s character may not be remapped",
96 KEY_NAME(sp
, input
[0]));
99 return (seq_set(sp
, NULL
, 0, input
, cmdp
->argv
[0]->len
,
100 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, stype
, SEQ_USERDEF
));
104 * ex_unmap -- (:unmap[!] key)
107 * PUBLIC: int ex_unmap __P((SCR *, EXCMD *));
110 ex_unmap(SCR
*sp
, EXCMD
*cmdp
)
112 if (seq_delete(sp
, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
,
113 FL_ISSET(cmdp
->iflags
, E_C_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
)) {
114 msgq_wstr(sp
, M_INFO
,
115 cmdp
->argv
[0]->bp
, "135|\"%s\" isn't currently mapped");