Make visual mode, yanking and the ARMv7l build more robust

This commit is contained in:
markmental 2026-09-06 01:52:09 -04:00
commit 5f512cc821
3 changed files with 83 additions and 22 deletions

View file

@ -14,8 +14,16 @@ set -euo pipefail
# Adjust these if your toolchain lives elsewhere
CROSS_PREFIX="arm-linux-gnueabihf"
CC="${CROSS_PREFIX}-gcc"
AR="${CROSS_PREFIX}-ar"
EXE="" # empty → no suffix; set to e.g. ".bin" if needed
# 32-bit armv7l target notes:
# The "${CROSS_PREFIX}-gcc" toolchain defaults to ARMv7-A hard-float
# (armv7-a+fp, EABI5), so no extra -march/-mfpu CFLAGS are needed and
# none are passed: overriding CFLAGS on the make command line would
# clobber the Makefiles' own CFLAGS+= include paths (-I., -I..,
# -I./libqhtml, -I$(OBJS_DIR)) and break the build.
# Target selection: teqe (tiny) or eqe (full)
TARGET="${1:-eqe}"
@ -30,28 +38,35 @@ check_tool() {
# ----- validation ----------------------------------------------------------
check_tool "$CC"
check_tool "$AR"
[ "$TARGET" = "eqe" ] || [ "$TARGET" = "teqe" ] || die "unknown target '$TARGET', use 'eqe' or 'teqe'"
# ----- prepare Makefile config --------------------------------------------
# Build the make command line.
# Build the make command line (bash array so values containing spaces
# such as LDFLAGS/CFLAGS stay a single make argument).
# -B forces rebuilding all targets regardless of timestamps.
# CC is passed on the command line to override config.mak's CC.
# CC/AR are passed on the command line to override config.mak's natives;
# they propagate to the libqhtml sub-make via MAKEFLAGS.
# TARGET_ARCH=arm keeps the .objs dir named for the target, not the host.
# For teqe also set TARGET_TINY=1.
# Static linking keeps the binary self-contained for devices that may
# not have a recent glibc (e.g. the Miyoo Mini Plus).
# HOST_CFLAGS=-I. is needed because the host tools (fbftoqe & co) are
# built with HOST_CC while CC is the cross compiler; without it the
# tools cannot find cutils.h.
# The goal is the binary itself, not "all": the full target also builds
# host-side extras (html2png, manuals) that have no business in a
# cross-compiled device binary.
MAKE_FLAGS="-B LDFLAGS=-static -Wl,--no-as-needed -lc HOST_CFLAGS=-I."
# The goals are the binary itself plus its cross-built static dep,
# not "all": the full target also builds host-side extras (html2png,
# manuals) that have no business in a cross-compiled device binary.
# NOTE: goal `eqe` alone is not enough: with TARGET=qe set, `libqhtml.a`
# is a prerequisite of eqe_g but the `libqhtml` sub-make is only wired
# into `all`, so it must be requested explicitly (teqe needs no libqhtml).
MAKE_ARGS=(-B "LDFLAGS=-static -Wl,--no-as-needed -lc" "HOST_CFLAGS=-I." "TARGET_ARCH=arm" "CC=${CC}" "AR=${AR}")
case "$TARGET" in
eqe)
MAKE_FLAGS="$MAKE_FLAGS TARGET=qe CC=${CC} eqe"
MAKE_ARGS+=("TARGET=qe" "libqhtml" "eqe")
;;
teqe)
MAKE_FLAGS="$MAKE_FLAGS TARGET=tqe TARGET_TINY=1 CC=${CC} teqe"
MAKE_ARGS+=("TARGET=tqe" "TARGET_TINY=1" "teqe")
;;
*)
die "unsupported target '$TARGET'"
@ -59,7 +74,7 @@ case "$TARGET" in
esac
# ----- build ---------------------------------------------------------------
if ! make $MAKE_FLAGS 2>&1; then
if ! make "${MAKE_ARGS[@]}" 2>&1; then
die "make failed"
fi

View file

