|
573 | 573 | (save-buffer-check-faithful name opts) |
574 | 574 | (choose-file (lambda (x) (apply save-buffer-as-main (cons x opts))) |
575 | 575 | "Save TeXmacs file" |
576 | | - "tmu" |
| 576 | + "action_save_as" |
577 | 577 | ) ;choose-file |
578 | 578 | ) ;if |
579 | 579 | ) ; |
|
1201 | 1201 | (and (not (buffer-exists? u)) (not (url-exists? u))) |
1202 | 1202 | ) ;define |
1203 | 1203 |
|
1204 | | -(define (scratch-candidate dir stamp) |
1205 | | - (url-append dir (string-append "draft_" stamp ".tmu")) |
| 1204 | +(define (normalize-draft-ext ext) |
| 1205 | + (if (equal? ext ".stem") ".stem" ".tmu") |
| 1206 | +) ;define |
| 1207 | + |
| 1208 | +(define (scratch-candidate dir stamp ext) |
| 1209 | + (url-append dir (string-append "draft_" stamp ext)) |
1206 | 1210 | ) ;define |
1207 | 1211 |
|
1208 | 1212 | ;; 秒级名字仍冲突时,追加 -2、-3 …… 保证唯一 |
1209 | 1213 |
|
1210 | | -(define (scratch-unique-name dir stamp i) |
| 1214 | +(define (scratch-unique-name dir stamp i ext) |
1211 | 1215 | (let ((u (scratch-candidate dir |
1212 | 1216 | (if (= i 0) stamp (string-append stamp "-" (number->string i))) |
| 1217 | + ext |
1213 | 1218 | ) ;scratch-candidate |
1214 | 1219 | ) ;u |
1215 | 1220 | ) ; |
1216 | | - (if (scratch-name-free? u) u (scratch-unique-name dir stamp (+ i 1))) |
| 1221 | + (if (scratch-name-free? u) u (scratch-unique-name dir stamp (+ i 1) ext)) |
1217 | 1222 | ) ;let |
1218 | 1223 | ) ;define |
1219 | 1224 |
|
1220 | 1225 | ;; 新 scratch buffer 的名字:日期与时刻用 _ 分开,精确到秒,冲突加 -N |
1221 | | -;; 例: draft_20260901_194700.tmu / draft_20260901_194700-1.tmu |
| 1226 | +;; 例: draft_20260901_194700.tmu / draft_20260901_194700-1.tmu / .stem |
1222 | 1227 | ;; 返回系统路径字符串(供 C++ make_new_buffer 使用) |
1223 | | -(tm-define (scratch-buffer-name) |
| 1228 | +(tm-define (scratch-buffer-name ext) |
1224 | 1229 | (with dir |
1225 | 1230 | (scratch-buffer-dir) |
1226 | 1231 | (when (not (url-exists? dir)) |
1227 | 1232 | (system-mkdir dir) |
1228 | 1233 | ) ;when |
1229 | 1234 | (with full |
1230 | 1235 | (date->string (current-date) "~Y~m~d_~H~M~S") |
1231 | | - (url->system (scratch-unique-name dir full 0)) |
| 1236 | + (url->system (scratch-unique-name dir full 0 (normalize-draft-ext ext))) |
1232 | 1237 | ) ;with |
1233 | 1238 | ) ;with |
1234 | 1239 | ) ;tm-define |
1235 | 1240 |
|
| 1241 | +(tm-define (new-buffer . opt-ext) |
| 1242 | + (cpp-new-buffer-with-ext (if (null? opt-ext) ".tmu" (normalize-draft-ext (car opt-ext))) |
| 1243 | + ) ;cpp-new-buffer-with-ext |
| 1244 | +) ;tm-define |
| 1245 | + |
1236 | 1246 | ;; draft 文件名 → 纯数字时间戳,供标题按位切分(YYYYMMDDHH[MM][SS])。 |
1237 | 1247 | ;; 新格式 "draft_20260901_194700.tmu" → "20260901194700"; |
| 1248 | +;; ".stem" 格式 "draft_20260901_194700.stem" → "20260901194700"; |
1238 | 1249 | ;; 旧格式 "draft_202608242127-2.tmu" → "202608242127"; |
1239 | 1250 | ;; 非 draft 名返回 #f |
1240 | 1251 |
|
1241 | 1252 | (define (draft-stamp u) |
1242 | 1253 | (with name |
1243 | 1254 | (url->string (url-tail u)) |
1244 | | - (and (string-starts? name "draft_") |
1245 | | - (string-ends? name ".tmu") |
1246 | | - (let* ((body (substring name 6 (- (string-length name) 4))) |
1247 | | - (cut (or (string-index body #\-) (string-length body))) |
1248 | | - (raw (substring body 0 cut)) |
1249 | | - ;; 去掉日期与时刻之间的 _,标题逻辑仍按连续数字下标切 |
1250 | | - (digits (string-join (string-split raw "_") "")) |
1251 | | - ) ; |
1252 | | - (and (>= (string-length digits) 12) digits) |
1253 | | - ) ;let* |
1254 | | - ) ;and |
| 1255 | + (let ((ext (url-suffix u))) |
| 1256 | + (and (in? ext '("tmu" "stem")) |
| 1257 | + (string-starts? name "draft_") |
| 1258 | + (let* ((body (substring name 6 (- (string-length name) (string-length ext) 1))) |
| 1259 | + (cut (or (string-index body #\-) (string-length body))) |
| 1260 | + (raw (substring body 0 cut)) |
| 1261 | + ;; 去掉日期与时刻之间的 _,标题逻辑仍按连续数字下标切 |
| 1262 | + (digits (string-join (string-split raw "_") "")) |
| 1263 | + ) ; |
| 1264 | + (and (>= (string-length digits) 12) digits) |
| 1265 | + ) ;let* |
| 1266 | + ) ;and |
| 1267 | + ) ;let |
1255 | 1268 | ) ;with |
1256 | 1269 | ) ;define |
1257 | 1270 |
|
|
0 commit comments