This diff adds the capability to toggle on and off the system bell
within mg via the 'audible-bell' command. It also introduces the
'visible-bell' command: the modeline will flash instead.  However,
both can be used together, if so desired. Comments/oks? 

-lum

Index: Makefile
===================================================================
RCS file: /cvs/src/usr.bin/mg/Makefile,v
retrieving revision 1.27
diff -u -r1.27 Makefile
--- Makefile    18 Jun 2012 07:13:26 -0000      1.27
+++ Makefile    30 May 2013 18:33:42 -0000
@@ -15,7 +15,7 @@
 #
 CFLAGS+=-Wall -DFKEYS -DREGEX -DXKEYS
 
-SRCS=  autoexec.c basic.c buffer.c cinfo.c dir.c display.c \
+SRCS=  autoexec.c basic.c bell.c buffer.c cinfo.c dir.c display.c \
        echo.c extend.c file.c fileio.c funmap.c help.c kbd.c keymap.c \
        line.c macro.c main.c match.c modes.c paragraph.c random.c \
        re_search.c region.c search.c spawn.c tty.c ttyio.c ttykbd.c \
Index: basic.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.39
diff -u -r1.39 basic.c
--- basic.c     25 Mar 2013 11:41:44 -0000      1.39
+++ basic.c     30 May 2013 18:33:42 -0000
@@ -43,8 +43,10 @@
        while (n--) {
                if (curwp->w_doto == 0) {
                        if ((lp = lback(curwp->w_dotp)) == curbp->b_headp) {
-                               if (!(f & FFRAND))
+                               if (!(f & FFRAND)) {
+                                       dobeep();
                                        ewprintf("Beginning of buffer");
+                               }
                                return (FALSE);
                        }
                        curwp->w_dotp = lp;
@@ -85,8 +87,10 @@
                        curwp->w_dotp = lforw(curwp->w_dotp);
                        if (curwp->w_dotp == curbp->b_headp) {
                                curwp->w_dotp = lback(curwp->w_dotp);
-                               if (!(f & FFRAND))
+                               if (!(f & FFRAND)) {
+                                       dobeep();
                                        ewprintf("End of buffer");
+                               }
                                return (FALSE);
                        }
                        curwp->w_doto = 0;
@@ -283,7 +287,7 @@
        lp = curwp->w_linep;
        while (n--)
                if ((lp = lforw(lp)) == curbp->b_headp) {
-                       ttbeep();
+                       dobeep();
                        ewprintf("End of buffer");
                        return(TRUE);
                }
@@ -332,7 +336,7 @@
                lp = lback(lp);
        }
        if (lp == curwp->w_linep) {
-               ttbeep();
+               dobeep();
                ewprintf("Beginning of buffer");
        }
        curwp->w_linep = lp;
Index: bell.c
===================================================================
RCS file: bell.c
diff -N bell.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ bell.c      30 May 2013 18:33:42 -0000
@@ -0,0 +1,57 @@
+/*     $OpenBSD$       */
+
+/*
+ * This file is in the public domain.
+ *
+ */
+/*
+ * Control how mg communicates with the user.
+ */
+
+#include "def.h"
+
+void
+bellinit(void)
+{
+       doaudiblebell = 1;
+       dovisiblebell = 0;
+       donebell = 0;
+}
+
+void
+dobeep(void)
+{
+       if (doaudiblebell) {
+               ttbeep();
+       }
+       if (dovisiblebell) {
+               sgarbf = TRUE;
+               update(CNONE);
+               usleep(50000);
+       }
+       donebell = 1;
+}
+
+/* ARGSUSED */
+int
+toggleaudiblebell(int f, int n)
+{
+       if (f & FFARG)
+               doaudiblebell = n > 0;
+       else
+               doaudiblebell = !doaudiblebell;
+
+       return (TRUE);
+}
+
+/* ARGSUSED */
+int
+togglevisiblebell(int f, int n)
+{
+       if (f & FFARG)
+               dovisiblebell = n > 0;
+       else
+               dovisiblebell = !dovisiblebell;
+
+       return (TRUE);
+}
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/def.h,v
retrieving revision 1.137
diff -u -r1.137 def.h
--- def.h       30 May 2013 04:17:25 -0000      1.137
+++ def.h       30 May 2013 18:33:42 -0000
@@ -424,7 +424,7 @@
 int            vtresize(int, int, int);
 void           vtinit(void);
 void           vttidy(void);
-void           update(void);
+void           update(int);
 int            linenotoggle(int, int);
 int            colnotoggle(int, int);
 
@@ -681,6 +681,12 @@
 int             globalwdtoggle(int, int);
 int             compile(int, int);
 
+/* bell.c */
+void            bellinit(void);
+int             toggleaudiblebell(int, int);
+int             togglevisiblebell(int, int);
+void            dobeep(void);
+
 /*
  * Externals.
  */
@@ -704,6 +710,9 @@
 extern int              tthue;
 extern int              defb_nmodes;
 extern int              defb_flag;
+extern int              doaudiblebell;
+extern int              dovisiblebell;
+extern int              donebell;
 extern char             cinfo[];
 extern char            *keystrings[];
 extern char             pat[NPAT];
Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/display.c,v
retrieving revision 1.40
diff -u -r1.40 display.c
--- display.c   25 Mar 2013 11:41:44 -0000      1.40
+++ display.c   30 May 2013 18:33:42 -0000
@@ -68,7 +68,7 @@
 int    vtputs(const char *);
 void   vteeol(void);
 void   updext(int, int);
-void   modeline(struct mgwin *);
+void   modeline(struct mgwin *, int);
 void   setscores(int, int);
 void   traceback(int, int, int, int);
 void   ucopy(struct video *, struct video *);
@@ -403,7 +403,7 @@
  * virtual and physical screens the same.
  */
 void
-update(void)
+update(int modelinecolor)
 {
        struct line     *lp;
        struct mgwin    *wp;
@@ -503,7 +503,7 @@
                        }
                }
                if ((wp->w_rflag & WFMODE) != 0)