@ -98,12 +98,11 @@ static void vi_visual_region(EditState *s, int *p1, int *p2)
{
int a = s->vi_visual_start;
int c = s->offset;
int save, tmp;
int save = s->offset, tmp;
if (a > c) { tmp = a; a = c; c = tmp; }
if (s->vi_visual_linewise) {
save = s->offset;
s->offset = a; do_bol(s); a = s->offset;
s->offset = save; do_eol(s); c = s->offset;
s->offset = c; do_eol(s); c = s->offset;
s->offset = save;
c = vi_include_newline(s->b, c);
} else {
@ -123,20 +122,31 @@ static void vi_visual_region(EditState *s, int *p1, int *p2)
* The cursor (s->offset) is the moving end of the selection; only the
* mark is adjusted so motions keep their natural arithmetic and the
* yank/delete region can always be recomputed from anchor + cursor.
* Linewise snaps the cursor to EOL of the last selected line. */
* Linewise is bidirectional: cursor at/below the anchor snaps to EOL
* of the cursor line, cursor above the anchor snaps to BOL of the
* cursor line (mark holds the anchor end in both cases). */
static void vi_visual_update(EditState *s)
{
int a = s->vi_visual_start;
int c = s->offset;
int save, tmp;
if (a > c) { tmp = a; a = c; c = tmp; }
int save;
if (s->vi_visual_linewise) {
save = s->offset;
s->offset = a; do_bol(s); a = s->offset;
s->offset = save; do_eol(s); c = s->offset;
s->b->mark = a;
s->offset = c;
if (c >= a) {
save = c;
s->offset = a; do_bol(s); a = s->offset;
s->offset = save; do_eol(s); c = s->offset;
s->b->mark = a;
s->offset = c;
} else {
save = c;
s->offset = a; do_eol(s); a = s->offset;
s->offset = save; do_bol(s); c = s->offset;
s->b->mark = a;
s->offset = c;
}
} else {
int tmp;
if (a > c) { tmp = a; a = c; c = tmp; }
s->b->mark = a;
}
s->region_style = QE_STYLE_REGION_HILITE;
@ -172,6 +182,22 @@ static void vi_visual_toggle(EditState *s, int linewise)
}
}
/* Yank the current whole line (vim `yy`) without deleting it. */
static void vi_yank_whole_line(EditState *s)
{
int save = s->offset;
int p1, p2;
do_bol(s); p1 = s->offset;
do_eol(s); p2 = s->offset;
p2 = vi_include_newline(s->b, p2);
s->offset = save;
if (p1 != p2) {
do_kill(s, p1, p2, 0, 1);
vi_yank_linewise[s->qs->yank_current] = 1;
s->qs->last_cmd_func = NULL;
}
}
/* Yank the visual region and exit. */
static void vi_visual_yank(EditState *s)
{
@ -562,7 +588,7 @@ static int vi_normal_key(EditState *s, int key)
/* Pending multi-key commands (dd, gg, >>, <<, ...).
* Mode-switching keys cancel the pending state and are processed
* normally so e.g. "d:q!" does the right thing. */
if (s->vi_pending == 'd') {
if (s->vi_pending == 'd') {
if (key == 'd') {
do_kill_whole_line(s, 1);
vi_yank_linewise[s->qs->yank_current] = 1;
@ -577,6 +603,20 @@ static int vi_normal_key(EditState *s, int key)
vi_set_pending(s, 0);
return 1;
}
if (s->vi_pending == 'y') {
if (key == 'y') {
vi_yank_whole_line(s);
} else if (key == ':' || key == 'i' || key == 'a' ||
key == 'o' || key == 'O' || key == 'v' ||
key == 'V' || key == 'd' || key == 'p') {
vi_set_pending(s, 0);
return vi_normal_key(s, key);
} else {
put_status(s, "Unknown y command");
}
vi_set_pending(s, 0);
return 1;
}
if (s->vi_pending == 'g') {
if (key == 'g') {
do_bof(s);
@ -803,7 +843,7 @@ static int vi_normal_key(EditState *s, int key)
if (s->vi_visual_active)
vi_visual_yank(s);
else
put_status(s, "Use v/V then y to yank");
vi_set_pending(s, 'y');
return 1;
case 'd':
if (s->vi_visual_active) {

View file

@ -497,6 +497,12 @@ TESTS = [
b'aaa\nbbb\nccc\n\naaa\nbbb\n', cat='visual'),
T('vline_bwd_delete', b'G V k d:wq\r', 'aaa\nbbb\nccc\n',
b'aaa\nbbb\n', cat='visual'),
T('vline_up_delete', b'j V k d:wq\r', 'aaa\nbbb\nccc\n',
b'ccc\n', cat='visual'),
T('vline_up_yank_put_eof', b'j V k y G p:wq\r', 'aaa\nbbb\nccc\n',
b'aaa\nbbb\nccc\naaa\nbbb\n', cat='visual'),
T('vline_up2_delete', b'G V k k d:wq\r', 'aaa\nbbb\nccc\n',
b'aaa\n', cat='visual'),
# ---- put / register types ----
T('put_charwise_eol', b'v l y j $ p:wq\r', 'abcd\nefgh\n',