summaryrefslogtreecommitdiff
path: root/usr.bin/vim/misccmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/vim/misccmds.c')
-rw-r--r--usr.bin/vim/misccmds.c85
1 files changed, 70 insertions, 15 deletions
diff --git a/usr.bin/vim/misccmds.c b/usr.bin/vim/misccmds.c
index ff08529ab07..01e2c5dae5e 100644
--- a/usr.bin/vim/misccmds.c
+++ b/usr.bin/vim/misccmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misccmds.c,v 1.1 1996/09/07 21:40:25 downsj Exp $ */
+/* $OpenBSD: misccmds.c,v 1.2 1996/09/21 06:23:10 downsj Exp $ */
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
@@ -1390,7 +1390,7 @@ set_Changed()
{
if (!curbuf->b_changed)
{
- change_warning();
+ change_warning(0);
curbuf->b_changed = TRUE;
check_status(curbuf);
}
@@ -1441,7 +1441,9 @@ check_status(buf)
* will be TRUE.
*/
void
-change_warning()
+change_warning(col)
+ int col; /* column for message; non-zero when in insert
+ mode and 'showmode' is on */
{
if (curbuf->b_did_warn == FALSE && curbuf->b_changed == 0 &&
#ifdef AUTOCMD
@@ -1449,9 +1451,16 @@ change_warning()
#endif
curbuf->b_p_ro)
{
- curbuf->b_did_warn = TRUE;
- MSG("Warning: Changing a readonly file");
+ /*
+ * Do what msg() does, but with a column offset.
+ */
+ msg_start();
+ msg_col = col;
+ MSG_OUTSTR("Warning: Changing a readonly file");
+ msg_clr_eos();
+ (void)msg_end();
mch_delay(1000L, TRUE); /* give him some time to think about it */
+ curbuf->b_did_warn = TRUE;
}
}
@@ -1800,8 +1809,8 @@ expand_env(src, dst, dstlen)
}
/*
- * Replace home directory by "~/" in each space or comma separated filename in
- * 'src'. If anything fails (except when out of space) dst equals src.
+ * Replace home directory by "~" in each space or comma separated filename in
+ * 'src'. If anything fails (except when out of space) dst equals src.
*/
void
home_replace(buf, src, dst, dstlen)
@@ -1862,8 +1871,9 @@ home_replace(buf, src, dst, dstlen)
src += len;
if (--dstlen > 0)
*dst++ = '~';
+
/*
- * If it's just the home directory, make it "~/".
+ * If it's just the home directory, add "/".
*/
if (!ispathsep(src[0]) && --dstlen > 0)
*dst++ = '/';
@@ -1898,10 +1908,9 @@ home_replace_save(buf, src)
char_u *dst;
unsigned len;
- if (src == NULL) /* just in case */
- len = 3;
- else
- len = STRLEN(src) + 3; /* extra space for "~/" and trailing NUL */
+ len = 3; /* space for "~/" and trailing NUL */
+ if (src != NULL) /* just in case */
+ len += STRLEN(src);
dst = alloc(len);
if (dst != NULL)
home_replace(buf, src, dst, len);
@@ -1984,6 +1993,40 @@ gettail(fname)
}
/*
+ * Get a pointer to one character past the head of a path name.
+ * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/".
+ * If there is no head, path is returned.
+ */
+ char_u *
+get_past_head(path)
+ char_u *path;
+{
+ char_u *retval;
+
+#if defined(MSDOS) || defined(WIN32) || defined(OS2)
+ /* may skip "c:" */
+ if (isalpha(path[0]) && path[1] == ':')
+ retval = path + 2;
+ else
+ retval = path;
+#else
+# if defined(AMIGA)
+ /* may skip "label:" */
+ retval = vim_strchr(path, ':');
+ if (retval == NULL)
+ retval = path;
+# else /* Unix */
+ retval = path;
+# endif
+#endif
+
+ while (ispathsep(*retval))
+ ++retval;
+
+ return retval;
+}
+
+/*
* return TRUE if 'c' is a path separator.
*/
int
@@ -2307,6 +2350,7 @@ commentorempty(s)
/*
* Recognize a line that starts with '{' or '}', or ends with ';' or '}'.
+ * Don't consider "} else" a terminated line.
* Also consider a line terminated if it ends in ','. This is not 100%
* correct, but this mostly means we are in initializations and then it's OK.
*/
@@ -2316,7 +2360,7 @@ isterminated(s)
{
s = skipwhite(s);
- if (*s == '{' || *s == '}')
+ if (*s == '{' || (*s == '}' && !iselse(s)))
return TRUE;
while (*s)
@@ -2416,6 +2460,8 @@ isif(p)
iselse(p)
char_u *p;
{
+ if (*p == '}') /* accept "} else" */
+ p = skipwhite(p + 1);
return (STRNCMP(p, "else", 4) == 0 && !isidchar(p[4]));
}
@@ -2442,11 +2488,19 @@ iswhileofdo(p, lnum, ind_maxparen) /* XXX */
int retval = FALSE;
p = skipwhite(p);
+ if (*p == '}') /* accept "} while (cond);" */
+ p = skipwhite(p + 1);
if (STRNCMP(p, "while", 5) == 0 && !isidchar(p[5]))
{
cursor_save = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = 0;
+ p = ml_get_curline();
+ while (*p && *p != 'w') /* skip any '}', until the 'w' of the "while" */
+ {
+ ++p;
+ ++curwin->w_cursor.col;
+ }
if ((trypos = findmatchlimit(0, 0, ind_maxparen)) != NULL)
{
p = ml_get_pos(trypos) + 1;
@@ -3254,8 +3308,9 @@ get_c_indent()
/*
* Check if we are after an "if", "while", etc.
+ * Also allow "} else".
*/
- if (is_cinword(l))
+ if (is_cinword(l) || iselse(l))
{
/*
* Found an unterminated line after an if (), line up
@@ -3349,7 +3404,7 @@ get_c_indent()
/*
* Check if we are after a while (cond);
- * If so: Ignore the matching "do".
+ * If so: Ignore until the matching "do".
*/
/* XXX */
else if (iswhileofdo(l, curwin->w_cursor.lnum, ind_maxparen))