From 702fcedf2d1536ffb4a3e04e9be6fd1417d18e9db299d70d0a36e746fdc047da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= Date: Tue, 1 Dec 2026 13:59:37 +0100 Subject: [PATCH] line-read: Tab lists the candidates when it can add nothing; 0.2.1 As fish does: a second Tab is no longer needed. Co-Authored-By: Claude Opus 5.5 --- manifest.bjodat | 2 +- src/line.bjo | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/manifest.bjodat b/manifest.bjodat index 9d9d78b..3559c05 100644 --- a/manifest.bjodat +++ b/manifest.bjodat @@ -1,6 +1,6 @@ (package (name (bjoterm)) - (version "0.2.0") + (version "0.2.1") (description "The terminal for Bjolang programs: raw mode, key events and escape sequences. Linux.") (license "MPL-2.0") diff --git a/src/line.bjo b/src/line.bjo index 53840bc..96e2405 100644 --- a/src/line.bjo +++ b/src/line.bjo @@ -106,13 +106,10 @@ ;; - `killing?`: the last key killed text, so the next kill adds to `kill`. ;; - `hist-at`: the history entry shown; the history's length for the ;; input being written, which is kept in `draft` meanwhile. -;; - `tabbed?`: the last key was Tab and completed nothing more, so the next -;; Tab lists the candidates. (type (: State (Record (: text (Vec string)) (: cursor int) (: kill string) (: killing? bool) (: hist-at int) (: draft (Vec string)) - (: search (Option Search)) - (: tabbed? bool)))) + (: search (Option Search))))) ;; What one key does. (type (: Step (Union (: Edited State) @@ -235,8 +232,9 @@ ;; M-d (the word after); C-y yanks. C-t swaps two characters. ;; - History: Up and Down on the first and last line, C-p, C-n; C-r ;; searches back, again C-r for an older match, C-g ends the search. -;; - Tab completes with `#:completer`, and a second Tab lists the -;; candidates. Without a completer it inserts a tab. +;; - Tab completes with `#:completer`: it inserts the candidates' common +;; prefix, or lists them when that adds nothing, as fish does. Without +;; a completer it inserts a tab. ;; - A suggestion from `#:suggester`: at the end of the input, Right, C-f, ;; End and C-e accept all of it; M-f, C-Right and M-Right one word. ;; - Enter accepts (see `#:input-done?`), M-Enter and C-j start a new line, @@ -282,7 +280,7 @@ (def text (clusters initial)) (State (text text) (cursor (vec-length text)) (kill "") (killing? #f) (hist-at (vec-length (record-ref ed history))) (draft []) - (search None) (tabbed? #f))) + (search None))) (: (-> LineEditor Terminal string string (Option (-> (Vec string))) string LineResult)) (defun (edit-loop ed term prompt cont notices initial) @@ -386,7 +384,7 @@ (_ unit)) result)))) -;; The list of candidates that a second Tab writes, each row ended by "\n". +;; The list of candidates that Tab writes, each row ended by "\n". ;; - Without descriptions: in columns, as `columns`. ;; - With descriptions: one candidate a row, its description after it, ;; dimmed and cut to fit `width`. The candidates' column is as wide as @@ -821,8 +819,8 @@ (Finished st (LineText text)) (Edited (insert st "\n")))) -(: (-> LineEditor State bool Step)) -(defun (complete ed st tabbed?) +(: (-> LineEditor State Step)) +(defun (complete ed st) (match (record-ref ed completer) (None (Edited (insert st "\t"))) ((Some completer) @@ -841,8 +839,7 @@ (def common (common-prefix candidates)) (cond ((> (vec-length (clusters common)) k) (Edited (replace-with common))) - (tabbed? (ShowList st candidates (record-ref c descriptions))) - (else (Bell (record-set st (tabbed? #t)))))))))) + (else (ShowList st candidates (record-ref c descriptions))))))))) ;; The next older match of `query` from history index `from` down, or None. (: (-> LineEditor string int (Option (Tuple int int)))) @@ -905,7 +902,7 @@ (: (-> LineEditor State TermEvent Step)) (defun (editing ed prev ev) ;; The flags hold only for the key after the one that set them. - (def st (record-set prev (killing? #f) (tabbed? #f))) + (def st (record-set prev (killing? #f))) (def killing? (record-ref prev killing?)) (def cursor (record-ref st cursor)) (def n (vec-length (record-ref st text))) @@ -986,8 +983,8 @@ (def text (vec-set (vec-set (record-ref st text) (- i 1) b) i a)) (Edited (record-set st (text text) (cursor (+ i 1))))))) ;; Completion, the screen, and the program. - ((Tuple KeyTab (Tuple #f #f)) (complete ed st (record-ref prev tabbed?))) - ((Tuple (KeyChar #\i) (Tuple #t #f)) (complete ed st (record-ref prev tabbed?))) + ((Tuple KeyTab (Tuple #f #f)) (complete ed st)) + ((Tuple (KeyChar #\i) (Tuple #t #f)) (complete ed st)) ((Tuple (KeyChar #\l) (Tuple #t #f)) (ClearScreen st)) ((Tuple (KeyChar #\z) (Tuple #t #f)) (if (record-ref ed suspend?) (SuspendNow st) (Bell st))) (_ (Bell st))))))