|
756 | 756 | (set-message "Only implemented for complete subtrees" |
757 | 757 | "correct formula")) |
758 | 758 | (math-manually-correct-tree (buffer-tree)))) |
| 759 | + |
| 760 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 761 | +;; Tab cycling completion |
| 762 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 763 | + |
| 764 | +(define (tabcycle-symbols comb) |
| 765 | + ;; 根据按键序列获取数学符号Tab循环展示的列表 |
| 766 | + ;; 输入: |
| 767 | + ;; comb: 按键序列,类型为string,如"b tab" |
| 768 | + ;; 处理过程: |
| 769 | + ;; 1. 裁剪comb获得最基本的按键序列,例如“space b tab” -> "b" |
| 770 | + ;; 2. 查找该按键序列对应的符号绑定 |
| 771 | + ;; 3. 如果绑定不存在,返回空列表 |
| 772 | + ;; 4. 如果绑定存在,继续查找所有以该按键序列为前缀的符号绑定 |
| 773 | + ;; 5. 返回所有找到的符号绑定列表,例如((symbol "<alpha>")) |
| 774 | + ;; 输出: |
| 775 | + ;; 符号列表,格式为((symbol "符号") ...) |
| 776 | + (if (not (kbd-find-key-binding comb)) '() |
| 777 | + (let* ((pre (string-replace (string-replace comb " tab" "") "space " "")) |
| 778 | + (kbd-res (kbd-find-key-binding pre)) |
| 779 | + (kbd-sym (and (pair? kbd-res) (car kbd-res)))) |
| 780 | + (append |
| 781 | + (if kbd-sym `((symbol ,kbd-sym)) '()) |
| 782 | + (reverse |
| 783 | + (map (lambda (x) `(symbol ,(and (pair? x) (pair? (cdr x)) (cadadr x)))) |
| 784 | + (list-sort |
| 785 | + (filter |
| 786 | + (lambda (x) |
| 787 | + (and (pair? x) |
| 788 | + (string? (car x)) |
| 789 | + (string-ends? (car x) "tab") |
| 790 | + (string=? (string-replace (car x) " tab" "") pre))) |
| 791 | + (kbd-find-prefix pre)) |
| 792 | + (lambda (x y) |
| 793 | + (and (pair? x) (pair? y) |
| 794 | + (string>? (car x) (car y))))))))))) |
| 795 | + |
| 796 | +(define (highlight-tabcycle-symbols lst comb) |
| 797 | + ;; 高亮显示Tab循环符号列表中符合按键序列的符号 |
| 798 | + ;; 输入: |
| 799 | + ;; lst: 符号列表,格式为((symbol "符号") ...) |
| 800 | + ;; comb: 按键序列,类型为string,如"b tab" |
| 801 | + ;; 输出: |
| 802 | + ;; 符号列表,格式为((symbol "符号") (symbol* "符号") ...), |
| 803 | + ;; 其中 symbol* 表示高亮显示的符号,参见 make-menu-symbol 中的定义 |
| 804 | + (let ((bind (let ((res (kbd-find-key-binding comb))) |
| 805 | + (and res (car res))))) |
| 806 | + (if (string? bind) |
| 807 | + (map (lambda (x) (if (and bind |
| 808 | + (pair? x) |
| 809 | + (eq? (car x) 'symbol) |
| 810 | + (string=? (cadr x) bind)) |
| 811 | + (list 'symbol* bind) x)) |
| 812 | + lst) |
| 813 | + lst))) |
| 814 | + |
| 815 | +(tm-define (math-tabcycle-symbols comb) |
| 816 | + ;; 根据按键序列获取数学符号Tab循环展示的列表 |
| 817 | + ;; 输入: |
| 818 | + ;; comb: 按键序列,类型为string,如"b tab" |
| 819 | + ;; 输出: |
| 820 | + ;; 符号列表,格式为((symbol "符号") (symbol* "符号") ...) |
| 821 | + (if (in-math?) |
| 822 | + (highlight-tabcycle-symbols (tabcycle-symbols comb) comb) |
| 823 | + '())) |
| 824 | + |
| 825 | +(tm-define (math-variant comb) |
| 826 | + ;; 触发数学符号Tab循环的展示 |
| 827 | + ;; 输入: |
| 828 | + ;; comb: 按键序列,类型为string,如"b tab" |
| 829 | + (if (in-math?) |
| 830 | + (set-auxiliary-widget |
| 831 | + (make-menu-widget |
| 832 | + `((tile 99 (link (lambda () (math-tabcycle-symbols ,comb))))) 0) |
| 833 | + "Math")) |
| 834 | + (noop)) |
0 commit comments