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_abbrev.c,v 10.10 2001/12/16 18:18:54 skimo Exp (Berkeley) Date: 2001/12/16 18:18:54";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
29 #include "../common/common.h"
33 * ex_abbr -- :abbreviate [key replacement]
34 * Create an abbreviation or display abbreviations.
36 * PUBLIC: int ex_abbr __P((SCR *, EXCMD *));
39 ex_abbr(SCR
*sp
, EXCMD
*cmdp
)
46 if (seq_dump(sp
, SEQ_ABBREV
, 0) == 0)
47 msgq(sp
, M_INFO
, "105|No abbreviations to display");
56 * Check for illegal characters.
59 * Another fun one, historically. See vi/v_ntext.c:txt_abbrev() for
60 * details. The bottom line is that all abbreviations have to end
61 * with a "word" character, because it's the transition from word to
62 * non-word characters that triggers the test for an abbreviation. In
63 * addition, because of the way the test is done, there can't be any
64 * transitions from word to non-word character (or vice-versa) other
65 * than between the next-to-last and last characters of the string,
66 * and there can't be any <blank> characters. Warn the user.
68 if (!inword(cmdp
->argv
[0]->bp
[cmdp
->argv
[0]->len
- 1])) {
70 "106|Abbreviations must end with a \"word\" character");
73 for (p
= cmdp
->argv
[0]->bp
; *p
!= '\0'; ++p
)
76 "107|Abbreviations may not contain tabs or spaces");
79 if (cmdp
->argv
[0]->len
> 2)
80 for (p
= cmdp
->argv
[0]->bp
,
81 len
= cmdp
->argv
[0]->len
- 2; len
; --len
, ++p
)
82 if (inword(p
[0]) != inword(p
[1])) {
84 "108|Abbreviations may not mix word/non-word characters, except at the end");
88 if (seq_set(sp
, NULL
, 0, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
,
89 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, SEQ_ABBREV
, SEQ_USERDEF
))
92 F_SET(sp
->gp
, G_ABBREV
);
97 * ex_unabbr -- :unabbreviate key
98 * Delete an abbreviation.
100 * PUBLIC: int ex_unabbr __P((SCR *, EXCMD *));
103 ex_unabbr(SCR
*sp
, EXCMD
*cmdp
)
108 if (!F_ISSET(sp
->gp
, G_ABBREV
) ||
109 seq_delete(sp
, ap
->bp
, ap
->len
, SEQ_ABBREV
)) {
110 msgq_wstr(sp
, M_ERR
, ap
->bp
,
111 "109|\"%s\" is not an abbreviation");