-                       modeline(wp);
+                       modeline(wp, modelinecolor);
                wp->w_rflag = 0;
                wp->w_frame = 0;
        }
@@ -796,7 +796,7 @@
  * characters may never be seen.
  */
 void
-modeline(struct mgwin *wp)
+modeline(struct mgwin *wp, int modelinecolor)
 {
        int     n, md;
        struct buffer *bp;
@@ -804,7 +804,7 @@
        int len;
 
        n = wp->w_toprow + wp->w_ntrows;        /* Location.             */
-       vscreen[n]->v_color = CMODE;            /* Mode line color.      */
+       vscreen[n]->v_color = modelinecolor;    /* Mode line color.      */
        vscreen[n]->v_flag |= (VFCHG | VFHBAD); /* Recompute, display.   */
        vtmove(n, 0);                           /* Seek to right line.   */
        bp = wp->w_bufp;
Index: echo.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/echo.c,v
retrieving revision 1.54
diff -u -r1.54 echo.c
--- echo.c      3 Nov 2012 16:28:14 -0000       1.54
+++ echo.c      30 May 2013 18:33:42 -0000
@@ -756,7 +756,7 @@
        free_file_list(wholelist);
        popbuftop(bp, WEPHEM);  /* split the screen and put up the help
                                 * buffer */
-       update();               /* needed to make the new stuff actually
+       update(CMODE);          /* needed to make the new stuff actually
                                 * appear */
        ttmove(oldrow, oldcol); /* update leaves cursor in arbitrary place */
        ttcolor(oldhue);        /* with arbitrary color */
Index: funmap.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/funmap.c,v
retrieving revision 1.46
diff -u -r1.46 funmap.c
--- funmap.c    22 May 2013 19:23:45 -0000      1.46
+++ funmap.c    30 May 2013 18:33:42 -0000
@@ -21,6 +21,7 @@
 
 static struct funmap functnames[] = {
        {apropos_command, "apropos",},
+       {toggleaudiblebell, "audible-bell",},
        {auto_execute, "auto-execute",},
        {fillmode, "auto-fill-mode",},
        {indentmode, "auto-indent-mode",},
@@ -200,6 +201,7 @@
        {universal_argument, "universal-argument",},
        {upperregion, "upcase-region",},
        {upperword, "upcase-word",},
+       {togglevisiblebell, "visible-bell",},
        {tagsvisit, "visit-tags-table",},
        {showcpos, "what-cursor-position",},
        {filewrite, "write-file",},
Index: kbd.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/kbd.c,v
retrieving revision 1.25
diff -u -r1.25 kbd.c
--- kbd.c       12 Apr 2012 04:47:59 -0000      1.25
+++ kbd.c       30 May 2013 18:33:42 -0000
@@ -81,7 +81,7 @@
                        /* avoid problems with % */
                        ewprintf("%s", prompt);
                        /* put the cursor back */
-                       update();
+                       update(CMODE);
                        epresf = KCLEAR;
                }
                if (promptp > prompt)
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/main.c,v
retrieving revision 1.70
diff -u -r1.70 main.c
--- main.c      28 Dec 2012 16:12:50 -0000      1.70
+++ main.c      30 May 2013 18:33:42 -0000
@@ -18,6 +18,9 @@
 int             lastflag;                      /* flags, last command  */
 int             curgoal;                       /* goal column          */
 int             startrow;                      /* row to start         */
+int             doaudiblebell;                 /* audible bell toggle  */
+int             dovisiblebell;                 /* visible bell toggle  */
+int             donebell;                      /* done't wring bell    */
 struct buffer  *curbp;                         /* current buffer       */
 struct buffer  *bheadp;                        /* BUFFER list head     */
 struct mgwin   *curwp;                         /* current window       */
@@ -93,13 +96,14 @@
        dirinit();              /* Get current directory.       */
        edinit(bp);             /* Buffers, windows.            */
        ttykeymapinit();        /* Symbols, bindings.           */
+       bellinit();             /* Audible and visible bell.    */
 
        /*
         * doing update() before reading files causes the error messages from
         * the file I/O show up on the screen.  (and also an extra display of
         * the mode line if there are files specified on the command line.)
         */
-       update();
+       update(CMODE);
 
        /* user startup file. */
        if ((cp = startupfile(NULL)) != NULL)
@@ -171,7 +175,7 @@
                        do_redraw(0, 0, TRUE);
                        winch_flag = 0;
                }
