branch: elpa/typst-ts-mode commit 5169b63ef103aa16f12192c8ff173ad224973c9d Author: Meow King <mr.meowk...@anche.no> Commit: Meow King <mr.meowk...@anche.no>
doc: update README and change copyright infromation --- .gitignore | 2 +- README.md | 96 ++++++++++++++++++++++++------------- side/sync_with_upstream.typ | 4 +- typst-ts-compile.el | 2 +- typst-ts-edit-indirect.el | 2 +- typst-ts-embedding-lang-settings.el | 2 +- typst-ts-faces.el | 2 +- typst-ts-mode.el | 5 +- typst-ts-utils.el | 2 +- typst-ts-watch-mode.el | 2 +- 10 files changed, 77 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 4c0e86d826..f12b74e6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.elc /side/*.pdf -/makem.sh +makem.sh # Added by cargo diff --git a/README.md b/README.md index fe882dbcf1..2337e30c93 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Tree Sitter support for Typst. Minimum Emacs version requirement: 29. - - [Discussion on Zulip](https://meow-place.zulipchat.com/) [Tickets](https://todo.sr.ht/~meow_king/typst-ts-mode): Issues, feature requests, etc. [Announce](https://lists.sr.ht/~meow_king/typst-ts-mode-announce) Announcements. Subscribe to it to receive the latest news for `typst-ts-mode`. @@ -26,7 +24,7 @@ Tree Sitter support for Typst. Minimum Emacs version requirement: 29. (treesit-install-language-grammar 'typst) ``` - Note there are also [tree sitter modules](https://github.com/casouri/tree-sitter-module), [treesit-auto](https://github.com/renzmann/treesit-auto) and [treesit-langs](https://github.com/kiennq/treesit-langs) for you to easily manage your tree sitter modes and grammars. + Note there are also [tree sitter modules](https://github.com/casouri/tree-sitter-module), [treesit-auto](https://github.com/renzmann/treesit-auto) and [treesit-langs](https://github.com/kiennq/treesit-langs) for you to easily manage your tree sitter modes and grammars. For vanilla solution, there is my [configuration](https://github.com/Ziqi-Yang/.emacs.d/blob/main/languages/l-treesit.el) for reference. ## Installation @@ -34,7 +32,8 @@ Example configuration. ``` emacs-lisp (use-package typst-ts-mode :ensure (:type git :host sourcehut :repo "meow_king/typst-ts-mode" :files (:defaults "*.el")) - ;; (optional) checking typst grammar version needs it + :custom + ;; (optional) If you want to ensure your typst tree sitter grammar version is greater than the minimum requirement (typst-ts-mode-grammar-location (expand-file-name "tree-sitter/libtree-sitter-typst.so" user-emacs-directory))) ``` @@ -58,35 +57,28 @@ defined by `outline-minor-mode` such as `outline-cycle`. ## Customization Options -For customizable options: `customize` -> `typst-ts`. +You can view all the custom options in Emacs using `customize` command. Go to `typst-ts` group. Here are some options you may find useful: 1. **typst-ts-mode-indent-offset** (default 4) - Use [outline-indent-mode](https://sr.ht/~meow_king/outline-indent-mode/) to behave like `org-indent-mode`. + If you want to have `org-indent-mode` like behavior, you can use [outline-indent-mode](https://sr.ht/~meow_king/outline-indent-mode/) plugin. 2. **typst-ts-compile-executable-location** + You can set a custom typst executable location. 3. **typst-ts-watch-options**. - Set this to `--open` so typst will open the compiled file for you. + Set this to `--open` so typst will automatically open the compiled file for you when you enter `typst-ts-watch-mode`. 4. **typst-ts-compile-options**. - Note that setting `--open` has no use for this customization variable. - You can execute the shell command `typst compile <file> --open && sleep 1` - to view what is happening. + Note that setting `--open` has no use for this customization variable. You can execute command `async-shell-command` and input `typst compile <file> --open && sleep 1` to view what is happening. Use command `typst-ts-compile-and-preview` if you want to view the output document after compiling. 5. **typst-ts-watch-auto-display-compilation-error**. (default `t`) - so the `typst watch` process buffer appear when an error occurs, and - disappear when there is no error. You may find sometimes there is only one - error at a time, and it is because Typst itself do this style. - You may find `auto-save-visited-mode`, - [auto-save](https://github.com/manateelazycat/auto-save) or - [super-save](https://github.com/bbatsov/super-save) useful (or annoying). + This variable controls whether `typst watch` process buffer will appear when an error occurs, and disappear when there is no error. + You may find `auto-save-visited-mode`, [auto-save](https://github.com/manateelazycat/auto-save) or [super-save](https://github.com/bbatsov/super-save) useful (or annoying). 6. **typst-ts-compile-before-compilation-hook** and **typst-ts-compile-after-compilation-hook** -7. **typst-ts-mode-return-autoincrement** auto-increment lists when pressing RETURN (default `t`). -8. **typst-ts-mode-grammar-location**: used for grammar version check at major mode start. +7. **typst-ts-mode-grammar-location**: used for grammar version check at major mode start. ### Fontification 1. **typst-ts-mode-fontification-precise-level** (default `'middle`) Available values: `min`, `middle` and `max`. Different level affects the precision - of the fontification. For example, `- item`, we may fontify the whole expression - using one face, or two faces. Note it is related to the performance of fontification - process, especially the first fontification process (when you open the file). + of the fontification. For example, to fontify `- item`, we may fontify the whole expression + using one face, or two faces (one for `-`, and one for `item`). Note it is related to the performance of fontification process, especially the first fontification process (when you open the file). 2. **typst-ts-markup-header-same-height** and **typst-ts-markup-header-scale** Control header height. Note that it only works when **typst-ts-mode-fontification-precise-level** is set to `max`. @@ -97,8 +89,8 @@ Here are some options you may find useful: ### Raw block highlighting _This is an experimental feature_ -**Note**: currently only support Emacs 30 (master branch). But non-treesit font lock for raw block feature will be added soon (both 29 and 30). Only support tree-sitter languages. +**Note**: Currently only support Emacs 30 (master branch). But non-treesit font lock for raw block feature will be added soon (both 29 and 30). For more detailed documentation about raw block highlighting see [this documentation](./doc/raw-block-highlighing.md) 1. **typst-ts-mode-enable-raw-blocks-highlight** (default `nil`) @@ -119,17 +111,57 @@ command [consult](https://github.com/minad/consult), you way want this setting. ## Contribute -1. please work on `develop` branch, which will be combined into `main` branch every one week or so. +Please work on `develop` branch, which will be combined into `main` branch every one week or so if there are new commits. +This document [./side/sync_with_upstream.typ](./side/sync_with_upstream.typ) shows information related to synchronous status with upstream grammar. + +### Tree Sitter Resources +1. `(info "(elisp) Parser-based Font Lock")` and `(info "(elisp) Parsing Program Source")` (Use `eval-expression` command to jump to the corresponding Info Manual Node) +2. [Let’s Write a Tree-Sitter Major Mode - Matering Emacs](https://www.masteringemacs.org/article/lets-write-a-treesitter-major-mode) +3. [ts-query-highlight](https://sr.ht/~meow_king/ts-query-highlight/). I wrote this package to highlight tree sitter queries. This package is used in the process of building `typst-ts-mode`. +4. All common treesit operations can be viewd using command `shortdoc` + +### Package Development + +#### How to load all files used by this packages? +This snippet is taken from [The Emacs Package Developer’s Handbook - Byte-compile and load directory](https://github.com/alphapapa/emacs-package-dev-handbook?tab=readme-ov-file#byte-compile-and-load-directory) with some modification. + +```emacs-lisp +(defun others/byte-compile-and-load-directory (directory) + "Byte-compile and load all elisp files in DIRECTORY. +Interactively, directory defaults to `default-directory' and asks +for confirmation." + (interactive (list default-directory)) + (let* ((load-path (cons directory load-path)) + (files (directory-files directory 't (rx ".el" eos)))) + (dolist (file files) + (byte-compile-file file 'load)))) +``` +#### How to eval a buffer and override the origin definitions +You can use `eval-defun` to eval and override a function definition. However, to eval and override a buffer, `eval-buffer` doesn't work. +This snippet is taken from [How do I force re-evaluation of a defvar? - François Févotte - emacs.stackexchange.com](https://emacs.stackexchange.com/a/2302) with some modification. + +```emacs-lisp +(defun others/eval-buffer () +"Execute the current buffer as Lisp code. +Top-level forms are evaluated with `eval-defun' so that `defvar' +and `defcustom' forms reset their default values." + (interactive) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (forward-sexp) + (eval-defun nil)))) +``` + +#### How to do lint +I recommend you to use [makem.sh](https://github.com/alphapapa/makem.sh). However, you can choose anything you like. +To use it, first `cd` into the project root directory, then: +```emacs-lisp +wget https://raw.githubusercontent.com/alphapapa/makem.sh/master/makem.sh +chmod +x ./makem.sh +``` +To do `lint`, you can execute shell command `./makem.sh lint` ## Co-Maintainer [Huan Nguyen](https://sr.ht/~huan) - -## Do you want to develop a new Tree Sitter Major Mode? - -Here are some resources: -- [Let’s Write a Tree-Sitter Major Mode - Matering Emacs](https://www.masteringemacs.org/article/lets-write-a-treesitter-major-mode) -- [ts-query-highlight](https://sr.ht/~meow_king/ts-query-highlight/) - I wrote this package to highlight tree sitter queries. I use this package to help -developing `typst-ts-mode`. -- [combobulate](https://github.com/mickeynp/combobulate) diff --git a/side/sync_with_upstream.typ b/side/sync_with_upstream.typ index 877f59db8d..f5d65482ee 100644 --- a/side/sync_with_upstream.typ +++ b/side/sync_with_upstream.typ @@ -97,5 +97,7 @@ Use `git diff` or `git blame` to get the grammar change. [`["," ";" ".." ":" "sep"] @punctuation.delimiter`], yes, [`"assign" @punctuation`] , yes, [`(field "." @punctuation)`] , yes, -) + tableSep([ Node not included in `/queries/typst/highlights.scm` ]), + [ `(code)` ], [ HAVEN'T ADDED since it isn't visual (for highlighting) and doesn't affect indentation ] +) diff --git a/typst-ts-compile.el b/typst-ts-compile.el index fc9a6b0cfa..deef37df61 100644 --- a/typst-ts-compile.el +++ b/typst-ts-compile.el @@ -1,5 +1,5 @@ ;;; typst-ts-compile.el --- Compile Typst Files -*- lexical-binding: t; -*- -;; Copyright (C) 2024 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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 diff --git a/typst-ts-edit-indirect.el b/typst-ts-edit-indirect.el index 115a43b52d..66add1aa7b 100644 --- a/typst-ts-edit-indirect.el +++ b/typst-ts-edit-indirect.el @@ -1,5 +1,5 @@ ;;; typst-ts-watch-mode.el --- Edit blocks in separate buffer -*- lexical-binding: t; -*- -;; Copyright (C) 2023 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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 diff --git a/typst-ts-embedding-lang-settings.el b/typst-ts-embedding-lang-settings.el index 7372350db5..f5d6039a88 100644 --- a/typst-ts-embedding-lang-settings.el +++ b/typst-ts-embedding-lang-settings.el @@ -1,5 +1,5 @@ ;;; typst-ts-embedding-lang-settings.el --- Embedding Languages Settings -*- lexical-binding: t; -*- -;; Copyright (C) 2023 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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 diff --git a/typst-ts-faces.el b/typst-ts-faces.el index 4338285121..74951ecb08 100644 --- a/typst-ts-faces.el +++ b/typst-ts-faces.el @@ -1,5 +1,5 @@ ;;; typst-ts-faces.el --- typst-ts-mode faces -*- lexical-binding: t; -*- -;; Copyright (C) 2023 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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 diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 7e92efc8d6..37c24aca3c 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -1,9 +1,10 @@ ;;; typst-ts-mode.el --- Tree Sitter support for Typst -*- lexical-binding: t; -*- - -;; Copyright (C) 2023 Ziqi Yang <mr.meowk...@anche.no> +;; Copyright (C) 2023 The typst-ts-mode Project Contributors ;; Version: 0.10.0 ;; Author: Ziqi Yang <mr.meowk...@anche.no> +;; Maintainer: Ziqi Yang <mr.meowk...@anche.no> +;; Huan Nguyen <nguyenthieuh...@gmail.com> ;; Keywords: typst languages tree-sitter ;; URL: https://git.sr.ht/~meow_king/typst-ts-mode ;; License: GNU General Public License >= 3 diff --git a/typst-ts-utils.el b/typst-ts-utils.el index 7ee59a208a..8113b71138 100644 --- a/typst-ts-utils.el +++ b/typst-ts-utils.el @@ -1,5 +1,5 @@ ;;; typst-ts-utils.el --- utility functions for typst-ts-mode -*- lexical-binding: t; -*- -;; Copyright (C) 2024 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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 diff --git a/typst-ts-watch-mode.el b/typst-ts-watch-mode.el index 9873e1c5bf..b0a62ffd7b 100644 --- a/typst-ts-watch-mode.el +++ b/typst-ts-watch-mode.el @@ -1,5 +1,5 @@ ;;; typst-ts-watch-mode.el --- Watch typst file -*- lexical-binding: t; -*- -;; Copyright (C) 2023 Meow King <mr.meowk...@anche.no> +;; Copyright (C) 2023 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