Merge pull request #64 from dtolpin/master - sam - An updated version of the sa… | |
git clone git://vernunftzentrum.de/sam.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 5eac1dc352e2791e882d5d52d036542e98c05d1d | |
parent 20e0ad8abcc61009fcf089968d84f7a277078437 | |
Author: Rob King <[email protected]> | |
Date: Tue, 12 Sep 2017 12:52:02 -0500 | |
Merge pull request #64 from dtolpin/master | |
optional autoindent | |
Diffstat: | |
doc/samrc | 3 +++ | |
doc/samrc.5 | 17 +++++++++++++++++ | |
samterm/main.c | 46 +++++++++++++++++++++++++++++++ | |
samterm/samrc.c | 14 +++++++++++++- | |
4 files changed, 79 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/doc/samrc b/doc/samrc | |
@@ -67,3 +67,6 @@ background white:seashell:lightgreen:oldlace:lightcyan:gainsb… | |
# Expand tabs and have tabstops every four columns | |
tabs 4 | |
expandtabs true | |
+ | |
+# Automatically indent lines | |
+autoindent true | |
diff --git a/doc/samrc.5 b/doc/samrc.5 | |
@@ -195,6 +195,23 @@ or | |
If | |
.Dq true "," | |
then tabs will be automatically expanded. | |
+.It autoindent | |
+Determines whether a line following a non-empty indented line is automatically… | |
+It is of the form: | |
+.Bd -literal | |
+ | |
+ autoindent B | |
+ | |
+.Ed | |
+where | |
+.Em B | |
+is the string | |
+.Dq true | |
+or | |
+.Dq false "." | |
+If | |
+.Dq true "," | |
+then a new line after a non-empty indented line is automatically indented. | |
.It snarfselection | |
Indicates which X selection should be exchanged with | |
.Nm | |
diff --git a/samterm/main.c b/samterm/main.c | |
@@ -27,6 +27,7 @@ bool modified = false; /* strange lookahead for menu… | |
char lock = 1; | |
bool hasunlocked = false; | |
bool expandtabs = false; | |
+bool autoindent = false; | |
char *machine = "localhost"; | |
int exfd = -1; | |
const char *exname; | |
@@ -388,6 +389,49 @@ ctlu(Rasp *r, int64_t o, int64_t p) | |
return p>=o? p : o; | |
} | |
+int64_t | |
+indent(Flayer *l, long p) | |
+{ | |
+ Text *t = (Text *)l->user1; | |
+ static wchar_t sbuf[7] = {' ',' ',' ',' ',' ',' ',' '}; | |
+ static wchar_t tbuf[7] = {'\t','\t','\t','\t','\t','\t','\t'}; | |
+ int i, is, it, q, c, space; | |
+ | |
+ q = p - 1; is = 0; it = 0; space = true; | |
+ while(--q >= l->origin) { | |
+ c = raspc(&t->rasp, q); | |
+ if(c == '\n') { | |
+ break; | |
+ } else if(c == '\t') { | |
+ ++it; | |
+ } else if(c == ' ') { | |
+ ++is; | |
+ } else { | |
+ it = is = 0; | |
+ space = false; | |
+ } | |
+ } | |
+ if(space) | |
+ it = is = 0; | |
+ | |
+ while(it != 0) { | |
+ i = it>7?7:it; | |
+ hgrow(t->tag, p, i, 0); | |
+ t->lock++; | |
+ hdatarune(t->tag, p, tbuf, i); | |
+ it -= i; p += i; | |
+ } | |
+ while(is != 0) { | |
+ i = is > 7? 7 : is; | |
+ hgrow(t->tag, p, i, 0); | |
+ t->lock++; | |
+ hdatarune(t->tag, p, sbuf, i); | |
+ is -= i; p += i; | |
+ } | |
+ | |
+ return typeend = l->p0 = l->p1 = p; | |
+} | |
+ | |
int | |
center(Flayer *l, int64_t a) | |
{ | |
@@ -980,6 +1024,8 @@ type(Flayer *l) /* what a bloody mess this is -- but it… | |
l->p0 = a; | |
l->p1 = a; | |
typeend = a; | |
+ if (autoindent && k.c == '\n' && t!=&cmd) | |
+ a = indent(l, a); | |
if (k.c == '\n' || typeend - typestart > 100) | |
flushtyping(false); | |
onethird(l, a); | |
diff --git a/samterm/samrc.c b/samterm/samrc.c | |
@@ -11,8 +11,9 @@ | |
#include "flayer.h" | |
#include "samterm.h" | |
-extern int expandtabs; | |
+extern bool expandtabs; | |
extern int tabwidth; | |
+extern bool autoindent; | |
typedef struct Namemapping Namemapping; | |
struct Namemapping{ | |
@@ -349,6 +350,16 @@ direxpandtabs(const char *s1, const char *s2, const char *… | |
} | |
static int | |
+dirautoindent(const char *s1, const char *s2, const char *s3, const char *s4, … | |
+{ | |
+ if (strcasecmp(s1, "true") != 0 && strcasecmp(s1, "false") != 0) | |
+ return -1; | |
+ | |
+ autoindent = (strcasecmp(s1, "true") == 0); | |
+ return 0; | |
+} | |
+ | |
+static int | |
dircomment(const char *s1, const char *s2, const char *s3, const char *s4, con… | |
{ | |
return 0; | |
@@ -376,6 +387,7 @@ Directive directives[] ={ | |
{" font %1023[^\n]", 1, dirfont… | |
{" tabs %2[0-9]", 1, dirtabs… | |
{" expandtabs %99s", 1, direxpa… | |
+ {" autoindent %99s", 1, dirauto… | |
{" snarfselection %99s", 1, dirsnar… | |
{" %1[#]", 1, dircomm… | |
{" %1[^ ]", EOF, dircomm… |