diff --git a/README.md b/README.md index 5944f37..e0455ba 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The gallery owns one definite 720 px canvas so its nested Grid examples cannot e (ebox-playground-open) ``` -The package also owns the `.ebox` file boundary. Visiting an Ebox DSL file selects `ebox-dsl-mode`; press `C-c C-c` to build the single DSL form and render a preview through the public Ebox API. +The package also owns the `.ebox` file boundary. Visiting an Ebox DSL file selects `ebox-dsl-mode`; its header line shows `C-c C-c Render preview`. Press `C-c C-c` to build the single DSL form, render it through the public Ebox API, and automatically display the preview buffer. ```elisp (add-to-list 'auto-mode-alist '("\\.ebox\\'" . ebox-dsl-mode)) diff --git a/README.zh-CN.md b/README.zh-CN.md index 0d7e745..84bad85 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -9,7 +9,7 @@ (ebox-playground-open) ``` -这个包也拥有 `.ebox` 文件入口。访问 Ebox DSL 文件时会自动进入 `ebox-dsl-mode`;按 `C-c C-c` 会通过 Ebox 公开 API 构建单个 DSL form 并渲染预览。 +这个包也拥有 `.ebox` 文件入口。访问 Ebox DSL 文件时会自动进入 `ebox-dsl-mode`,header line 会显示 `C-c C-c Render preview`;按 `C-c C-c` 会通过 Ebox 公开 API 构建单个 DSL form、渲染并自动弹出预览 buffer。 ```elisp (add-to-list 'auto-mode-alist '("\\.ebox\\'" . ebox-dsl-mode)) diff --git a/ebox-playground.el b/ebox-playground.el index da8259d..eb9cf1c 100644 --- a/ebox-playground.el +++ b/ebox-playground.el @@ -29,6 +29,10 @@ map) "Keymap used by `ebox-dsl-mode'.") +(defconst ebox-playground--dsl-header-line + "Ebox DSL | C-c C-c Render preview" + "Header line shown by `ebox-dsl-mode'.") + (defun ebox-playground--source-form () "Read the single Ebox DSL form from the current buffer." (ebox-playground--evaluate-form @@ -38,6 +42,7 @@ ;;;###autoload (define-derived-mode ebox-dsl-mode emacs-lisp-mode "EboxDSL" "Major mode for Ebox DSL source files." + (setq-local header-line-format ebox-playground--dsl-header-line) (setq-local truncate-lines nil) (setq-local bidi-display-reordering nil) (setq-local bidi-paragraph-direction 'left-to-right)) @@ -50,7 +55,7 @@ (name (format "*Ebox Preview: %s*" (or (buffer-file-name) (buffer-name)))) (node (ebox-build source))) - (ebox-render-to-buffer name node) + (ebox-display-buffer name node) (message "Rendered Ebox DSL into %s" name) (get-buffer name))) diff --git a/tests/ebox-playground-tests.el b/tests/ebox-playground-tests.el index 6325c09..7ebd254 100644 --- a/tests/ebox-playground-tests.el +++ b/tests/ebox-playground-tests.el @@ -95,7 +95,9 @@ (with-temp-buffer (setq buffer-file-name "/tmp/ebox-playground-mode-test.ebox") (set-auto-mode) - (should (eq major-mode 'ebox-dsl-mode)))) + (should (eq major-mode 'ebox-dsl-mode)) + (should (eq (key-binding (kbd "C-c C-c")) #'ebox-dsl-render)) + (should (string-match-p "C-c C-c" header-line-format)))) (ert-deftest ebox-playground-renders-ebox-file-mode-source () "Render a file-mode buffer through the public Ebox build path." @@ -106,6 +108,8 @@ (insert "(box :content \"Rendered from .ebox\" :width '(240))") (ebox-dsl-mode) (ebox-dsl-render) + (should (eq (window-buffer (selected-window)) + (get-buffer preview))) (with-current-buffer preview (should (string-match-p "Rendered from .ebox" (buffer-string))))) (when (get-buffer preview)