diff --git a/TeXmacs/progs/math/math-edit.scm b/TeXmacs/progs/math/math-edit.scm index bff9ba3fba..8115f6dbe4 100644 --- a/TeXmacs/progs/math/math-edit.scm +++ b/TeXmacs/progs/math/math-edit.scm @@ -811,17 +811,29 @@ list | boolean (cond ((not (pair? body)) #f) ((null? (cdr body)) #f) - ((not (string? (cadr body))) #f) (else - (let ((func-name (car body)) - (arg (cadr body))) + (let ((func-name (car body))) (case func-name ;; Case 1: math-big-operator (处理积分、求和等大运算符) ;; 转换目标: "" (TeXmacs 内部字体图标名) ((math-big-operator) - `(symbol-completion - ,(string-append ""))) - + (and (string? (cadr body)) + `(symbol-completion + ,(string-append "")))) + ;; Case 2: make-lprime (左上标/prime 符号) + ((make-lprime) + (and (string? (cadr body)) + `(symbol-completion ,(cadr body)))) + ;; Case 3: math-bracket-open (括号对) + ;; 提取左右括号并组合为 "lb…rb" 格式,确保每个变体唯一 + ((math-bracket-open) + (and (>= (length (cdr body)) 2) + (string? (cadr body)) + (string? (caddr body)) + (let ((lb (cadr body)) + (rb (caddr body))) + `(symbol-completion + ,(string-append lb rb))))) ;; 预留位置:可以在此添加其他函数的处理逻辑 (else #f))))))))))) @@ -894,9 +906,13 @@ list | boolean (kbd-sym (and (pair? kbd-res) (car kbd-res))) ;; primary-sym 是当前已输入的符号 (pre 的绑定) (primary-sym kbd-sym) - (base (if (string? primary-sym) - `((symbol-completion ,primary-sym)) - '())) + (base (cond + ((string? primary-sym) + `((symbol-completion ,primary-sym))) + ((procedure? primary-sym) + (let ((sym (function-to-symbol kbd-res))) + (if sym (list sym) '()))) + (else '()))) ;; 使用新的 kbd-find-prefix-tab 获取所有 tab 切换候选 (tab-pairs (kbd-find-prefix-tab pre))) (let ((others (filter-map (lambda (pair) @@ -905,13 +921,17 @@ list | boolean `(symbol-completion ,(car val)) (function-to-symbol val)))) tab-pairs))) - (if (string? primary-sym) - (let ((filtered (filter (lambda (entry) - (or (not (pair? entry)) - (not (= (length entry) 2)) - (not (string? (cadr entry))) - (not (string=? (cadr entry) primary-sym)))) - others))) + (if (not (null? base)) + (let* ((primary-name (and (pair? (car base)) + (= (length (car base)) 2) + (cadr (car base)))) + (filtered (filter (lambda (entry) + (or (not (pair? entry)) + (not (= (length entry) 2)) + (not (string? (cadr entry))) + (not primary-name) + (not (string=? (cadr entry) primary-name)))) + others))) (append base filtered)) '()))))) diff --git a/devel/222_49.md b/devel/222_49.md new file mode 100644 index 0000000000..3580c35285 --- /dev/null +++ b/devel/222_49.md @@ -0,0 +1,73 @@ +# [222_49] Enable Tab cycle popup for backtick, brackets, and pipe in math mode + +### What +The `tabcycle-symbols` function in math mode only handled string-type keyboard +bindings, returning an empty list for keys bound to procedures. Extended +`lambda-to-symbol` to support `make-lprime` and `math-bracket-open`, and modified +`tabcycle-symbols` to handle procedure-bound primary symbols, enabling the Tab +cycle focus box for `` ` ``, `[`, and `|`. + +### Why +Typing backtick (`` ` ``), open square bracket (`[`), or vertical bar (`|`) in +math mode did not show the Tab cycle popup, even though these keys have Tab +variants defined in `math-kbd.scm`. Users could not discover or cycle through +bracket/prime variants using Tab. + +### How +In `TeXmacs/progs/math/math-edit.scm`: + +1. **Extended `lambda-to-symbol`** (line 801-839) to handle `make-lprime` and + `math-bracket-open`. For brackets, both left and right bracket arguments are + concatenated to produce unique representations (e.g., `[]`, `[[`, `]]`, `][`): + +```diff + (case func-name + ((math-big-operator) +- `(symbol-completion +- ,(string-append ""))) +- (else #f)) ++ (and (string? (cadr body)) ++ `(symbol-completion ++ ,(string-append "")))) ++ ((make-lprime) ++ (and (string? (cadr body)) ++ `(symbol-completion ,(cadr body)))) ++ ((math-bracket-open) ++ (and (>= (length (cdr body)) 2) ++ (string? (cadr body)) ++ (string? (caddr body)) ++ (let ((lb (cadr body)) ++ (rb (caddr body))) ++ `(symbol-completion ++ ,(string-append lb rb))))) ++ (else #f)) +``` + +2. **Modified `tabcycle-symbols`** (line 909-915) to handle procedure bindings + via `function-to-symbol`: + +```diff +-(base (if (string? primary-sym) +- `((symbol-completion ,primary-sym)) +- '())) ++(base (cond ++ ((string? primary-sym) ++ `((symbol-completion ,primary-sym))) ++ ((procedure? primary-sym) ++ (let ((sym (function-to-symbol kbd-res))) ++ (if sym (list sym) '()))) ++ (else '()))) +``` + +3. **Fixed deduplication filter** (line 924-934) to extract `primary-name` from + `base` instead of using `primary-sym` directly, preventing crashes when + `primary-sym` is a procedure. + +## How to test +1. Open Mogan Editor +2. Enter math mode by pressing `$` +3. Type `` ` `` (backtick) — verify a Tab cycle popup appears showing prime variants +4. Press Tab to cycle through the variants (`` ` ``, `'`, `*`, etc.) +5. Type `[` — verify a popup appears showing bracket pair variants (`[]`, `[[`, `]]`, `][`) +6. Type `|` — verify a popup appears showing pipe variants +7. Type `a` — verify the existing Tab cycle behavior (`a` → `α`) still works correctly