-               update();
+               update(CMODE);
                lastflag = thisflag;
                thisflag = 0;
 
@@ -183,9 +187,11 @@
                        /* FALLTHRU */
                case FALSE:
                default:
-                       ttbeep();
+                       if (!donebell)
+                               dobeep();
                        macrodef = FALSE;
                }
+               donebell = 0;
        }
 }
 
Index: match.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/match.c,v
retrieving revision 1.16
diff -u -r1.16 match.c
--- match.c     4 Jun 2009 02:23:37 -0000       1.16
+++ match.c     30 May 2013 18:33:42 -0000
@@ -45,7 +45,7 @@
                        return (s);
                /* unbalanced -- warn user */
                if (balance() != TRUE)
-                       ttbeep();
+                       dobeep();
        }
        return (TRUE);
 }
@@ -152,13 +152,13 @@
                curwp->w_doto = cbo;
                curwp->w_rflag |= WFMOVE;
 
-               update();               /* show match */
+               update(CMODE);          /* show match */
                ttwait(1000);           /* wait for key or 1 second */
 
                curwp->w_dotp = tlp;    /* return to old position */
                curwp->w_doto = tbo;
                curwp->w_rflag |= WFMOVE;
-               update();
+               update(CMODE);
        } else {
                /* match is not in this window, so display line in echo area */
                bufo = 0;
Index: mg.1
===================================================================
RCS file: /cvs/src/usr.bin/mg/mg.1,v
retrieving revision 1.78
diff -u -r1.78 mg.1
--- mg.1        27 May 2013 19:28:51 -0000      1.78
+++ mg.1        30 May 2013 18:33:43 -0000
@@ -361,6 +361,8 @@
 and list all
 .Nm
 commands that contain that string.
+.It audible-bell
+Toggle the audible system bell.
 .It auto-execute
 Register an auto-execute hook; that is, specify a filename pattern
 (conforming to the shell's filename globbing rules) and an associated
@@ -897,6 +899,8 @@
 .It upcase-word
 Move the cursor forward by the specified number of words.
 As it moves, convert any characters to upper case.
+.It visible-bell
+Toggle the visible bell. If this toggle is on, the modeline will flash.
 .It visit-tags-table
 Record name of the tags file to be used for subsequent find-tag.
 .It what-cursor-position
Index: re_search.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/re_search.c,v
retrieving revision 1.26
diff -u -r1.26 re_search.c
--- re_search.c 21 Jan 2011 19:10:13 -0000      1.26
+++ re_search.c 30 May 2013 18:33:43 -0000
@@ -149,7 +149,7 @@
         */
        while (re_forwsrch() == TRUE) {
 retry:
-               update();
+               update(CMODE);
                switch (getkey(FALSE)) {
                case ' ':
                        plen = re_match[0].rm_eo - re_match[0].rm_so;
@@ -191,7 +191,7 @@
 
 stopsearch:
        curwp->w_rflag |= WFFULL;
-       update();
+       update(CMODE);
        if (!inmacro) {
                if (rcnt == 0)
                        ewprintf("(No replacements done)");
Index: search.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/search.c,v
retrieving revision 1.41
diff -u -r1.41 search.c
--- search.c    7 Sep 2012 19:01:56 -0000       1.41
+++ search.c    30 May 2013 18:33:44 -0000
@@ -192,7 +192,7 @@
        is_prompt(dir, TRUE, success);
 
        for (;;) {
-               update();
+               update(CMODE);
 
                switch (c = getkey(FALSE)) {
                case CCHR('['):
@@ -248,7 +248,7 @@
                        is_lpush();
                        pptr = strlen(pat);
                        if (forwchar(FFRAND, 1) == FALSE) {
-                                ttbeep();
+                                dobeep();
                                 success = FALSE;
                                 ewprintf("Failed I-search: %s", pat);
                        } else {
@@ -256,7 +256,7 @@
                                        is_cpush(SRCH_MARK);
                                else {
                                        (void)backchar(FFRAND, 1);
-                                       ttbeep();
+                                       dobeep();
                                        success = FALSE;
                                        ewprintf("Failed I-search: %s", pat);
                                }
@@ -285,14 +285,14 @@
                        is_lpush();
                        pptr = strlen(pat);
                         if (backchar(FFRAND, 1) == FALSE) {
-                                ttbeep();
+                                dobeep();
                                 success = FALSE;
                         } else {
                                if (is_find(SRCH_BACK) != FALSE)
                                        is_cpush(SRCH_MARK);
                                else {
                                        (void)forwchar(FFRAND, 1);
-                                       ttbeep();
+                                       dobeep();
                                        success = FALSE;
                                }
                        }
@@ -322,7 +322,7 @@
                                        break;
 
                                if (pptr == NPAT - 1) {
-                                       ttbeep();
+                                       dobeep();
                                        break;
                                }
                                firstc = 0;
@@ -335,7 +335,7 @@
                                if (dir == SRCH_FORW) {
                                        curwp->w_doto = cbo;
                                        curwp->w_rflag |= WFMOVE;
-                                       update();
+                                       update(CMODE);
                                }
                        }
                        is_prompt(dir, pptr < 0, success);
@@ -373,7 +373,7 @@
                        if (pptr == 0)
                                success = TRUE;
                        if (pptr == NPAT - 1)
-                               ttbeep();
+                               dobeep();
                        else {
                                pat[pptr++] = c;
                                pat[pptr] = '\0';
@@ -384,7 +384,7 @@
                                        is_cpush(c);
                                else {
                                        success = FALSE;
-                                       ttbeep();
+                                       dobeep();
                                        is_cpush(SRCH_ACCM);
                                }
                        } else
@@ -579,7 +579,7 @@
         */
        while (forwsrch() == TRUE) {
 retry:
-               update();
+               update(CMODE);
                switch (getkey(FALSE)) {
                case 'y':
                case ' ':
@@ -618,7 +618,7 @@
        }
 stopsearch:
        curwp->w_rflag |= WFFULL;
-       update();
+       update(CMODE);
        if (rcnt == 1)
                ewprintf("Replaced 1 occurrence");
        else
@@ -647,7 +647,7 @@
 
        plen = strlen(pat);
        while (forwsrch() == TRUE) {
-               update();
+               update(CMODE);
                if (lreplace((RSIZE)plen, news) == FALSE)
                        return (FALSE);
 
@@ -655,7 +655,7 @@
        }
 
        curwp->w_rflag |= WFFULL;
-       update();
+       update(CMODE);
 
        if (rcnt == 1)
                ewprintf("Replaced 1 occurrence");
Index: window.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/window.c,v
retrieving revision 1.28
diff -u -r1.28 window.c
--- window.c    1 Aug 2011 12:15:23 -0000       1.28
+++ window.c    30 May 2013 18:33:44 -0000
@@ -97,7 +97,7 @@
                }
                wp->w_ntrows = nrow - wp->w_toprow - 2;
                sgarbf = TRUE;
-               update();
+               update(CMODE);
        } else
                sgarbf = TRUE;
        return (TRUE);

Reply via email to