diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2009-06-04 23:39:38 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2009-06-04 23:39:38 +0000 |
commit | 6260330c332daf1197d0218472e43fd2e7750645 (patch) | |
tree | 9f4420a7b6a336fb6c5a8a2d33b2954ad42f9e1d /usr.bin/mg | |
parent | a513404baf363e211790bd230dd8448444415fbb (diff) |
Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)
This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.
ok maja@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/buffer.c | 36 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 16 | ||||
-rw-r--r-- | usr.bin/mg/dired.c | 8 | ||||
-rw-r--r-- | usr.bin/mg/echo.c | 14 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/grep.c | 12 | ||||
-rw-r--r-- | usr.bin/mg/help.c | 6 | ||||
-rw-r--r-- | usr.bin/mg/theo.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/undo.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/window.c | 29 |
10 files changed, 71 insertions, 62 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index ca832768091..f72af3281af 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.70 2009/06/04 02:23:37 kjell Exp $ */ +/* $OpenBSD: buffer.c,v 1.71 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -98,8 +98,8 @@ poptobuffer(int f, int n) return (FALSE); if (bp == curbp) return (splitwind(f, n)); - /* and put it in a new window */ - if ((wp = popbuf(bp)) == NULL) + /* and put it in a new, non-ephemeral window */ + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; @@ -263,7 +263,7 @@ listbuffers(int f, int n) initialized = 1; } - if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL) + if ((bp = makelist()) == NULL || (wp = popbuf(bp, WNONE)) == NULL) return (FALSE); wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */ wp->w_doto = bp->b_doto; @@ -379,7 +379,7 @@ listbuf_goto_buffer_helper(int f, int n, int only) if (bp == NULL) goto cleanup; - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) goto cleanup; curbp = bp; curwp = wp; @@ -661,13 +661,29 @@ augbname(char *bn, const char *fn, size_t bs) * Returns a status. */ struct mgwin * -popbuf(struct buffer *bp) +popbuf(struct buffer *bp, int flags) { struct mgwin *wp; if (bp->b_nwnd == 0) { /* Not on screen yet. */ - if ((wp = wpopup()) == NULL) - return (NULL); + /* + * Pick a window for a pop-up. + * If only one window, split the screen. + * Flag the new window as ephemeral + */ + if (wheadp->w_wndp == NULL && + splitwind(FFOTHARG, flags) == FALSE) + return (NULL); + + /* + * Pick the uppermost window that isn't + * the current window. An LRU algorithm + * might be better. Return a pointer, or NULL on error. + */ + wp = wheadp; + + while (wp != NULL && wp == curwp) + wp = wp->w_wndp; } else for (wp = wheadp; wp != NULL; wp = wp->w_wndp) if (wp->w_bufp == bp) { @@ -762,7 +778,7 @@ notmodified(int f, int n) * help functions. */ int -popbuftop(struct buffer *bp) +popbuftop(struct buffer *bp, int flags) { struct mgwin *wp; @@ -776,7 +792,7 @@ popbuftop(struct buffer *bp) wp->w_rflag |= WFFULL; } } - return (popbuf(bp) != NULL); + return (popbuf(bp, flags) != NULL); } #endif diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 2de0ef407c7..e7b79b87a95 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.110 2009/06/04 23:31:47 kjell Exp $ */ +/* $OpenBSD: def.h,v 1.111 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -202,7 +202,8 @@ struct mgwin { char w_toprow; /* Origin 0 top row of window */ char w_ntrows; /* # of rows of text in window */ char w_frame; /* #lines to reframe by. */ - char w_rflag; /* Redisplay Flags. */ + char w_rflag; /* Redisplay Flags. */ + char w_flag; /* Flags. */ struct line *w_wrapline; int w_dotline; /* current line number of dot */ int w_markline; /* current line number of mark */ @@ -225,6 +226,12 @@ struct mgwin { #define WFFULL 0x08 /* Do a full display. */ #define WFMODE 0x10 /* Update mode line. */ +/* + * Window flags + */ +#define WNONE 0x00 /* No special window options. */ +#define WEPHEM 0x01 /* Window is ephemeral. */ + struct undo_rec; /* @@ -384,7 +391,6 @@ int splitwind(int, int); int enlargewind(int, int); int shrinkwind(int, int); int delwind(int, int); -struct mgwin *wpopup(void); /* buffer.c */ int togglereadonly(int, int); @@ -400,11 +406,11 @@ int anycb(int); int bclear(struct buffer *); int showbuffer(struct buffer *, struct mgwin *, int); int augbname(char *, const char *, size_t); -struct mgwin *popbuf(struct buffer *); +struct mgwin *popbuf(struct buffer *, int); int bufferinsert(int, int); int usebuffer(int, int); int notmodified(int, int); -int popbuftop(struct buffer *); +int popbuftop(struct buffer *, int); int getbufcwd(char *, size_t); int checkdirty(struct buffer *); diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 7a758fbaf57..b5eeaff1081 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.44 2009/06/04 02:23:37 kjell Exp $ */ +/* $OpenBSD: dired.c,v 1.45 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -225,7 +225,7 @@ d_otherwindow(int f, int n) return (FALSE); if ((bp = dired_(bufp)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; @@ -320,7 +320,7 @@ d_ffotherwindow(int f, int n) return (FALSE); if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; @@ -519,7 +519,7 @@ d_shell_command(int f, int n) close(fds[0]); break; } - wp = popbuf(bp); + wp = popbuf(bp, WNONE); if (wp == NULL) return (ABORT); /* XXX - free the buffer?? */ curwp = wp; diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c index c3df2366c6f..deba7a576df 100644 --- a/usr.bin/mg/echo.c +++ b/usr.bin/mg/echo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: echo.c,v 1.48 2009/06/03 20:58:20 kjell Exp $ */ +/* $OpenBSD: echo.c,v 1.49 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -472,9 +472,13 @@ done: if (cwin == TRUE) { /* blow away cpltion window */ bp = bfind("*Completions*", TRUE); - if ((wp = popbuf(bp)) != NULL) { - curwp = wp; - delwind(FFRAND, 1); + if ((wp = popbuf(bp, WEPHEM)) != NULL) { + if (wp->w_flag & WEPHEM) { + curwp = wp; + delwind(FFRAND, 1); + } else { + killbuffer(bp); + } } } return (ret); @@ -729,7 +733,7 @@ complt_list(int flags, char *buf, int cpos) * the buffer list, obviously we don't want it freed. */ free_file_list(wholelist); - popbuftop(bp); /* split the screen and put up the help + popbuftop(bp, WEPHEM); /* split the screen and put up the help * buffer */ update(); /* needed to make the new stuff actually * appear */ diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 61cd03c23b5..ee345924c75 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.70 2009/06/04 02:23:37 kjell Exp $ */ +/* $OpenBSD: file.c,v 1.71 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -156,7 +156,7 @@ poptofile(int f, int n) return (FALSE); if (bp == curbp) return (splitwind(f, n)); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; diff --git a/usr.bin/mg/grep.c b/usr.bin/mg/grep.c index 3c670c53f58..0d688b5b83f 100644 --- a/usr.bin/mg/grep.c +++ b/usr.bin/mg/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.37 2009/06/04 02:23:37 kjell Exp $ */ +/* $OpenBSD: grep.c,v 1.38 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain */ @@ -74,7 +74,7 @@ grep(int f, int n) if ((bp = compile_mode("*grep*", cprompt)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; compile_win = curwp = wp; @@ -98,7 +98,7 @@ xlint(int f, int n) if ((bp = compile_mode("*lint*", cprompt)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; compile_win = curwp = wp; @@ -125,7 +125,7 @@ compile(int f, int n) if ((bp = compile_mode("*compile*", cprompt)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; compile_win = curwp = wp; @@ -183,7 +183,7 @@ gid(int f, int n) if ((bp = compile_mode("*gid*", command)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; compile_win = curwp = wp; @@ -307,7 +307,7 @@ compile_goto_error(int f, int n) if ((bp = findbuffer(adjf)) == NULL) return (FALSE); - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; curwp = wp; diff --git a/usr.bin/mg/help.c b/usr.bin/mg/help.c index dce1c76bef0..bbf63775ae7 100644 --- a/usr.bin/mg/help.c +++ b/usr.bin/mg/help.c @@ -1,4 +1,4 @@ -/* $OpenBSD: help.c,v 1.31 2005/12/14 07:11:44 kjell Exp $ */ +/* $OpenBSD: help.c,v 1.32 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -121,7 +121,7 @@ wallchart(int f, int n) if ((addline(bp, "Global bindings:") == FALSE) || (showall(bp, fundamental_map, "") == FALSE)) return (FALSE); - return (popbuftop(bp)); + return (popbuftop(bp, WNONE)); } static int @@ -205,7 +205,7 @@ apropos_command(int f, int n) } } free_file_list(fnames); - return (popbuftop(bp)); + return (popbuftop(bp, WNONE)); } static int diff --git a/usr.bin/mg/theo.c b/usr.bin/mg/theo.c index 5aadf0c0144..5e466c82bbd 100644 --- a/usr.bin/mg/theo.c +++ b/usr.bin/mg/theo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: theo.c,v 1.108 2009/04/26 10:34:57 sthen Exp $ */ +/* $OpenBSD: theo.c,v 1.109 2009/06/04 23:39:37 kjell Exp $ */ /* * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> * All rights reserved. @@ -67,7 +67,7 @@ theo(int f, int n) bp->b_modes[1] = name_mode("theo"); bp->b_nmodes = 1; - if ((wp = popbuf(bp)) == NULL) + if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c index fe8b53bfeed..92d8d0d57e1 100644 --- a/usr.bin/mg/undo.c +++ b/usr.bin/mg/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.47 2008/09/15 16:13:35 kjell Exp $ */ +/* $OpenBSD: undo.c,v 1.48 2009/06/04 23:39:37 kjell Exp $ */ /* * This file is in the public domain */ @@ -381,7 +381,7 @@ undo_dump(int f, int n) return (FALSE); bp->b_flag |= BFREADONLY; bclear(bp); - popbuf(bp); + popbuf(bp, WNONE); for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == bp) { diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c index 85a0e1bac90..5bea67a6d00 100644 --- a/usr.bin/mg/window.c +++ b/usr.bin/mg/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.26 2009/06/04 02:23:37 kjell Exp $ */ +/* $OpenBSD: window.c,v 1.27 2009/06/04 23:39:37 kjell Exp $ */ /* This file is in the public domain. */ @@ -200,6 +200,7 @@ onlywind(int f, int n) * Split the current window. A window smaller than 3 lines cannot be split. * The only other error that is possible is a "malloc" failure allocating the * structure for the new window. + * If called with a FFOTHARG, flags on the new window are set to 'n'. */ /* ARGSUSED */ int @@ -277,6 +278,10 @@ splitwind(int f, int n) curwp->w_rflag |= WFMODE | WFFULL; wp->w_rflag |= WFMODE | WFFULL; + /* if FFOTHARG, set flags) */ + if (f & FFOTHARG) + wp->w_flag = n; + return (TRUE); } @@ -421,25 +426,3 @@ delwind(int f, int n) free(wp); return (TRUE); } - -/* - * Pick a window for a pop-up. Split the screen if there is only one window. - * Pick the uppermost window that isn't the current window. An LRU algorithm - * might be better. Return a pointer, or NULL on error. - */ -struct mgwin * -wpopup(void) -{ - struct mgwin *wp; - - if (wheadp->w_wndp == NULL && - splitwind(FFRAND, 0) == FALSE) - return (NULL); - - /* find a window to use */ - wp = wheadp; - - while (wp != NULL && wp == curwp) - wp = wp->w_wndp; - return (wp); -} |