Added support for expanding tabs to spaces. - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c3e45a28540eeac825842265b3408254ad42b7cc
 (DIR) parent ba79cd6352170c348fd33f185d347119edd1cce5
 (HTM) Author: Rob King <jking@deadpixi.com>
       Date:   Tue, 17 May 2016 23:44:39 -0500
       
       Added support for expanding tabs to spaces.
       
       Inserting a composed tab character (e.g. via Alt-t-a) still inserts a
       literal tab, for when you're editing Makefiles.
       
       Diffstat:
         sam/sam.c                           |       9 ++++++++-
         samterm/main.c                      |      30 ++++++++++++++++++++++++------
       
       2 files changed, 32 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/sam/sam.c b/sam/sam.c
       @@ -19,6 +19,7 @@ jmp_buf        mainloop;
        List tempfile;
        int        quitok = TRUE;
        int        downloaded;
       +int expandtabs;
        int        dflag;
        int        Rflag;
        char        *machine;
       @@ -42,6 +43,12 @@ int main(int argc, char *argv[])
                ap = argv;
                while(argc>1 && argv[0] && argv[0][0]=='-'){
                        switch(argv[0][1]){
       +        case 'e':
       +            *ap++ = *argv++;
       +            --argc;
       +            expandtabs++;
       +            break;
       +
                        case 'd':
                                dflag++;
                                break;
       @@ -119,7 +126,7 @@ int main(int argc, char *argv[])
        void
        usage(void)
        {
       -        dprint("usage: sam [-d] [-t samterm] [-s sam name] -r machine\n");
       +        dprint("usage: sam [-d] [-e] [-t samterm] [-s sam name] -r machine\n");
                exits("usage");
        }
        
 (DIR) diff --git a/samterm/main.c b/samterm/main.c
       @@ -3,6 +3,7 @@
        #include <libc.h>
        #include <libg.h>
        #include <frame.h>
       +#include <unistd.h>
        #include "flayer.h"
        #include "samterm.h"
        
       @@ -22,6 +23,7 @@ long        typeesc = -1;
        long        modified = 0;                /* strange lookahead for menus */
        char        lock = 1;
        char        hasunlocked = 0;
       +int expandtabs = 0;
        int        chord = 0;
        char *machine = "localhost";
        
       @@ -44,17 +46,23 @@ char *machine = "localhost";
        void
        main(int argc, char *argv[])
        {
       -        int i, got, scr;
       +        int i, got, scr, opt;
                Text *t;
                Rectangle r;
                Flayer *nwhich;
       -
                int fwdbut;
        
       -        if (argc >= 3 && strcmp(argv[1], "-r") == 0)
       -        {
       -                machine = argv[2];
       -        }
       +    while ((opt = getopt(argc, argv, "er:")) != -1){
       +        switch (opt){
       +            case 'r':
       +                machine = optarg;
       +                break;
       +
       +            case 'e':
       +                expandtabs = 1;
       +                break;
       +        }
       +    }
        
                getscreen(argc, argv);
                fwdbut = scrollfwdbut();
       @@ -528,6 +536,16 @@ type(Flayer *l, int res)        /* what a bloody mess this is */
                                        break;
                                }
                        }
       +        if (expandtabs && c == '\t' && !k.composed){
       +            int col = 0, nspaces = 8, off = a;
       +            while (off > 0 && raspc(&t->rasp, off - 1) != '\n')
       +                off--, col++;
       +
       +            nspaces = tabwidth - col % tabwidth;
       +            for (int i = 0; i < nspaces; i++)
       +                pushkbd(' ');
       +            break;
       +        }
                        *p++ = c;
                        if(c == '\n' || p >= buf+sizeof(buf)/sizeof(buf[0]))
                                break;