Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions TeXmacs/progs/math/math-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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 (处理积分、求和等大运算符)
;; 转换目标: "<big-int-2>" (TeXmacs 内部字体图标名)
((math-big-operator)
`(symbol-completion
,(string-append "<big-" arg "-2>")))

(and (string? (cadr body))
`(symbol-completion
,(string-append "<big-" (cadr body) "-2>"))))
;; 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)))))))))))
Expand Down Expand Up @@ -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)
Expand All @@ -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))
'())))))

Expand Down
73 changes: 73 additions & 0 deletions devel/222_49.md
Original file line number Diff line number Diff line change
@@ -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 "<big-" arg "-2>")))
- (else #f))
+ (and (string? (cadr body))
+ `(symbol-completion
+ ,(string-append "<big-" (cadr body) "-2>"))))
+ ((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