branch: elpa/typst-ts-mode commit 998eed6f22c600867b50dfe10ccf382dbbacccd4 Author: meowking <mr.meowk...@posteo.com> Commit: meowking <mr.meowk...@posteo.com>
refacvtor: move variables to separate file --- typst-ts-compile.el | 32 +---------- typst-ts-mode.el | 40 +------------- typst-ts-variables.el | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ typst-ts-watch-mode.el | 36 +----------- 4 files changed, 150 insertions(+), 105 deletions(-) diff --git a/typst-ts-compile.el b/typst-ts-compile.el index d397a7246b..cb030d61dc 100644 --- a/typst-ts-compile.el +++ b/typst-ts-compile.el @@ -19,37 +19,7 @@ ;;; Code: (require 'compile) - -(defgroup typst-ts-compile nil - "Typst TS Compilation." - :prefix "typst-ts-compile" - :group 'typst-ts) - -(defcustom typst-ts-compile-executable-location "typst" - "The location or name (if in variable `exec-path') for Typst executable." - :type 'string) - -(defcustom typst-ts-compile-options "" - "User defined compile options for `typst-ts-compile'. -The compile options will be passed to the end of -`<typst-executable> compile <current-file>' command." - :type 'string) - -(defcustom typst-ts-output-directory "" - "User defined output directory for `typst-ts-compile` and `typst-ts-watch`." - :type 'string - :group 'typst-ts) - -(defcustom typst-ts-compile-before-compilation-hook nil - "Hook runs after compile." - :type 'hook) - -(defcustom typst-ts-compile-after-compilation-hook nil - "Hook runs after compile. -Note the requirement of this hook is the same as `compilation-finish-functions'. -Also note that this hook runs with typst buffer(the buffer you are editing) as -the current buffer." - :type 'hook) +(require 'typst-ts-variables) (defun typst-ts-compile--compilation-finish-function (cur-buffer) "Compilation finish function. diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 289ee8db7f..8508738451 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -43,45 +43,7 @@ (require 'typst-ts-lsp) (require 'typst-ts-misc-commands) (require 'typst-ts-transient) - -(defgroup typst-ts nil - "Tree Sitter enabled Typst Writing." - :prefix "typst-ts" - :group 'text - :group 'languages) - - -(defcustom typst-ts-mode-grammar-location nil - "Specify typst tree sitter grammar file location. -This is used for grammar minimum version check. The modified time of the -grammar file is used for comparing. -This variable is used in `typst-ts-mode-check-grammar-version'." - :type '(choice (string :tag "typst tree sitter grammar file location") - (const :tag "Don't enable grammar version check" nil))) - -;; `git log -n1 --date=raw` or `git log -n1 --format="%at"` -(defvar typst-ts-mode--grammar-minimum-version-timestamp 1713791627 - "Timestamp for the minimum supported typst tree sitter grammar version.") - -(defcustom typst-ts-mode-enable-raw-blocks-highlight nil - "Whether to enable raw block highlighting. -NOTE this option must be set before the first loading(opening typst file)" - :type 'boolean) - -(defcustom typst-ts-mode-electric-return t - "Whether `typst-ts-mode-return' auto inserts list items or not." - :type 'boolean) - -;; ============================================================================== -;; code from Auctex -(defcustom typst-ts-mode-math-script-display '((raise -0.5) . (raise 0.5)) - "Display specification for subscript and superscript content. -The car is used for subscript, the cdr is used for superscripts." - :type '(cons (choice (sexp :tag "Subscript form") - (const :tag "No lowering" nil)) - (choice (sexp :tag "Superscript form") - (const :tag "No raising" nil))) - :group 'typst-ts) +(require 'typst-ts-variables) ;; ============================================================================== diff --git a/typst-ts-variables.el b/typst-ts-variables.el new file mode 100644 index 0000000000..dbc8d51ff1 --- /dev/null +++ b/typst-ts-variables.el @@ -0,0 +1,147 @@ +;;; typst-ts-variables.el --- typst-ts-mode variables -*- lexical-binding: t; -*- +;; Copyright (C) 2023-2024 The typst-ts-mode Project Contributors + +;; This file is NOT part of Emacs. +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Internal variables and customizable variables. + +;;; Code: + +(defgroup typst-ts nil + "Tree Sitter enabled Typst Writing." + :prefix "typst-ts" + :group 'text + :group 'languages) + + +(defcustom typst-ts-mode-grammar-location nil + "Specify typst tree sitter grammar file location. +This is used for grammar minimum version check. The modified time of the +grammar file is used for comparing. +This variable is used in `typst-ts-mode-check-grammar-version'." + :type '(choice (string :tag "typst tree sitter grammar file location") + (const :tag "Don't enable grammar version check" nil))) + +;; `git log -n1 --date=raw` or `git log -n1 --format="%at"` +(defvar typst-ts-mode--grammar-minimum-version-timestamp 1713791627 + "Timestamp for the minimum supported typst tree sitter grammar version.") + +(defcustom typst-ts-mode-enable-raw-blocks-highlight nil + "Whether to enable raw block highlighting. +NOTE this option must be set before the first loading(opening typst file)" + :type 'boolean) + +(defcustom typst-ts-mode-electric-return t + "Whether `typst-ts-mode-return' auto inserts list items or not." + :type 'boolean) + + +;; code from Auctex +(defcustom typst-ts-mode-math-script-display '((raise -0.5) . (raise 0.5)) + "Display specification for subscript and superscript content. +The car is used for subscript, the cdr is used for superscripts." + :type '(cons (choice (sexp :tag "Subscript form") + (const :tag "No lowering" nil)) + (choice (sexp :tag "Superscript form") + (const :tag "No raising" nil))) + :group 'typst-ts) + + +;;; Compile ==================================================================== + +(defgroup typst-ts-compile nil + "Typst TS Compilation." + :prefix "typst-ts-compile" + :group 'typst-ts) + +(defcustom typst-ts-compile-executable-location "typst" + "The location or name(if in variable `exec-path') for Typst executable." + :type 'string + :group 'typst-ts-compile) + +(defcustom typst-ts-compile-options "" + "User defined compile options for `typst-ts-compile'. +The compile options will be passed to the end of +`<typst-executable> compile <current-file>' command." + :type 'string + :group 'typst-ts) + +(defcustom typst-ts-output-directory "" + "User defined output directory for `typst-ts-compile` and `typst-ts-watch`." + :type 'string + :group 'typst-ts) + +(defcustom typst-ts-compile-before-compilation-hook nil + "Hook runs after compile." + :type 'hook + :group 'typst-ts) + +(defcustom typst-ts-compile-after-compilation-hook nil + "Hook runs after compile. +Note the requirement of this hook is the same as `compilation-finish-functions'. +Also note that this hook runs with typst buffer(the buffer you are editing) as +the current buffer." + :type 'hook + :group 'typst-ts) + + +;;; Watch Mode ================================================================= + +(defcustom typst-ts-watch-options "" + "User defined compile options for `typst-ts-watch'. +The compile options will be passed to the +`<typst-executable> watch <current-file>' sub-command." + :type 'string + :group 'typst-ts-watch) + +(defcustom typst-ts-watch-process-name "*Typst-Watch*" + "Process name for `typst watch' sub-command." + :type 'string + :group 'typst-ts-watch) + +(defcustom typst-ts-watch-process-buffer-name "*Typst-Watch*" + "Process buffer name for `typst watch' sub-command." + :type 'string + :group 'typst-ts-watch) + +(defcustom typst-ts-watch-auto-display-compilation-error t + "Whether the typst watch process buffer should be displayed automatically. +This means the buffer will be displayed when error occurs, hide when error +is eliminated." + :type 'boolean + :group 'typst-ts-watch) + +(defcustom typst-ts-watch-display-buffer-parameters + '(display-buffer-at-bottom + (window-height . fit-window-to-buffer)) + "Display buffer parameters. +Note that since the major mode of typst watch buffer is derived from compilation + mode. If you have a rule like `((derived-mode . compilation-mode) ...)' in +your `display-buffer-alist', then this option will be covered by that rule." + :type 'symbol + :group 'typst-ts-watch) + +(defvar typst-ts-watch-before-watch-hook nil + "Hook runs before compile.") +(defvar typst-ts-watch-after-watch-hook nil + "Hook runs after compile.") + + +(provide 'typst-ts-variables) + +;;; typst-ts-variables.el ends here + diff --git a/typst-ts-watch-mode.el b/typst-ts-watch-mode.el index 661340c560..4482d33133 100644 --- a/typst-ts-watch-mode.el +++ b/typst-ts-watch-mode.el @@ -22,6 +22,7 @@ ;;; Code: (require 'typst-ts-compile) +(require 'typst-ts-variables) (defgroup typst-ts-watch nil "Typst TS Watch." @@ -36,41 +37,6 @@ (typst-ts-watch-start) (typst-ts-watch-stop))) -(defcustom typst-ts-watch-options '() - "User defined compile options for `typst-ts-watch'. -The compile options will be passed to the -`<typst-executable> watch <current-file>' sub-command." - :type '(choice (repeat string) - (const :tag "Empty list" nil))) - -(defcustom typst-ts-watch-process-name "*Typst-Watch*" - "Process name for `typst watch' sub-command." - :type 'string) - -(defcustom typst-ts-watch-process-buffer-name "*Typst-Watch*" - "Process buffer name for `typst watch' sub-command." - :type 'string) - -(defcustom typst-ts-watch-auto-display-compilation-error t - "Whether the typst watch process buffer should be displayed automatically. -This means the buffer will be displayed when error occurs, hide when error -is eliminated." - :type 'boolean) - -(defcustom typst-ts-watch-display-buffer-parameters - '(display-buffer-at-bottom - (window-height . fit-window-to-buffer)) - "Display buffer parameters. -Note that since the major mode of typst watch buffer is derived from -compilation mode. -If you have a rule like `((derived-mode . `compilation-mode') ...)' -in your `display-buffer-alist', then this option will be covered by that rule." - :type 'symbol) - -(defvar typst-ts-watch-before-watch-hook nil - "Hook runs before compile.") -(defvar typst-ts-watch-after-watch-hook nil - "Hook runs after compile.") (defun typst-ts-watch--process-filter (proc output) "Filter the `typst watch' process output.