branch: elpa/typst-ts-mode commit 098abf17c864c05c89fc84ca5093c1a03c33f8b8 Merge: d3e44b5361 131c404ee0 Author: Meow King <mr.meowk...@tutamail.com> Commit: Meow King <mr.meowk...@tutamail.com>
Merge pull request 'Changed compile/preview behaviour and cleaned code' (#30) from vslavkin/typst-ts-mode:main into develop Reviewed-on: https://codeberg.org/meow_king/typst-ts-mode/pulls/30 --- typst-ts-compile.el | 26 +++++++++++++++----------- typst-ts-mode.el | 11 ++--------- typst-ts-transient.el | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/typst-ts-compile.el b/typst-ts-compile.el index 4c417fb3f1..59e6ad0b97 100644 --- a/typst-ts-compile.el +++ b/typst-ts-compile.el @@ -63,12 +63,12 @@ compilation buffer before compilation." (remove-hook 'compilation-finish-functions (typst-ts-compile--compilation-finish-function cur-buffer))))) -(defun typst-ts-compile (&optional arg) +(defun typst-ts-compile (&optional preview) "Compile current typst file. -When use a prefix argument, don't preview the document after compilation. -ARG: prefix argument." +When using a prefix argument or the optional argument PREVIEW, + preview the document after compilation." (interactive "P") - (unless arg + (when preview (add-hook 'compilation-finish-functions (typst-ts-mode-compile-and-preview--compilation-finish-function (current-buffer)))) @@ -107,7 +107,7 @@ CUR-BUFFER: original typst buffer, in case user set buffer before compilation." (lambda (_b _msg) (unwind-protect - (browse-url (typst-ts-compile-get-result-pdf-filename cur-buffer)) + (typst-ts-preview cur-buffer) (remove-hook 'compilation-finish-functions (typst-ts-mode-compile-and-preview--compilation-finish-function cur-buffer))))) @@ -116,12 +116,16 @@ buffer before compilation." "Compile & Preview. Assuming the compile output file name is in default style." (interactive) - ;; use a local variable version of `compilation-finish-functions' to shadow - ;; global version doesn't work - (add-hook 'compilation-finish-functions - (typst-ts-mode-compile-and-preview--compilation-finish-function - (current-buffer))) - (typst-ts-compile)) + (typst-ts-compile t)) + +;;;###autoload +(defun typst-ts-preview (&optional buffer) + "Preview the typst document output. +If BUFFER is passed, preview its output, otherwise use current buffer." + (interactive) + (unless buffer (setq buffer #'current-buffer)) + (browse-url (typst-ts-compile-get-result-pdf-filename #'current-buffer)) + ) (defvar typst-ts-compilation-mode-error (cons (rx bol "error:" (+ not-newline) "\n" (+ blank) "┌─ " diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 9c3554abf5..5f5a1bace8 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -461,19 +461,12 @@ This function is meant to be used when user hits a return key." 0))) -;;;###autoload -(defun typst-ts-mode-preview (file) - "Open the result compile file. -FILE: file path for the result compile file." - (interactive (list (typst-ts-compile-get-result-pdf-filename))) - ;; don't use `browse-url-of-file', which cannot open non-english documents - (browse-url file)) - ;;;###autoload (defvar-keymap typst-ts-mode-map "C-c C-c" #'typst-ts-compile ; use prefix argument to do preview + "C-c C-C" #'typst-ts-compile-and-preview "C-c C-w" #'typst-ts-watch-mode - "C-c C-p" #'typst-ts-mode-preview + "C-c C-p" #'typst-ts-preview "M-<left>" #'typst-ts-mode-meta-left "M-<right>" #'typst-ts-mode-meta-right diff --git a/typst-ts-transient.el b/typst-ts-transient.el index fbf21287fb..53f03cf7dd 100644 --- a/typst-ts-transient.el +++ b/typst-ts-transient.el @@ -31,7 +31,7 @@ ("c" "compile & preview" typst-ts-compile-and-preview) ("C" "compile" typst-ts-compile) ("w" "watch" typst-ts-watch-mode) - ("p" "preview" typst-ts-mode-preview)] + ("p" "preview" typst-ts-preview)] ["Export" ("em" "markdown" typst-ts-mc-export-to-markdown)]