-
Notifications
You must be signed in to change notification settings - Fork 52
[222_42] 启动时避免多出无标题缓冲区 #2798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[222_42] 启动时避免多出无标题缓冲区 #2798
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -548,19 +548,11 @@ | |||||||||||
| ((in? :new-window opts) | ||||||||||||
| (open-buffer-in-window name (buffer-get name) "")) | ||||||||||||
| (else | ||||||||||||
| ;; Remember current buffer to check if it's an unmodified scratch buffer | ||||||||||||
| (let ((prev-buffer (current-buffer))) | ||||||||||||
| (with wins (buffer->windows-of-tabpage name) | ||||||||||||
| (if (and (!= wins '()) | ||||||||||||
| (in? (current-window) wins)) | ||||||||||||
| (switch-to-buffer* name) | ||||||||||||
| (switch-to-buffer name))) | ||||||||||||
| ;; Close the previous unmodified scratch buffer after loading new file | ||||||||||||
| (when (and prev-buffer | ||||||||||||
| (!= prev-buffer name) | ||||||||||||
| (url-scratch? prev-buffer) | ||||||||||||
| (not (buffer-modified? prev-buffer))) | ||||||||||||
| (cpp-buffer-close prev-buffer))))) | ||||||||||||
| (with wins (buffer->windows-of-tabpage name) | ||||||||||||
| (if (and (!= wins '()) | ||||||||||||
| (in? (current-window) wins)) | ||||||||||||
| (switch-to-buffer* name) | ||||||||||||
| (switch-to-buffer name))))) | ||||||||||||
| (buffer-notify-recent name) | ||||||||||||
| ;; Remember directory for file dialog | ||||||||||||
| (remember-file-dialog-directory name) | ||||||||||||
|
|
@@ -625,6 +617,56 @@ | |||||||||||
| (load-buffer-check-permissions name opts))))) | ||||||||||||
| (load-buffer-check-permissions name opts))) | ||||||||||||
|
|
||||||||||||
| (tm-define (load-buffer-into-current name . opts) | ||||||||||||
| ;; @brief 启动阶段复用当前空白缓冲区加载文档,避免多出“无标题”缓冲区。 | ||||||||||||
| ;; 例:双击文件启动时,当前空白缓冲区会被重命名并加载目标文档。 | ||||||||||||
| (let ((cur (current-buffer))) | ||||||||||||
| (if (and cur (url-scratch? cur) (not (buffer-modified? cur)) | ||||||||||||
| (url-exists? name)) | ||||||||||||
| (letrec | ||||||||||||
| ;; @brief 复用当前缓冲区加载指定文档,保持与正常加载一致的提示行为。 | ||||||||||||
| ;; 例:遇到 autosave 时仍然弹出恢复确认框。 | ||||||||||||
| ((load-into-current | ||||||||||||
| (lambda (target) | ||||||||||||
| (let* ((doc (tree-import target (url-format target)))) | ||||||||||||
| (buffer-rename cur name) | ||||||||||||
| (buffer-set name doc) | ||||||||||||
| (load-buffer-open name opts)))) | ||||||||||||
| (load-check-permissions | ||||||||||||
| (lambda () | ||||||||||||
| (let* ((path (url->system name)) | ||||||||||||
| (vname `(verbatim ,(utf8->cork path)))) | ||||||||||||
| (cond ((and (not (url-test? name "f")) (url-exists? name)) | ||||||||||||
| (with msg "The file cannot be loaded or created:" | ||||||||||||
| (begin | ||||||||||||
| (debug-message "debug-io" (string-append msg "\n" path)) | ||||||||||||
| (notify-now `(concat ,msg "<br>" ,vname))))) | ||||||||||||
| ((and (url-test? name "f") (not (url-test? name "r"))) | ||||||||||||
| (with msg `(concat ,(translate "You do not have read access to") " " ,vname) | ||||||||||||
| (show-message msg "Load file"))) | ||||||||||||
| ((buffer-exists? name) | ||||||||||||
| ;; 复用当前空白缓冲区前,优先切换到已打开的目标缓冲区。 | ||||||||||||
| (load-buffer-open name opts) | ||||||||||||
| (buffer-close cur)) | ||||||||||||
|
||||||||||||
| (buffer-close cur)) | |
| ;; 仅在非后台、非新窗口模式下,才关闭当前缓冲区。 | |
| (if (and (nin? :background opts) | |
| (nin? :new-window opts)) | |
| (buffer-close cur))) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # 222_42 启动时避免多出“无标题”缓冲区 | ||
|
|
||
| ### 如何测试 | ||
| 1. 删除 `%APPDATA%\moganlab\system\settings.scm` 后启动 | ||
| 预期:仅显示欢迎文档,不出现额外“无标题” | ||
| 2. 从文件管理器用软件打开 `.tmu` 文件 | ||
| 预期:仅显示目标文件,不出现额外“无标题” | ||
| 3. 无参数启动(非首次) | ||
| 预期:显示一个空白文档 | ||
|
|
||
| ## 2026/02/10 | ||
|
|
||
| ### What | ||
| - 启动时复用空白缓冲区加载欢迎文档,避免多出“无标题”缓冲区 | ||
| - 通过“打开方式”启动文件时,复用空白缓冲区加载目标文档 | ||
| - 若有启动文件参数,则不再加载欢迎文档 | ||
|
|
||
| ### Why | ||
| - 启动阶段必须先有可用视图,避免崩溃 | ||
| - 用户打开欢迎文档或直接打开文件时,不应额外出现“无标题”文档 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load-buffer-into-currentusestree-importand then renames/overwrites the current scratch buffer without checking for import failure. Elsewhere (e.g.,revert-buffer-revert) the code checks(== t (tm->tree "error"))to surface an error message. Consider adding a similar check beforebuffer-rename/buffer-set, so a corrupted/unsupported file doesn’t silently replace the current buffer with an error tree.