Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Fix typo in config.def.h
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
11d01df
..
26053b0
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-180,7
+180,6
@@
typedef unsigned short ushort;
typedef XftDraw *Draw;
typedef XftColor Color;
typedef XftDraw *Draw;
typedef XftColor Color;
-typedef Colormap Colormap;
typedef struct {
char c[UTF_SIZ]; /* character code */
typedef struct {
char c[UTF_SIZ]; /* character code */
@@
-441,7
+440,7
@@
static void selclear(XEvent *);
static void selrequest(XEvent *);
static void selinit(void);
static void selrequest(XEvent *);
static void selinit(void);
-static void sel
sort
(void);
+static void sel
normalize
(void);
static inline bool selected(int, int);
static char *getsel(void);
static void selcopy(void);
static inline bool selected(int, int);
static char *getsel(void);
static void selcopy(void);
@@
-657,9
+656,20
@@
y2row(int y) {
return LIMIT(y, 0, term.row-1);
}
return LIMIT(y, 0, term.row-1);
}
+static int tlinelen(int y) {
+ int i = term.col;
+
+ while (i > 0 && term.line[y][i - 1].c[0] == ' ')
+ --i;
+
+ return i;
+}
+
static void
static void
-selsort(void) {
- if(sel.ob.y == sel.oe.y) {
+selnormalize(void) {
+ int i;
+
+ if(sel.ob.y == sel.oe.y || sel.type == SEL_RECTANGULAR) {
sel.nb.x = MIN(sel.ob.x, sel.oe.x);
sel.ne.x = MAX(sel.ob.x, sel.oe.x);
} else {
sel.nb.x = MIN(sel.ob.x, sel.oe.x);
sel.ne.x = MAX(sel.ob.x, sel.oe.x);
} else {
@@
-668,6
+678,15
@@
selsort(void) {
}
sel.nb.y = MIN(sel.ob.y, sel.oe.y);
sel.ne.y = MAX(sel.ob.y, sel.oe.y);
}
sel.nb.y = MIN(sel.ob.y, sel.oe.y);
sel.ne.y = MAX(sel.ob.y, sel.oe.y);
+
+ /* expand selection over line breaks */
+ if (sel.type == SEL_RECTANGULAR)
+ return;
+ i = tlinelen(sel.nb.y);
+ if (i < sel.nb.x)
+ sel.nb.x = i;
+ if (tlinelen(sel.ne.y) <= sel.ne.x)
+ sel.ne.x = term.col - 1;
}
static inline bool
}
static inline bool
@@
-683,7
+702,8
@@
selected(int x, int y) {
void
selsnap(int mode, int *x, int *y, int direction) {
void
selsnap(int mode, int *x, int *y, int direction) {
- int i;
+ int newx, newy, xt, yt;
+ Glyph *gp;
switch(mode) {
case SNAP_WORD:
switch(mode) {
case SNAP_WORD:
@@
-692,36
+712,31
@@
selsnap(int mode, int *x, int *y, int direction) {
* beginning of a line.
*/
for(;;) {
* beginning of a line.
*/
for(;;) {
- if(direction < 0 && *x <= 0) {
- if(*y > 0 && term.line[*y - 1][term.col-1].mode
-
& ATTR_WRAP
) {
-
*y -= 1
;
-
*x = term.col-1
;
- } else {
+ newx = *x + direction;
+ newy = *y;
+
if(!BETWEEN(newx, 0, term.col - 1)
) {
+
newy += direction
;
+
newx = (newx + term.col) % term.col
;
+ if (!BETWEEN(newy, 0, term.row - 1))
break;
break;
- }
- }
- if(direction > 0 && *x >= term.col-1) {
- if(*y < term.row-1 && term.line[*y][*x].mode
- & ATTR_WRAP) {
- *y += 1;
- *x = 0;
- } else {
+
+ if(direction > 0)
+ yt = *y, xt = *x;
+ else
+ yt = newy, xt = newx;
+ if(!(term.line[yt][xt].mode & ATTR_WRAP))
break;
break;
- }
}
}
- if(term.line[*y][*x+direction].mode & ATTR_WDUMMY) {
- *x += direction;
- continue;
- }
+ if (newx >= tlinelen(newy))
+ break;
- if(strchr(worddelimiters,
- term.line[*y][*x+direction].c[0])) {
+ gp = &term.line[newy][newx];
+ if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0]))
break;
break;
- }
- *x += direction;
+ *x = newx;
+ *y = newy;
}
break;
case SNAP_LINE:
}
break;
case SNAP_LINE:
@@
-747,18
+762,6
@@
selsnap(int mode, int *x, int *y, int direction) {
}
}
break;
}
}
break;
- default:
- /*
- * Select the whole line when the end of line is reached.
- */
- if(direction > 0) {
- i = term.col;
- while(--i > 0 && term.line[*y][i].c[0] == ' ')
- /* nothing */;
- if(i > 0 && i < *x)
- *x = term.col - 1;
- }
- break;
}
}
}
}
@@
-780,7
+783,7
@@
getbuttoninfo(XEvent *e) {
selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
}
selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
}
- sel
sort
();
+ sel
normalize
();
sel.type = SEL_REGULAR;
for(type = 1; type < LEN(selmasks); ++type) {
sel.type = SEL_REGULAR;
for(type = 1; type < LEN(selmasks); ++type) {
@@
-896,7
+899,7
@@
bpress(XEvent *e) {
}
selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
}
selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
- sel
sort
();
+ sel
normalize
();
/*
* Draw selection, unless it's regular and we don't want to
/*
* Draw selection, unless it's regular and we don't want to
@@
-914,7
+917,7
@@
bpress(XEvent *e) {
char *
getsel(void) {
char *str, *ptr;
char *
getsel(void) {
char *str, *ptr;
- int x, y, bufsize, size,
i,
ex;
+ int x, y, bufsize, size, ex;
Glyph *gp, *last;
if(sel.ob.x == -1)
Glyph *gp, *last;
if(sel.ob.x == -1)
@@
-959,13
+962,10
@@
getsel(void) {
* after the visible text '\n' is appended.
*/
if(y == sel.ne.y) {
* after the visible text '\n' is appended.
*/
if(y == sel.ne.y) {
- i = term.col;
- while(--i > 0 && term.line[y][i].c[0] == ' ')
- /* nothing */;
ex = sel.ne.x;
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
ex = sel.nb.x;
ex = sel.ne.x;
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
ex = sel.nb.x;
- if(
i
< ex)
+ if(
tlinelen(y)
< ex)
*ptr++ = '\n';
}
}
*ptr++ = '\n';
}
}
@@
-1451,7
+1451,7
@@
selscroll(int orig, int n) {
sel.oe.x = term.col;
}
}
sel.oe.x = term.col;
}
}
- sel
sort
();
+ sel
normalize
();
}
}
}
}
@@
-2315,19
+2315,15
@@
techo(char *buf, int len) {
void
tdeftran(char ascii) {
void
tdeftran(char ascii) {
- char c, (*bp)[2];
- static char tbl[][2] = {
- {'0', CS_GRAPHIC0}, {'B', CS_USA},
- {0, 0}
- };
-
- for (bp = &tbl[0]; (c = (*bp)[0]) && c != ascii; ++bp)
- /* nothing */;
+ static char cs[] = "0B";
+ static int vcs[] = {CS_GRAPHIC0, CS_USA};
+ char *p;
- if
(c == 0)
+ if
((p = strchr(cs, ascii)) == NULL) {
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
- else
- term.trantbl[term.icharset] = (*bp)[1];
+ } else {
+ term.trantbl[term.icharset] = vcs[p - cs];
+ }
}
void
}
void
@@
-2997,6
+2993,7
@@
xzoom(const Arg *arg) {
xloadfonts(usedfont, usedfontsize + arg->i);
cresize(0, 0);
redraw(0);
xloadfonts(usedfont, usedfontsize + arg->i);
cresize(0, 0);
redraw(0);
+ xhints();
}
void
}
void
@@
-3249,28
+3246,22
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
bytelen -= u8cblen;
doesexist = XftCharExists(xw.dpy, font->match, unicodep);
bytelen -= u8cblen;
doesexist = XftCharExists(xw.dpy, font->match, unicodep);
- if(oneatatime || !doesexist || bytelen <= 0) {
- if(oneatatime || bytelen <= 0) {
- if(doesexist) {
- u8fl++;
- u8fblen += u8cblen;
- }
- }
-
- if(u8fl > 0) {
- XftDrawStringUtf8(xw.draw, fg,
- font->match, xp,
- winy + font->ascent,
- (FcChar8 *)u8fs,
- u8fblen);
- xp += xw.cw * u8fl;
-
- }
- break;
+ if(doesexist) {
+ u8fl++;
+ u8fblen += u8cblen;
+ if(!oneatatime && bytelen > 0)
+ continue;
}
}
- u8fl++;
- u8fblen += u8cblen;
+ if(u8fl > 0) {
+ XftDrawStringUtf8(xw.draw, fg,
+ font->match, xp,
+ winy + font->ascent,
+ (FcChar8 *)u8fs,
+ u8fblen);
+ xp += xw.cw * u8fl;
+ }
+ break;
}
if(doesexist) {
if(oneatatime)
}
if(doesexist) {
if(oneatatime)