diff --git a/TeXmacs/progs/text/text-edit.scm b/TeXmacs/progs/text/text-edit.scm index 0215554dc6..85b4a77fa4 100644 --- a/TeXmacs/progs/text/text-edit.scm +++ b/TeXmacs/progs/text/text-edit.scm @@ -13,10 +13,12 @@ (texmacs-module (text text-edit) (:use (utils library tree) - (utils edit variants) - (utils edit selections) - (text text-drd) - (generic format-edit))) + (utils edit variants) + (utils edit selections) + (text text-drd) + (generic format-edit) + ) ;:use +) ;texmacs-module ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Style package rules @@ -24,30 +26,47 @@ (tm-define (style-category p) (:require (in? p (list "modern-program" "centered-program" "framed-program"))) - :program-theme) + :program-theme +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Inserting a title and an abstract ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (tm-define (document-propose-title?) - (with bt (buffer-tree) - (with brothers (map tree-label (tree-children bt)) - (and-with t (tree-ref bt :down) - (and (== (cursor-path) `(0 0 0)) - (tree-is? bt 'document) - (match? (cursor-tree) "") - (not (in? 'doc-data brothers)) - (not (style-has? "beamer-style"))))))) + (with bt + (buffer-tree) + (with brothers + (map tree-label (tree-children bt)) + (and-with t + (tree-ref bt :down) + (and (== (cursor-path) '(0 0 0)) + (tree-is? bt 'document) + (match? (cursor-tree) "") + (not (in? 'doc-data brothers)) + (not (style-has? "beamer-style")) + ) ;and + ) ;and-with + ) ;with + ) ;with +) ;tm-define (tm-define (document-propose-abstract?) - (with bt (buffer-tree) - (with brothers (map tree-label (tree-children bt)) - (and-with t (tree-ref bt :down) + (with bt + (buffer-tree) + (with brothers + (map tree-label (tree-children bt)) + (and-with t + (tree-ref bt :down) (and (tree-is? bt 'document) - (match? (cursor-tree) "") - (in? 'doc-data brothers) - (not (in? 'abstract-data brothers))))))) + (match? (cursor-tree) "") + (in? 'doc-data brothers) + (not (in? 'abstract-data brothers)) + ) ;and + ) ;and-with + ) ;with + ) ;with +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Inserting document, author and abstract data @@ -55,162 +74,224 @@ (tm-define (doc-title-context? t) (and (tree-search-upwards t 'doc-data) - (or (tree-in? t (doc-title-tag-list)) - (and (tree-is? t 'date) (tree-is? t :up 'doc-date))))) + (or (tree-in? t (doc-title-tag-list)) + (and (tree-is? t 'date) (tree-is? t :up 'doc-date)) + ) ;or + ) ;and +) ;tm-define (tm-define (doc-author-context? t) - (and (tree-search-upwards t 'doc-data) - (tree-in? t (author-data-tag-list)))) + (and (tree-search-upwards t 'doc-data) (tree-in? t (author-data-tag-list))) +) ;tm-define -(define doc-data-inactive-tags - (doc-title-inactive-tag-list)) +(define doc-data-inactive-tags (doc-title-inactive-tag-list)) (tm-define (make-doc-data) (:applicable (not (selection-active-non-small?))) - (insert-go-to '(doc-data (doc-title "")) '(0 0 0))) + (insert-go-to '(doc-data (doc-title "")) '(0 0 0)) +) ;tm-define (tm-define (make-doc-data-element l) - (with-innermost t 'doc-data - (with pos (1+ (tree-down-index t)) + (with-innermost t + 'doc-data + (with pos + (1+ (tree-down-index t)) (cond ((== l 'doc-author) (tree-insert! t pos `((,l (author-data (author-name ""))))) - (tree-go-to t pos 0 0 0 0)) + (tree-go-to t pos 0 0 0 0) + ) ; ((== l 'doc-note) (tree-insert! t pos `((,l (document "")))) - (tree-go-to t pos 0 0 0)) - ((== l 'doc-title-options) - (tree-insert! t pos `((,l)))) + (tree-go-to t pos 0 0 0) + ) ; + ((== l 'doc-title-options) (tree-insert! t pos `((,l)))) ((in? l doc-data-inactive-tags) - (let* ((r (tree-search t (cut tree-is? <> l))) - (x (and (pair? r) (car r)))) + (let* ((r (tree-search t (cut tree-is? <> l))) (x (and (pair? r) (car r)))) (cond ((not x) - (tree-insert! t pos `((doc-inactive (,l "")))) - (tree-go-to t pos 0 0 0)) - (else - (tree-set! x `(doc-inactive ,x)) - (tree-go-to x 0 0 :end))))) - (else - (tree-insert! t pos `((,l ""))) - (tree-go-to t pos 0 0)))))) + (tree-insert! t pos `((doc-inactive (,l ,"")))) + (tree-go-to t pos 0 0 0) + ) ; + (else (tree-set! x `(doc-inactive ,x)) (tree-go-to x 0 0 :end)) + ) ;cond + ) ;let* + ) ; + (else (tree-insert! t pos `((,l ,""))) (tree-go-to t pos 0 0)) + ) ;cond + ) ;with + ) ;with-innermost +) ;tm-define (tm-define (make-author-data-element l) - (with-innermost t 'author-data - (with pos (1+ (tree-down-index t)) + (with-innermost t + 'author-data + (with pos + (1+ (tree-down-index t)) (cond ((in? l '(author-affiliation author-note)) (tree-insert! t pos `((,l (document "")))) - (tree-go-to t pos 0 0 0)) - (else - (tree-insert! t pos `((,l ""))) - (tree-go-to t pos 0 0)))))) + (tree-go-to t pos 0 0 0) + ) ; + (else (tree-insert! t pos `((,l ,""))) (tree-go-to t pos 0 0)) + ) ;cond + ) ;with + ) ;with-innermost +) ;tm-define -(tm-define (abstract-data-context? t) - (tree-in? t (abstract-data-tag-list))) +(tm-define (abstract-data-context? t) (tree-in? t (abstract-data-tag-list))) (tm-define (make-abstract-data) - (insert-go-to '(abstract-data (abstract "")) '(0 0 0))) + (insert-go-to '(abstract-data (abstract "")) '(0 0 0)) +) ;tm-define (tm-define (make-abstract-data-element l) - (with-innermost t 'abstract-data - (with pos (1+ (tree-down-index t)) - (tree-insert! t pos `((,l ""))) - (tree-go-to t pos 0 0)))) + (with-innermost t + 'abstract-data + (with pos + (1+ (tree-down-index t)) + (tree-insert! t pos `((,l ,""))) + (tree-go-to t pos 0 0) + ) ;with + ) ;with-innermost +) ;tm-define (tm-define (kbd-space-bar t shift?) - (:require (and (tree-is-buffer? t) (in-text?) - (!= (get-env "language") "verbatim"))) - (let* ((b (before-cursor)) - (p (get-preference "text spacebar"))) - (cond ((== p "allow multiple spaces") - (insert " ")) - ((and (== b " ") (== p "no multiple spaces")) - (noop)) - ((== b " ") - (remove-text #f) - (make-space "1em")) + (:require (and (tree-is-buffer? t) (in-text?) (!= (get-env "language") "verbatim")) + ) ;:require + (let* ((b (before-cursor)) (p (get-preference "text spacebar"))) + (cond ((== p "allow multiple spaces") (insert " ")) + ((and (== b " ") (== p "no multiple spaces")) (noop)) + ((== b " ") (remove-text #f) (make-space "1em")) ((and (tree? b) (tree-func? b 'space 1)) (if (and (tree-atomic? (tree-ref b 0)) - (string-ends? (tree->string (tree-ref b 0)) "em")) - (make-space "1em") - (geometry-horizontal b #t))) - (else (insert " "))))) + (string-ends? (tree->string (tree-ref b 0)) "em") + ) ;and + (make-space "1em") + (geometry-horizontal b #t) + ) ;if + ) ; + (else (insert " ")) + ) ;cond + ) ;let* +) ;tm-define (tm-define (kbd-enter t shift?) (:require (tree-is? t 'title)) (go-end-line) - (insert-return)) + (insert-return) +) ;tm-define (tm-define (kbd-enter t shift?) (:require (tree-is? t 'doc-title)) - (make-doc-data-element 'doc-author)) + (make-doc-data-element 'doc-author) +) ;tm-define (tm-define (kbd-enter t shift?) (:require (tree-is? t 'author-name)) - (make-author-data-element 'author-affiliation)) + (make-author-data-element 'author-affiliation) +) ;tm-define (tm-define (kbd-enter t shift?) - (:require (or - (tree-is? t 'abstract-arxiv) + (:require (or (tree-is? t 'abstract-arxiv) (tree-is? t 'abstract-pacs) (tree-is? t 'abstract-acm) (tree-is? t 'abstract-msc) - (tree-is? t 'abstract-keywords))) - (with t (tree-search-upwards - t '(abstract-msc abstract-acm abstract-pacs - abstract-arxiv abstract-keywords)) - (with pos (1+ (tree-down-index t)) - (tree-insert! t pos `((concat ""))) - (tree-go-to t pos 0 0)))) + (tree-is? t 'abstract-keywords) + ) ;or + ) ;:require + (with t + (tree-search-upwards t + '(abstract-msc abstract-acm + abstract-pacs + abstract-arxiv + abstract-keywords) + ) ;tree-search-upwards + (with pos + (1+ (tree-down-index t)) + (tree-insert! t pos '((concat ""))) + (tree-go-to t pos 0 0) + ) ;with + ) ;with +) ;tm-define (tm-define (kbd-enter t shift?) (:require (tree-is? t 'doc-inactive)) - (doc-data-activate-here)) + (doc-data-activate-here) +) ;tm-define (tm-define (doc-data-clean t) (for (c (reverse (tree-children t))) - (cond ((tree-empty? c) - (tree-remove t (tree-index c) 1)) - ((and (tree-func? c 'doc-author 1) - (tree-empty? (tree-ref c 0))) - (tree-remove t (tree-index c) 1)) - ((and (tree-func? c 'doc-author 1) - (tm-is? (tree-ref c 0) 'author-data)) - (doc-data-clean (tree-ref c 0)))))) + (cond ((tree-empty? c) (tree-remove t (tree-index c) 1)) + ((and (tree-func? c 'doc-author 1) (tree-empty? (tree-ref c 0))) + (tree-remove t (tree-index c) 1) + ) ; + ((and (tree-func? c 'doc-author 1) (tm-is? (tree-ref c 0) 'author-data)) + (doc-data-clean (tree-ref c 0)) + ) ; + ) ;cond + ) ;for +) ;tm-define (tm-define (kbd-remove t forwards?) (:require (tree-search-upwards t 'doc-data)) - (with d (tree-search-upwards t 'doc-data) + (with d + (tree-search-upwards t 'doc-data) (former t forwards?) (when (and (tree->path d) (tree-is? d 'doc-data)) - (doc-data-clean d)))) + (doc-data-clean d) + ) ;when + ) ;with +) ;tm-define (tm-define (set-doc-title-options opts) - (with-innermost t 'doc-data - (with opts-trees (select t '(doc-title-options)) + (with-innermost t + 'doc-data + (with opts-trees + (select t '(doc-title-options)) (if (null? opts) - (when (nnull? opts-trees) - (with old (car opts-trees) - (tree-remove (tree-up old) (tree-index old) 1))) - (begin - (when (null? opts-trees) - (make-doc-data-element 'doc-title-options) - (set! opts-trees (select t '(doc-title-options)))) - (tree-set (car opts-trees) `(doc-title-options ,@opts))))))) + (when (nnull? opts-trees) + (with old (car opts-trees) (tree-remove (tree-up old) (tree-index old) 1)) + ) ;when + (begin + (when (null? opts-trees) + (make-doc-data-element 'doc-title-options) + (set! opts-trees (select t '(doc-title-options))) + ) ;when + (tree-set (car opts-trees) `(doc-title-options ,@opts)) + ) ;begin + ) ;if + ) ;with + ) ;with-innermost +) ;tm-define (tm-define (get-doc-title-options) - (with-innermost t 'doc-data - (with opts-trees (select t '(doc-title-options :%1)) - (map tree->stree opts-trees)))) + (with-innermost t + 'doc-data + (with opts-trees + (select t '(doc-title-options :%1)) + (map tree->stree opts-trees) + ) ;with + ) ;with-innermost +) ;tm-define (tm-define (test-doc-title-clustering? mode) - (with cl (list "cluster-all" "cluster-by-affiliation") - (with old (get-doc-title-options) - (if mode (in? mode old) (null? (list-intersection cl old)))))) + (with cl + (list "cluster-all" "cluster-by-affiliation") + (with old + (get-doc-title-options) + (if mode (in? mode old) (null? (list-intersection cl old))) + ) ;with + ) ;with +) ;tm-define (tm-define (set-doc-title-clustering mode) (:check-mark "*" test-doc-title-clustering?) - (with cl (list "cluster-all" "cluster-by-affiliation") - (with old (list-difference (get-doc-title-options) cl) - (set-doc-title-options (if mode (cons mode old) old))))) + (with cl + (list "cluster-all" "cluster-by-affiliation") + (with old + (list-difference (get-doc-title-options) cl) + (set-doc-title-options (if mode (cons mode old) old)) + ) ;with + ) ;with +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Activation and disactivation @@ -218,53 +299,80 @@ (define (doc-data-go-to-active t i) (cond ((< i 0) (tree-go-to t :end)) - ((tree-in? t i (doc-title-inactive-tag-list)) - (doc-data-go-to-active t (- i 1))) - ((not (cursor-inside? (tree-ref t i))) - (tree-go-to t i :end)))) + ((tree-in? t i (doc-title-inactive-tag-list)) (doc-data-go-to-active t (- i 1))) + ((not (cursor-inside? (tree-ref t i))) (tree-go-to t i :end)) + ) ;cond +) ;define (tm-define (doc-data-activate-here) - (with-innermost dd 'doc-data - (with-innermost t 'doc-inactive + (with-innermost dd + 'doc-data + (with-innermost t + 'doc-inactive (tree-remove-node! t 0) - (doc-data-go-to-active dd (tree-down-index dd))))) + (doc-data-go-to-active dd (tree-down-index dd)) + ) ;with-innermost + ) ;with-innermost +) ;tm-define (tm-define (doc-data-has-hidden?) - (with-innermost t 'doc-data - (with l (cdr (tree->list t)) - (with fun (lambda (t) (or (tree-in? t (doc-title-inactive-tag-list)) - (tree-is? t 'doc-inactive))) - (list-or (map fun l)))))) + (with-innermost t + 'doc-data + (with l + (cdr (tree->list t)) + (with fun + (lambda (t) + (or (tree-in? t (doc-title-inactive-tag-list)) (tree-is? t 'doc-inactive)) + ) ;lambda + (list-or (map fun l)) + ) ;with + ) ;with + ) ;with-innermost +) ;tm-define (tm-define (doc-data-deactivated?) - (with-innermost t 'doc-data - (with l (cdr (tree->list t)) - (list-or (map (lambda (t) (== (tm-car t) 'doc-inactive)) l))))) + (with-innermost t + 'doc-data + (with l + (cdr (tree->list t)) + (list-or (map (lambda (t) (== (tm-car t) 'doc-inactive)) l)) + ) ;with + ) ;with-innermost +) ;tm-define (define (doc-data-activate-one t) (when (tree-is? t 'doc-inactive) - (tree-remove-node! t 0))) + (tree-remove-node! t 0) + ) ;when +) ;define (tm-define (doc-data-activate-all) - (with-innermost t 'doc-data - (with i (tree-down-index t) - (with l (cdr (tree->list t)) - (for-each doc-data-activate-one l)) - (doc-data-go-to-active t i)))) + (with-innermost t + 'doc-data + (with i + (tree-down-index t) + (with l (cdr (tree->list t)) (for-each doc-data-activate-one l)) + (doc-data-go-to-active t i) + ) ;with + ) ;with-innermost +) ;tm-define (define (doc-data-deactivate-one t) (if (in? (tm-car t) doc-data-inactive-tags) - (tree-insert-node! t 0 '(doc-inactive)))) + (tree-insert-node! t 0 '(doc-inactive)) + ) ;if +) ;define (tm-define (doc-data-deactivate-all) - (with-innermost t 'doc-data - (with l (cdr (tree->list t)) - (for-each doc-data-deactivate-one l)))) + (with-innermost t + 'doc-data + (with l (cdr (tree->list t)) (for-each doc-data-deactivate-one l)) + ) ;with-innermost +) ;tm-define (tm-define (doc-data-activate-toggle) - (if (doc-data-deactivated?) - (doc-data-activate-all) - (doc-data-deactivate-all))) + (if (doc-data-deactivated?) (doc-data-activate-all) (doc-data-deactivate-all)) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Making letter headings or titles @@ -275,230 +383,287 @@ (if (inside? 'destination) (go-end-of 'destination)) (if (inside? 'cc) (go-end-of 'cc)) (if (inside? 'encl) (go-end-of 'encl)) - (go-end-line)) + (go-end-line) +) ;tm-define (tm-define (make-header l) (go-end-of-header-element) (if (!= (tree->stree (paragraph-tree)) "") (insert-return)) - (make l)) + (make l) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Sectional commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (tm-define (section-context? t) - (tree-in? t (numbered-unnumbered-append (section-tag-list)))) + (tree-in? t (numbered-unnumbered-append (section-tag-list))) +) ;tm-define (tm-define (previous-section) - (with bt (buffer-tree) + (with bt + (buffer-tree) (and (cursor-inside? bt) - (with bp (list-drop (cursor-path) (length (tree->path bt))) - (with sp (path-previous-section bt bp) - (and (!= sp bp) (path->tree (append (tree->path bt) sp)))))))) + (with bp + (list-drop (cursor-path) (length (tree->path bt))) + (with sp + (path-previous-section bt bp) + (and (!= sp bp) (path->tree (append (tree->path bt) sp))) + ) ;with + ) ;with + ) ;and + ) ;with +) ;tm-define (tm-define (go-to-section-title) - (and-with s (previous-section) + (and-with s + (previous-section) (when (or (section-tag? (tm-car s)) (section*-tag? (tm-car s))) - (tree-go-to s 0 :start)))) + (tree-go-to s 0 :start) + ) ;when + ) ;and-with +) ;tm-define (define (selection-trim-ending) (if (selection-active-any?) - (with st (selection-tree) - (if (and (not (tree-atomic? st )) - (tree-empty? (tree-ref st :last))) - (begin - (selection-set - (selection-get-start) - (path-previous (root-tree) (selection-get-end))) - (selection-trim-ending)))))) + (with st + (selection-tree) + (if (and (not (tree-atomic? st)) (tree-empty? (tree-ref st :last))) + (begin + (selection-set (selection-get-start) + (path-previous (root-tree) (selection-get-end)) + ) ;selection-set + (selection-trim-ending) + ) ;begin + ) ;if + ) ;with + ) ;if +) ;define (define (make-section-aux l flag) - (if (selection-active-any?) - (let - ((cp (cursor-path)) - (selstart (selection-get-start))) + (if (selection-active-any?) + (let ((cp (cursor-path)) (selstart (selection-get-start))) (selection-trim-ending) (if (tree-multi-paragraph? (selection-tree)) (set-message "make-section error" "invalid multi-paragraph selection") - (with selend (selection-get-end) + (with selend + (selection-get-end) (make l) - (if flag (make-return-before) + (if flag + (make-return-before) (if (or (path-less-eq? cp selstart) (path-less? selend cp)) ;; reposition cursor when its path still exists - (go-to cp)))))) - (if (not (make-return-after)) - (begin - (make l) - (if flag (make-return-before)))))) + (go-to cp) + ) ;if + ) ;if + ) ;with + ) ;if + ) ;let + (if (not (make-return-after)) (begin (make l) (if flag (make-return-before)))) + ) ;if +) ;define (tm-define (make-section l) (:applicable (not (selection-active-non-small?))) - (make-section-aux l #f)) + (make-section-aux l #f) +) ;tm-define -(tm-define (make-unnamed-section l) - (make-section-aux l #t)) +(tm-define (make-unnamed-section l) (make-section-aux l #t)) (tm-define (kbd-enter t shift?) (:require (section-context? t)) (tree-go-to t :end) - (insert-return)) + (insert-return) +) ;tm-define (tm-define (label-insert t) (:require (section-context? t)) (tree-go-to t :end) - (make 'label)) + (make 'label) +) ;tm-define (tm-define (focus-label t) (:require (section-context? t)) - (and-with p (tree-up t) - (and (tm-func? p 'concat) - (focus-search-label p)))) + (and-with p (tree-up t) (and (tm-func? p 'concat) (focus-search-label p))) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Routines for lists, enumerations and descriptions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (list-context? t) - (tree-in? t (list-tag-list))) +(tm-define (list-context? t) (tree-in? t (list-tag-list))) -(tm-define (itemize-context? t) - (tree-in? t (itemize-tag-list))) +(tm-define (itemize-context? t) (tree-in? t (itemize-tag-list))) -(tm-define (enumerate-context? t) - (tree-in? t (enumerate-tag-list))) +(tm-define (enumerate-context? t) (tree-in? t (enumerate-tag-list))) (tm-define (itemize-enumerate-context? t) - (or (tree-in? t (itemize-tag-list)) - (tree-in? t (enumerate-tag-list)))) + (or (tree-in? t (itemize-tag-list)) (tree-in? t (enumerate-tag-list))) +) ;tm-define (tm-define (make-tmlist l) - (with flag? (and (selection-active-non-small?) - (in? l (description-tag-list))) - (wrap-selection-any - (make l) - (if flag? (insert '(item* "")) (make-item))))) + (with flag? + (and (selection-active-non-small?) (in? l (description-tag-list))) + (wrap-selection-any (make l) (if flag? (insert '(item* "")) (make-item))) + ) ;with +) ;tm-define (define (blank-text? t) - (and (tree-atomic? t) - (== (string-trim-spaces (tree->string t)) ""))) + (and (tree-atomic? t) (== (string-trim-spaces (tree->string t)) "")) +) ;define (define (blank-tree? t) (cond ((blank-text? t) #t) ((tree-is? t 'concat) - (let loop ((i 0)) - (or (>= i (tree-arity t)) - (and (blank-tree? (tree-ref t i)) - (loop (+ i 1)))))) - (else (tree-empty? t)))) + (let loop + ((i 0)) + (or (>= i (tree-arity t)) (and (blank-tree? (tree-ref t i)) (loop (+ i 1)))) + ) ;let + ) ; + (else (tree-empty? t)) + ) ;cond +) ;define (define (left-siblings-blank-until? t stop) (or (not t) - (== t stop) - (let* ((parent (tree-up t)) - (index (and parent (tree-index t)))) - (and parent index - (let loop ((i 0)) - (or (>= i index) - (and (blank-tree? (tree-ref parent i)) - (loop (+ i 1))))) - (left-siblings-blank-until? parent stop))))) + (== t stop) + (let* ((parent (tree-up t)) (index (and parent (tree-index t)))) + (and parent + index + (let loop + ((i 0)) + (or (>= i index) (and (blank-tree? (tree-ref parent i)) (loop (+ i 1)))) + ) ;let + (left-siblings-blank-until? parent stop) + ) ;and + ) ;let* + ) ;or +) ;define (tm-define (line-start-empty-text?) - (let* ((t (cursor-tree)) - (i (cAr (cursor-path))) - (p (and t (paragraph-tree)))) + (let* ((t (cursor-tree)) (i (cAr (cursor-path))) (p (and t (paragraph-tree)))) (and t - (tree-atomic? t) - (== (string-trim-spaces (substring (tree->string t) 0 i)) "") - (left-siblings-blank-until? t p)))) + (tree-atomic? t) + (== (string-trim-spaces (substring (tree->string t) 0 i)) "") + (left-siblings-blank-until? t p) + ) ;and + ) ;let* +) ;tm-define (tm-define (make-tmlist-if-line-start l fallback) - (if (line-start-empty-text?) - (make-tmlist l) - (insert fallback))) + (if (line-start-empty-text?) (make-tmlist l) (insert fallback)) +) ;tm-define (define (list-item-marker? t) - (tree-in? t '(item item*))) + (tree-in? t '(item item*)) +) ;define (define (list-item-wrapper? t) (and (tree-is? t 'concat) - (> (tree-arity t) 0) - (list-item-marker? (tree-ref t 0)))) + (> (tree-arity t) 0) + (list-item-marker? (tree-ref t 0)) + ) ;and +) ;define (define (list-item-logical-tree t) - (if (and (list-item-marker? t) - (list-item-wrapper? (tree-up t))) - (tree-up t) - t)) + (if (and (list-item-marker? t) (list-item-wrapper? (tree-up t))) (tree-up t) t) +) ;define (define (current-list-item-tree) - (and-with item (tree-search-upwards - (cursor-tree) - (lambda (t) - (or (list-item-marker? t) - (list-item-wrapper? t)))) - (list-item-logical-tree item))) + (and-with item + (tree-search-upwards (cursor-tree) + (lambda (t) (or (list-item-marker? t) (list-item-wrapper? t))) + ) ;tree-search-upwards + (list-item-logical-tree item) + ) ;and-with +) ;define (tm-define (make-item) (if (not (make-return-after)) - (with lab (inside-which (list-tag-list)) - (cond ((in? lab (itemize-tag-list)) (make 'item)) - ((in? lab (enumerate-tag-list)) (make 'item)) - ((in? lab (description-tag-list)) (make 'item*)) - (else (make 'item)))))) + (with lab + (inside-which (list-tag-list)) + (cond ((in? lab (itemize-tag-list)) (make 'item)) + ((in? lab (enumerate-tag-list)) (make 'item)) + ((in? lab (description-tag-list)) (make 'item*)) + (else (make 'item)) + ) ;cond + ) ;with + ) ;if +) ;tm-define (tm-define (kbd-enter t shift?) - (:require (and (list-context? t) - (current-list-item-tree) - (not (in-prog?)))) - (if shift? (make-return-after) (make-item))) + (:require (and (list-context? t) (current-list-item-tree) (not (in-prog?)))) + (if shift? (make-return-after) (make-item)) +) ;tm-define (tm-define (kbd-enter t shift?) (:require (tree-is? t 'item*)) - (go-end-of 'item*)) + (go-end-of 'item*) +) ;tm-define (tm-define (focus-label t) (:require (or (list-context? t) (tree-is? t 'bib-list))) - (and-with doc (tree-down t) + (and-with doc + (tree-down t) (and (tree-is? doc 'document) - (and-with par (tree-down doc) - (focus-search-label par))))) + (and-with par (tree-down doc) (focus-search-label par)) + ) ;and + ) ;and-with +) ;tm-define (tm-define (numbered-context? t) (:require (or (itemize-context? t) (enumerate-context? t))) - #t) + #t +) ;tm-define -(tm-define (numbered-numbered? t) - (:require (enumerate-context? t)) - #t) +(tm-define (numbered-numbered? t) (:require (enumerate-context? t)) #t) (tm-define (numbered-toggle t) (:require (itemize-context? t)) - (variant-set t 'enumerate)) + (variant-set t 'enumerate) +) ;tm-define (tm-define (numbered-toggle t) (:require (enumerate-context? t)) - (variant-set t 'itemize)) + (variant-set t 'itemize) +) ;tm-define (tm-define (standard-parameters l) (:require (== l "itemize")) (list-remove (cons* "itemize-levels" - "item-tag" "item-1" "item-2" "item-3" "item-4" - (search-parameters "itemize-1")) - "itemize-level")) + "item-tag" + "item-1" + "item-2" + "item-3" + "item-4" + "item-nr" + (search-parameters "itemize-1") + ) ;cons* + "itemize-level" + ) ;list-remove +) ;tm-define (ahash-set! inhibit-global-table "item-tag" #t) (ahash-set! inhibit-local-table "item-1" #t) (ahash-set! inhibit-local-table "item-2" #t) (ahash-set! inhibit-local-table "item-3" #t) (ahash-set! inhibit-local-table "item-4" #t) +(ahash-set! inhibit-global-table "item-nr" #t) (tm-define (standard-parameters l) (:require (== l "enumerate")) (list-remove (cons* "enumerate-levels" - "enum-tag" "enum-1" "enum-2" "enum-3" "enum-4" - (search-parameters "enumerate-1")) - "enumerate-level")) + "enum-tag" + "enum-1" + "enum-2" + "enum-3" + "enum-4" + "item-nr" + (search-parameters "enumerate-1") + ) ;cons* + "enumerate-level" + ) ;list-remove +) ;tm-define (ahash-set! inhibit-global-table "enum-tag" #t) (ahash-set! inhibit-local-table "enum-1" #t) @@ -508,29 +673,42 @@ (tm-define (parameter-choice-list l) (:require (in? l (list "itemize-levels" "enumerate-levels"))) - (list "1" "2" "3" "4")) + (list "1" "2" "3" "4") +) ;tm-define (tm-define (parameter-choice-list l) (:require (== l "item-nr")) - (list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" :other)) + (list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" :other) +) ;tm-define (tm-define (parameter-choice-list l) (:require (in? l (list "item-tag" "item-1" "item-2" "item-3" "item-4"))) - (list "" "" "" "" "*" - "" "" - "" "" :other)) + (list "" + "" + "" + "" + "*" + "" + "" + "" + "" + :other + ) ;list +) ;tm-define (tm-define (parameter-choice-list l) (:require (in? l (list "enum-tag" "enum-1" "enum-2" "enum-3" "enum-4"))) (list (list "1, 2, 3, ..." '(macro "x" (arg "x"))) - (list "a, b, c, ..." '(macro "x" (number (arg "x") "alpha"))) - (list "A, B, C, ..." '(macro "x" (number (arg "x") "Alpha"))) - (list "i, ii, iii, ..." '(macro "x" (number (arg "x") "roman"))) - (list "I, II, III, ..." '(macro "x" (number (arg "x") "Roman"))) - (list "①, ②, ③, ..." '(macro "x" (number (arg "x") "circle"))) - (list "一, 二, 三, ..." '(macro "x" (number (arg "x") "hanzi"))) - (list "(1), (2), (3), ..." '(macro "x" (number (arg "x") "paren"))) - :other)) + (list "a, b, c, ..." '(macro "x" (number (arg "x") "alpha"))) + (list "A, B, C, ..." '(macro "x" (number (arg "x") "Alpha"))) + (list "i, ii, iii, ..." '(macro "x" (number (arg "x") "roman"))) + (list "I, II, III, ..." '(macro "x" (number (arg "x") "Roman"))) + (list "①, ②, ③, ..." '(macro "x" (number (arg "x") "circle"))) + (list "一, 二, 三, ..." '(macro "x" (number (arg "x") "hanzi"))) + (list "(1), (2), (3), ..." '(macro "x" (number (arg "x") "paren"))) + :other + ) ;list +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Hyphenation @@ -540,9 +718,12 @@ (:interactive #t) (:argument hyph "Hyphenate as") (:proposals hyph (list (tm->string (selection-tree)))) - (with ins `(hyphenate-as ,hyph ,(selection-tree)) + (with ins + `(hyphenate-as ,hyph ,(selection-tree)) (clipboard-cut "null") - (insert ins))) + (insert ins) + ) ;with +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Formulas @@ -551,37 +732,44 @@ (tm-define (make-equation) (:applicable (not (selection-active-non-small?))) (make 'equation) - (temp-proof-fix)) + (temp-proof-fix) +) ;tm-define (tm-define (make-equation*) (:applicable (not (selection-active-non-small?))) (make 'equation*) - (temp-proof-fix)) + (temp-proof-fix) +) ;tm-define (tm-define (make-eqnarray*) (:applicable (not (selection-active-non-small?))) (make 'eqnarray*) - (temp-proof-fix)) + (temp-proof-fix) +) ;tm-define (tm-define (make-align) (:applicable (not (selection-active-non-small?))) (make 'align) - (temp-proof-fix)) + (temp-proof-fix) +) ;tm-define (tm-define (focus-label t) (:require (tree-is? t 'equation)) - (focus-list-search-label (tree-children t))) + (focus-list-search-label (tree-children t)) +) ;tm-define (define (down-to-row t) (cond ((not (tree? t)) #f) ((tree-is? t 'row) t) ((tree-in? t '(document tformat table)) (down-to-row (tree-down t))) - (else #f))) + (else #f) + ) ;cond +) ;define (tm-define (focus-label t) (:require (tree-in? t '(eqnarray eqnarray*))) - (and-with row (down-to-row (tree-down t)) - (focus-search-label row))) + (and-with row (down-to-row (tree-down t)) (focus-search-label row)) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Routines for inserting miscellaneous content @@ -589,24 +777,36 @@ (tm-define (make-aux env var aux) (when (context-has? var) - (set! aux (get-env var))) + (set! aux (get-env var)) + ) ;when (if (not (make-return-after)) - (insert (list (string->symbol env) aux '(document ""))))) + (insert (list (string->symbol env) aux '(document ""))) + ) ;if +) ;tm-define (tm-define (make-aux* env var aux name) (when (context-has? var) - (set! aux (get-env var))) + (set! aux (get-env var)) + ) ;when (if (not (make-return-after)) - (insert (list (string->symbol env) aux name '(document ""))))) + (insert (list (string->symbol env) aux name '(document ""))) + ) ;if +) ;tm-define (define (normalized-bib-name f) - (if (string? f) f - (let* ((r (url-delta (current-buffer) f)) - (n (if (== (url-suffix r) "bib") (url-unglue r 4) r))) - (url->string n)))) + (if (string? f) + f + (let* ((r (url-delta (current-buffer) f)) + (n (if (== (url-suffix r) "bib") (url-unglue r 4) r)) + ) ; + (url->string n) + ) ;let* + ) ;if +) ;define (tm-define (automatic-section-context? t) - (tree-in? t (automatic-section-tag-list))) + (tree-in? t (automatic-section-tag-list)) +) ;tm-define (define (automatic-name-var t) (cond ((tm-func? t 'table-of-contents) "table-of-contents-text") @@ -615,483 +815,593 @@ ((tm-func? t 'the-glossary) "glossary-text") ((tm-func? t 'list-of-figures) "list-of-figures") ((tm-func? t 'list-of-tables) "list-of-tables") - (else #f))) + (else #f) + ) ;cond +) ;define (define (automatic-section-name) - (with-innermost t automatic-section-context? - (let* ((var (automatic-name-var t)) - (val (if var (get-env-tree var) ""))) + (with-innermost t + automatic-section-context? + (let* ((var (automatic-name-var t)) (val (if var (get-env-tree var) ""))) (when (tm-func? val 'macro 1) - (set! val (tm-ref val 0))) + (set! val (tm-ref val 0)) + ) ;when (when (and (tm-func? val 'localize 1) (tm-atomic? (tm-ref val 0))) - (set! val (tm-ref val 0))) - (if (tm-atomic? val) (tm->string val) "")))) + (set! val (tm-ref val 0)) + ) ;when + (if (tm-atomic? val) (tm->string val) "") + ) ;let* + ) ;with-innermost +) ;define (tm-define (automatic-section-rename new-name) (:argument new-name "New name") (:proposals new-name (list (automatic-section-name))) - (with-innermost t automatic-section-context? + (with-innermost t + automatic-section-context? (when t - (let* ((l (tree-label t)) - (l* (symbol-append l '*))) - (tree-set t `(,l* ,@(cDr (tm-children t)) - ,new-name ,(tm-ref t :last))))))) + (let* ((l (tree-label t)) (l* (symbol-append l '*))) + (tree-set t `(,l* ,@(cDr (tm-children t)) ,new-name ,(tm-ref t :last))) + ) ;let* + ) ;when + ) ;with-innermost +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Editing enunciations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (enunciation-context? t) - (tree-in? t (enunciation-tag-list))) +(tm-define (enunciation-context? t) (tree-in? t (enunciation-tag-list))) (tm-define (style-category p) (:require (in? p (list "framed-theorems" "hanging-theorems"))) - :theorem-decorations) + :theorem-decorations +) ;tm-define (tm-define (dueto-supporting-context? t) (or (tree-in? t (numbered-unnumbered-append (enunciation-tag-list))) - (tree-in? t (render-enunciation-tag-list)) - (tree-in? t '(proof render-proof)))) + (tree-in? t (render-enunciation-tag-list)) + (tree-in? t '(proof render-proof)) + ) ;or +) ;tm-define -(tm-define (dueto-added? t) - (tm-find t (lambda (x) (tm-is? x 'dueto)))) +(tm-define (dueto-added? t) (tm-find t (lambda (x) (tm-is? x 'dueto)))) -(tm-define (dueto-add t) - (tree-go-to t :last :start) - (make 'dueto)) +(tm-define (dueto-add t) (tree-go-to t :last :start) (make 'dueto)) (tm-define (focus-label t) (:require (enunciation-context? t)) - (and (== (tree-arity t) 1) - (focus-search-label (tree-ref t 0)))) + (and (== (tree-arity t) 1) (focus-search-label (tree-ref t 0))) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Editing algorithms ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (algorithm-context? t) - (tree-in? t (algorithm-tag-list))) +(tm-define (algorithm-context? t) (tree-in? t (algorithm-tag-list))) (tm-define (algorithm-root s) - (cond ((symbol-ends? s '*) - (algorithm-root (symbol-drop-right s 1))) - ((symbol-starts? s 'specified-) - (algorithm-root (symbol-drop s 10))) - ((symbol-starts? s 'named-) - (algorithm-root (symbol-drop s 6))) - (else s))) + (cond ((symbol-ends? s '*) (algorithm-root (symbol-drop-right s 1))) + ((symbol-starts? s 'specified-) (algorithm-root (symbol-drop s 10))) + ((symbol-starts? s 'named-) (algorithm-root (symbol-drop s 6))) + (else s) + ) ;cond +) ;tm-define (tm-define (algorithm-numbered? t) - (let* ((l (tree-label t)) - (r (algorithm-root l))) - (in? l (list r (symbol-append 'specified- r))))) + (let* ((l (tree-label t)) (r (algorithm-root l))) + (in? l (list r (symbol-append 'specified- r))) + ) ;let* +) ;tm-define (tm-define (algorithm-named? t) - (with l (tree-label t) - (symbol-starts? l 'named-))) + (with l (tree-label t) (symbol-starts? l 'named-)) +) ;tm-define (tm-define (algorithm-specified? t) - (with l (tree-label t) - (or (symbol-starts? l 'named-specified-) - (symbol-starts? l 'specified-)))) + (with l + (tree-label t) + (or (symbol-starts? l 'named-specified-) (symbol-starts? l 'specified-)) + ) ;with +) ;tm-define (tm-define (algorithm-toggle-number t) - (let* ((l (tree-label t)) - (r (algorithm-root l))) + (let* ((l (tree-label t)) (r (algorithm-root l))) (if (algorithm-numbered? t) - (if (algorithm-specified? t) - (variant-set t (symbol-append 'specified- r '*)) - (variant-set t (symbol-append r '*))) - (if (algorithm-specified? t) - (variant-set t (symbol-append 'specified- r)) - (variant-set t r))))) + (if (algorithm-specified? t) + (variant-set t (symbol-append 'specified- r '*)) + (variant-set t (symbol-append r '*)) + ) ;if + (if (algorithm-specified? t) + (variant-set t (symbol-append 'specified- r)) + (variant-set t r) + ) ;if + ) ;if + ) ;let* +) ;tm-define (tm-define (algorithm-toggle-name t) - (let* ((l (tree-label t)) - (r (algorithm-root l))) + (let* ((l (tree-label t)) (r (algorithm-root l))) (if (algorithm-named? t) - (begin - (if (algorithm-specified? t) - (tree-assign-node! t (symbol-append 'specified- r)) - (tree-assign-node! t r)) - (tree-remove! t 0 1)) - (begin - (if (algorithm-specified? t) - (tree-assign-node! t (symbol-append 'named-specified- r)) - (tree-assign-node! t (symbol-append 'named- r))) - (tree-insert! t 0 '("")) - (tree-go-to t 0 :start))))) + (begin + (if (algorithm-specified? t) + (tree-assign-node! t (symbol-append 'specified- r)) + (tree-assign-node! t r) + ) ;if + (tree-remove! t 0 1) + ) ;begin + (begin + (if (algorithm-specified? t) + (tree-assign-node! t (symbol-append 'named-specified- r)) + (tree-assign-node! t (symbol-append 'named- r)) + ) ;if + (tree-insert! t 0 '("")) + (tree-go-to t 0 :start) + ) ;begin + ) ;if + ) ;let* +) ;tm-define (tm-define (algorithm-toggle-specification t) - (let* ((l (tree-label t)) - (r (algorithm-root l))) + (let* ((l (tree-label t)) (r (algorithm-root l))) (if (algorithm-specified? t) - (begin - (cond ((algorithm-named? t) - (tree-assign-node! t (symbol-append 'named- r))) - ((algorithm-numbered? t) - (tree-assign-node! t r)) - (else - (tree-assign-node! t (symbol-append r '*)))) - (tree-remove! t (- (tree-arity t) 2) 1)) - (begin - (cond ((algorithm-named? t) - (tree-assign-node! t (symbol-append 'named-specified- r))) - ((algorithm-numbered? t) - (tree-assign-node! t (symbol-append 'specified- r))) - (else - (tree-assign-node! t (symbol-append 'specified- r '*)))) - (tree-insert! t (- (tree-arity t) 1) '((document ""))) - (tree-go-to t (- (tree-arity t) 2) :start))))) + (begin + (cond ((algorithm-named? t) (tree-assign-node! t (symbol-append 'named- r))) + ((algorithm-numbered? t) (tree-assign-node! t r)) + (else (tree-assign-node! t (symbol-append r '*))) + ) ;cond + (tree-remove! t (- (tree-arity t) 2) 1) + ) ;begin + (begin + (cond ((algorithm-named? t) (tree-assign-node! t (symbol-append 'named-specified- r))) + ((algorithm-numbered? t) (tree-assign-node! t (symbol-append 'specified- r))) + (else (tree-assign-node! t (symbol-append 'specified- r '*))) + ) ;cond + (tree-insert! t (- (tree-arity t) 1) '((document ""))) + (tree-go-to t (- (tree-arity t) 2) :start) + ) ;begin + ) ;if + ) ;let* +) ;tm-define (tm-define (focus-label t) (:require (algorithm-context? t)) - (focus-list-search-label (tree-children t))) + (focus-list-search-label (tree-children t)) +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Possible to use a custom note symbol ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (detached-note-context? t) - (tree-in? t (detached-note-tag-list))) +(tm-define (detached-note-context? t) (tree-in? t (detached-note-tag-list))) -(tm-define (auto-note-context? t) - (tree-in? t (auto-note-tag-list))) +(tm-define (auto-note-context? t) (tree-in? t (auto-note-tag-list))) -(tm-define (custom-note-context? t) - (tree-in? t (custom-note-tag-list))) +(tm-define (custom-note-context? t) (tree-in? t (custom-note-tag-list))) (tm-define (note-toggle-custom t) - (let* ((l (symbol-toggle-number (tree-label t))) - (c (tree-children t))) + (let* ((l (symbol-toggle-number (tree-label t))) (c (tree-children t))) (if (auto-note-context? t) - (tree-insert! t (tree-arity t) (list "")) - (tree-remove! t (- (tree-arity t) 1) 1)) - (tree-assign-node! t l))) + (tree-insert! t (tree-arity t) (list "")) + (tree-remove! t (- (tree-arity t) 1) 1) + ) ;if + (tree-assign-node! t l) + ) ;let* +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Possible to change the title of titled environments ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (tm-define (titled-context? t) - (tree-in? t (numbered-unnumbered-append (titled-tag-list)))) + (tree-in? t (numbered-unnumbered-append (titled-tag-list))) +) ;tm-define -(tm-define (titled-named? t) - (tree-in? t (render-titled-tag-list))) +(tm-define (titled-named? t) (tree-in? t (render-titled-tag-list))) (tm-define (titled-toggle-name t) (cond ((tree-in? t (numbered-unnumbered-append (theorem-tag-list))) - (tree-set! t `(render-theorem "" ,(tree-ref t 0)))) + (tree-set! t `(render-theorem ,"" ,(tree-ref t 0))) + ) ; ((tree-in? t (numbered-unnumbered-append (remark-tag-list))) - (tree-set! t `(render-remark "" ,(tree-ref t 0)))) + (tree-set! t `(render-remark ,"" ,(tree-ref t 0))) + ) ; ((tree-in? t '(question answer)) - (tree-set! t `(render-remark "" ,(tree-ref t 0)))) + (tree-set! t `(render-remark ,"" ,(tree-ref t 0))) + ) ; ((tree-in? t (numbered-unnumbered-append (exercise-tag-list))) - (tree-set! t `(render-exercise "" ,(tree-ref t 0)))) + (tree-set! t `(render-exercise ,"" ,(tree-ref t 0))) + ) ; ((tree-in? t (numbered-unnumbered-append (solution-tag-list))) - (tree-set! t `(render-exercise "" ,(tree-ref t 0)))) - ((tree-in? t '(proof)) - (tree-set! t `(render-proof "" ,(tree-ref t 0)))) + (tree-set! t `(render-exercise ,"" ,(tree-ref t 0))) + ) ; + ((tree-in? t '(proof)) (tree-set! t `(render-proof ,"" ,(tree-ref t 0)))) ((tree-in? t (numbered-unnumbered-append (small-figure-tag-list))) - (tree-set! t `(render-small-figure "" "" ,(tree-ref t 0) - ,(tree-ref t 1)))) + (tree-set! t `(render-small-figure ,"" + ,"" + ,(tree-ref t 0) + ,(tree-ref t 1))) + ) ; ((tree-in? t (numbered-unnumbered-append (big-figure-tag-list))) - (tree-set! t `(render-big-figure "" "" ,(tree-ref t 0) - ,(tree-ref t 1)))) + (tree-set! t `(render-big-figure ,"" + ,"" + ,(tree-ref t 0) + ,(tree-ref t 1))) + ) ; ((tree-in? t (numbered-unnumbered-append (small-table-tag-list))) - (tree-set! t `(render-small-table "" "" ,(tree-ref t 0) - ,(tree-ref t 1)))) + (tree-set! t `(render-small-table ,"" + ,"" + ,(tree-ref t 0) + ,(tree-ref t 1))) + ) ; ((tree-in? t (numbered-unnumbered-append (big-table-tag-list))) - (tree-set! t `(render-big-table "" "" ,(tree-ref t 0) - ,(tree-ref t 1)))) - ((tree-is? t 'render-theorem) - (tree-set! t `(theorem ,(tree-ref t 1)))) - ((tree-is? t 'render-remark) - (tree-set! t `(remark ,(tree-ref t 1)))) - ((tree-is? t 'render-exercise) - (tree-set! t `(exercise ,(tree-ref t 1)))) - ((tree-is? t 'render-solution) - (tree-set! t `(solution ,(tree-ref t 1)))) - ((tree-is? t 'render-proof) - (tree-set! t `(proof ,(tree-ref t 1)))) + (tree-set! t `(render-big-table ,"" + ,"" + ,(tree-ref t 0) + ,(tree-ref t 1))) + ) ; + ((tree-is? t 'render-theorem) (tree-set! t `(theorem ,(tree-ref t 1)))) + ((tree-is? t 'render-remark) (tree-set! t `(remark ,(tree-ref t 1)))) + ((tree-is? t 'render-exercise) (tree-set! t `(exercise ,(tree-ref t 1)))) + ((tree-is? t 'render-solution) (tree-set! t `(solution ,(tree-ref t 1)))) + ((tree-is? t 'render-proof) (tree-set! t `(proof ,(tree-ref t 1)))) ((tree-is? t 'render-small-figure) - (tree-set! t `(small-figure ,(tree-ref t 2) ,(tree-ref t 3)))) + (tree-set! t `(small-figure ,(tree-ref t 2) ,(tree-ref t 3))) + ) ; ((tree-is? t 'render-big-figure) - (tree-set! t `(big-figure ,(tree-ref t 2) ,(tree-ref t 3)))) + (tree-set! t `(big-figure ,(tree-ref t 2) ,(tree-ref t 3))) + ) ; ((tree-is? t 'render-small-table) - (tree-set! t `(small-table ,(tree-ref t 2) ,(tree-ref t 3)))) + (tree-set! t `(small-table ,(tree-ref t 2) ,(tree-ref t 3))) + ) ; ((tree-is? t 'render-big-table) - (tree-set! t `(big-table ,(tree-ref t 2) ,(tree-ref t 3)))))) + (tree-set! t `(big-table ,(tree-ref t 2) ,(tree-ref t 3))) + ) ; + ) ;cond +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Framed environments ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (frame-context? t) - (tree-in? t (frame-tag-list))) +(tm-define (frame-context? t) (tree-in? t (frame-tag-list))) -(tm-define (frame-titled-context? t) - (tree-in? t (frame-titled-tag-list))) +(tm-define (frame-titled-context? t) (tree-in? t (frame-titled-tag-list))) -(tm-define (frame-titled? t) - (tree-in? t (frame-titled-tag-list))) +(tm-define (frame-titled? t) (tree-in? t (frame-titled-tag-list))) (tm-define (frame-toggle-title t) (cond ((tree-in? t (frame-tag-list)) - (with l (symbol-append (tree-label t) '-titled) - (tree-set! t `(,l ,(tree-ref t 0) "")) - (tree-go-to t 1 :end))) + (with l + (symbol-append (tree-label t) '-titled) + (tree-set! t `(,l ,(tree-ref t 0) ,"")) + (tree-go-to t 1 :end) + ) ;with + ) ; ((tree-in? t (frame-titled-tag-list)) - (with l (symbol-drop-right (tree-label t) 7) + (with l + (symbol-drop-right (tree-label t) 7) (tree-set! t `(,l ,(tree-ref t 0))) - (tree-go-to t 0 :end))))) + (tree-go-to t 0 :end) + ) ;with + ) ; + ) ;cond +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "padding-above" "padding-below"))) - (list "0fn" "0.5fn" "1fn" "1.5fn" "2fn" :other)) + (list "0fn" "0.5fn" "1fn" "1.5fn" "2fn" :other) +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(padded padded-titled))) - (list (list "padding-above" "Above") - (list "padding-below" "Below"))) + (list (list "padding-above" "Above") (list "padding-below" "Below")) +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "overlined-sep" "underlined-sep"))) - (list "0sep" "0.5sep" "1sep" "1.5sep" "2sep" :other)) + (list "0sep" "0.5sep" "1sep" "1.5sep" "2sep" :other) +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(overlined overlined-titled))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "overlined-sep" "Inner"))) + (list "padding-below" "Below") + (list "overlined-sep" "Inner") + ) ;list +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(underlined underlined-titled))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "underlined-sep" "Inner"))) + (list "padding-below" "Below") + (list "underlined-sep" "Inner") + ) ;list +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(bothlined bothlined-titled))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "overlined-sep" "Top") - (list "underlined-sep" "Bottom"))) + (list "padding-below" "Below") + (list "overlined-sep" "Top") + (list "underlined-sep" "Bottom") + ) ;list +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(framed framed-titled))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "framed-color" "Color"))) + (list "padding-below" "Below") + (list "framed-color" "Color") + ) ;list +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "ornament-hpadding" "ornament-vpadding"))) - (list "0spc" "0.5spc" "1spc" "1.5spc" "2spc" :other)) + (list "0spc" "0.5spc" "1spc" "1.5spc" "2spc" :other) +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "ornament-border"))) - (list "0ln" "0.5ln" "1ln" "2ln" "3ln" "4ln" "5ln" :other)) + (list "0ln" "0.5ln" "1ln" "2ln" "3ln" "4ln" "5ln" :other) +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(ornamented decorated))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "ornament-vpadding" "Inner") - (list "ornament-hpadding" "Indentation") - (list "ornament-shape" "Shape::ornament") - (list "ornament-color" "Color") - (list "ornament-border" "Border"))) + (list "padding-below" "Below") + (list "ornament-vpadding" "Inner") + (list "ornament-hpadding" "Indentation") + (list "ornament-shape" "Shape::ornament") + (list "ornament-color" "Color") + (list "ornament-border" "Border") + ) ;list +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t '(ornamented-titled decorated-titled))) (list (list "padding-above" "Above") - (list "padding-below" "Below") - (list "ornament-vpadding" "Inner") - (list "ornament-hpadding" "Indentation") - (list "ornament-shape" "Shape::ornament") - (list "ornament-color" "Color") - (list "ornament-border" "Border") - (list "ornament-title-style" "Title style") - (list "ornament-extra-color" "Title color"))) + (list "padding-below" "Below") + (list "ornament-vpadding" "Inner") + (list "ornament-hpadding" "Indentation") + (list "ornament-shape" "Shape::ornament") + (list "ornament-color" "Color") + (list "ornament-border" "Border") + (list "ornament-title-style" "Title style") + (list "ornament-extra-color" "Title color") + ) ;list +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-is? t 'ornament)) - (append (list (list "ornament-shape" "Shape::ornament") - (list "ornament-color" "Color")) - (if (== (tree-arity t) 1) (list) - (list (list "ornament-title-style" "Title style") - (list "ornament-extra-color" "Title color"))) - (list (list "ornament-border" "Border width") - (list "ornament-hpadding" "Horizontal padding") - (list "ornament-vpadding" "Vertical padding")))) + (append (list (list "ornament-shape" "Shape::ornament") (list "ornament-color" "Color")) + (if (== (tree-arity t) 1) + (list) + (list (list "ornament-title-style" "Title style") + (list "ornament-extra-color" "Title color") + ) ;list + ) ;if + (list (list "ornament-border" "Border width") + (list "ornament-hpadding" "Horizontal padding") + (list "ornament-vpadding" "Vertical padding") + ) ;list + ) ;append +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t (ornament-tag-list))) (list (list "ornament-shape" "Shape:ornament") - (list "ornament-border" "Border width") - (list "ornament-hpadding" "Horizontal padding") - (list "ornament-vpadding" "Vertical padding"))) + (list "ornament-border" "Border width") + (list "ornament-hpadding" "Horizontal padding") + (list "ornament-vpadding" "Vertical padding") + ) ;list +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "frame-hpadding" "frame-vpadding"))) - (list "0tab" "0.5tab" "1tab" "1.5tab" "2tab" :other)) + (list "0tab" "0.5tab" "1tab" "1.5tab" "2tab" :other) +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "frame-thickness"))) - (list "0.2" "0.5" "1" "1.5" "2" "3" "4" "5" :other)) + (list "0.2" "0.5" "1" "1.5" "2" "3" "4" "5" :other) +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t (art-frame-tag-list))) (list (list "frame-thickness" "Thickness") - (list "frame-recolor" "Recolor") - (list "frame-hpadding" "Horizontal padding") - (list "frame-vpadding" "Vertical padding"))) + (list "frame-recolor" "Recolor") + (list "frame-hpadding" "Horizontal padding") + (list "frame-vpadding" "Vertical padding") + ) ;list +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "shadow-elevation"))) - (list "0.2" "0.5" "1" "1.5" "2" "3" "4" "5" :other)) + (list "0.2" "0.5" "1" "1.5" "2" "3" "4" "5" :other) +) ;tm-define (tm-define (parameter-choice-list var) (:require (in? var (list "shadow-plain"))) - (list "false" "true")) + (list "false" "true") +) ;tm-define (tm-define (customizable-parameters t) (:require (tree-in? t (shadow-tag-list))) (list (list "shadow-elevation" "Elevation") - (list "shadow-recolor" "Recolor") - (list "shadow-plain" "Plain"))) + (list "shadow-recolor" "Recolor") + (list "shadow-plain" "Plain") + ) ;list +) ;tm-define ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Floating objects and environments ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(tm-define (float-context? t) - (tree-in? t '(float wide-float))) +(tm-define (float-context? t) (tree-in? t '(float wide-float))) -(tm-define (footnote-context? t) - (tree-in? t '(footnote wide-footnote))) +(tm-define (footnote-context? t) (tree-in? t '(footnote wide-footnote))) -(tm-define (figure-context? t) - (tree-in? t (figure-tag-list))) +(tm-define (figure-context? t) (tree-in? t (figure-tag-list))) -(tm-define (table-context? t) - (tree-in? t (table-tag-list))) +(tm-define (table-context? t) (tree-in? t (table-tag-list))) (tm-define (float-or-footnote-context? t) - (tree-in? t '(float wide-float footnote wide-footnote))) + (tree-in? t '(float wide-float footnote wide-footnote)) +) ;tm-define -(tm-define (phantom-float-context? t) - (tree-is? t 'phantom-float)) +(tm-define (phantom-float-context? t) (tree-is? t 'phantom-float)) (tm-define (rich-float-context? t) (cond ((tree-in? t '(float wide-float)) #t) - ((tree-in? t '(big-figure big-figure* - big-table big-table* - algorithm algorithm* - document concat)) - (and (tree-up t) (rich-float-context? (tree-up t)))) - (else #f))) + ((tree-in? t + '(big-figure big-figure* + big-table + big-table* + algorithm + algorithm* + document + concat) + ) ;tree-in? + (and (tree-up t) (rich-float-context? (tree-up t))) + ) ; + (else #f) + ) ;cond +) ;tm-define (tm-define (floatable-context? t) (and (tree-in? t '(big-figure big-figure* - big-table big-table* - algorithm algorithm*)) - (not (rich-float-context? t)) - (or (tree-is? t :up 'document) - (and (tree-is? t :up 'with) - (tree-is? t :up :up 'document))))) + big-table + big-table* + algorithm + algorithm*)) + (not (rich-float-context? t)) + (or (tree-is? t :up 'document) + (and (tree-is? t :up 'with) (tree-is? t :up :up 'document)) + ) ;or + ) ;and +) ;tm-define (define (with-wide? w) (and (tree-is? w 'with) - (== (tree-arity w) 3) - (tm-equal? (tree-ref w 0) "par-columns") - (tm-equal? (tree-ref w 1) "1"))) + (== (tree-arity w) 3) + (tm-equal? (tree-ref w 0) "par-columns") + (tm-equal? (tree-ref w 1) "1") + ) ;and +) ;define (tm-define (turn-floating t) (when (floatable-context? t) (when (tree-is? t :up 'with) - (set! t (tree-up t))) - (with f (if (with-wide? t) - `(wide-float "float" "thb" ,(tree-ref t 2)) - `(float "float" "thb" ,t)) + (set! t (tree-up t)) + ) ;when + (with f + (if (with-wide? t) + `(wide-float ,"float" ,"thb" ,(tree-ref t 2)) + `(float ,"float" ,"thb" ,t) + ) ;if (tree-set! t f) (tree-go-to t :start) (remove-text #f) - (tree-go-to t :end)))) + (tree-go-to t :end) + ) ;with + ) ;when +) ;tm-define (define (floatable-path t) (if (or (tm-func? t 'document 1) - (tm-func? t 'with 3) - (tm-in? t '(big-figure big-figure* - big-table big-table* - algorithm algorithm*))) - (with last (- (tm-arity t) 1) - (cons last (floatable-path (tm-ref t :last)))) - (path-end t '()))) + (tm-func? t 'with 3) + (tm-in? t '(big-figure big-figure* + big-table + big-table* + algorithm + algorithm*)) + ) ;or + (with last (- (tm-arity t) 1) (cons last (floatable-path (tm-ref t :last)))) + (path-end t '()) + ) ;if +) ;define (tm-define (turn-non-floating t) (when (float-context? t) - (with body (tree-copy (tree-ref t :last)) + (with body + (tree-copy (tree-ref t :last)) (when (tree-is? t 'wide-float) - (set! body (tm->tree `(with "par-columns" "1" ,body)))) + (set! body (tm->tree `(with ,"par-columns" ,"1" ,body))) + ) ;when (when (not (tree-is? body 'document)) - (set! body (tm->tree `(document ,body)))) + (set! body (tm->tree `(document ,body))) + ) ;when (tree-cut t) (insert-return) - (insert-go-to body (floatable-path body))))) + (insert-go-to body (floatable-path body)) + ) ;with + ) ;when +) ;tm-define (tm-define (float-wide? t) - (and-with f (tree-search-upwards t float-or-footnote-context?) - (tree-in? f '(wide-float wide-footnote)))) + (and-with f + (tree-search-upwards t float-or-footnote-context?) + (tree-in? f '(wide-float wide-footnote)) + ) ;and-with +) ;tm-define -(tm-define (test-float-wide? . args) - (float-wide? (focus-tree))) +(tm-define (test-float-wide? . args) (float-wide? (focus-tree))) (tm-define (float-toggle-wide t) (:check-mark "v" test-float-wide?) - (and-with f (tree-search-upwards t float-or-footnote-context?) + (and-with f + (tree-search-upwards t float-or-footnote-context?) (cond ((tree-is? f 'float) (tree-assign-node f 'wide-float)) ((tree-is? f 'wide-float) (tree-assign-node f 'float)) ((tree-is? f 'footnote) (tree-assign-node f 'wide-footnote)) - ((tree-is? f 'wide-footnote) (tree-assign-node f 'footnote))))) + ((tree-is? f 'wide-footnote) (tree-assign-node f 'footnote)) + ) ;cond + ) ;and-with +) ;tm-define -(tm-define (floatable-wide? t) - (and-with w (tree-up t) - (with-wide? w))) +(tm-define (floatable-wide? t) (and-with w (tree-up t) (with-wide? w))) -(tm-define (test-floatable-wide? . args) - (floatable-wide? (focus-tree))) +(tm-define (test-floatable-wide? . args) (floatable-wide? (focus-tree))) (tm-define (floatable-toggle-wide t) (:check-mark "v" test-floatable-wide?) - (and-with w (tree-up t) + (and-with w + (tree-up t) (if (with-wide? w) - (tree-set w (tree-ref w 2)) - (tree-set t `(with "par-columns" "1" ,t))))) + (tree-set w (tree-ref w 2)) + (tree-set t `(with ,"par-columns" ,"1" ,t)) + ) ;if + ) ;and-with +) ;tm-define (tm-define (cursor-at-anchor?) - (with t (cursor-tree) - (float-or-footnote-context? t))) + (with t (cursor-tree) (float-or-footnote-context? t)) +) ;tm-define (tm-define (go-to-anchor) (cond ((or (inside? 'float) (inside? 'wide-float)) - (with-innermost t float-context? - (tree-go-to t :end))) + (with-innermost t float-context? (tree-go-to t :end)) + ) ; ((or (inside? 'footnote) (inside? 'wide-footnote)) - (with-innermost t footnote-context? - (tree-go-to t :end))))) + (with-innermost t footnote-context? (tree-go-to t :end)) + ) ; + ) ;cond +) ;tm-define (tm-define (go-to-float) - (with t (cursor-tree) - (cond ((float-context? t) - (tree-go-to t 2 :start)) - ((footnote-context? t) - (tree-go-to t 0 :start))))) + (with t + (cursor-tree) + (cond ((float-context? t) (tree-go-to t 2 :start)) + ((footnote-context? t) (tree-go-to t 0 :start)) + ) ;cond + ) ;with +) ;tm-define (tm-define (cursor-toggle-anchor) (:check-mark "v" cursor-at-anchor?) - (if (cursor-at-anchor?) - (go-to-float) - (go-to-anchor))) + (if (cursor-at-anchor?) (go-to-float) (go-to-anchor)) +) ;tm-define (tm-define (focus-label t) (:require (or (footnote-context? t) (figure-context? t))) - (focus-list-search-label (tree-children t))) + (focus-list-search-label (tree-children t)) +) ;tm-define diff --git a/devel/0172.md b/devel/0172.md new file mode 100644 index 0000000000..4165c91633 --- /dev/null +++ b/devel/0172.md @@ -0,0 +1,53 @@ +# [0172] 移除有序列表中全局 item-nr 设置按钮 + +## 相关文档 +- [dddd.md](dddd.md) - 任务文档模板 + +## 任务相关的代码文件 +- `TeXmacs/progs/text/text-edit.scm` +- `TeXmacs/progs/generic/generic-menu.scm` + +## 如何测试 + +### 非确定性测试(UI 验证) +1. 打开 Mogan,插入一个有序列表(enumerate)。 +2. 将光标放入列表项中,点击上方聚焦工具栏的扳手图标(Preferences for tag)。 +3. 确认下拉菜单中**不再出现** `Item nr` 或 `Item-nr` 全局设置项。 +4. 点击渲染选项按钮(Rendering options for tag,主题图标)。 +5. 确认下拉菜单中**仍然出现** `Item nr` 本地渲染设置项,且可以正常修改列表起始编号。 + +## 如何提交 + +提交前执行以下最少步骤: + +```bash +gf fmt --changed-since=main +``` + +## What + +对于有序列表(enumerate)和无序列表(itemize),`item-nr` 是用于控制列表项起始编号的参数。该参数原本同时出现在: +- **全局偏好设置**(扳手图标 / Preferences for tag) +- **本地渲染选项**(主题图标 / Rendering options for tag) + +由于 `item-nr` 是列表局部的编号设置,全局设置按钮对它没有意义,需要将其从全局偏好菜单中移除,但保留在本地渲染菜单中。 + +## Why + +`item-nr` 作为列表项编号的局部控制变量,其作用域应当是当前列表环境本身,而非全局文档样式。用户通过全局偏好菜单意外修改 `item-nr` 会导致不直观的文档级副作用。因此该设置项应当仅出现在局部渲染选项中。 + +## How + +1. 在 `text-edit.scm` 中,将 `"item-nr"` 加入 `inhibit-global-table`,阻止它在全局偏好菜单中显示: + ```scheme + (ahash-set! inhibit-global-table "item-nr" #t) + ``` + +2. 在 `generic-menu.scm` 的 `rendering-parameters-merge` 中,将原来依赖 `focus-parameters-list-memo t :global` 判断是否追加 `"item-nr"` 的逻辑,改为直接查询 `search-parameters`: + ```scheme + (let ((params (search-parameters (tree-label t)))) + (if (and (in? "item-nr" params) (not (in? "item-nr" base))) + (append base (list "item-nr")) + base)) + ``` + 这样即使 `"item-nr"` 被全局抑制,只要当前标签的宏定义中引用了它,它仍会被追加到本地渲染参数列表中。