Skip to content

Commit

Permalink
Merge pull request #53 from emacs-php/add-treesit-language-source-alist
Browse files Browse the repository at this point in the history
Add treesit-language-source-alist for grammar installation
  • Loading branch information
zonuexe authored Jan 28, 2024
2 parents b2bcfe2 + 2935dad commit 8e60a23
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@

A Tree-sitter based major mode for editing PHP codes.

> **Warning**
> This package is still in early development and will not work.
> It's just that the java-ts-mode keyword has been replaced with PHP.
> [!NOTE]
> This package is based on Emacs 29's built-in [`treesit`][treesit] and `c-ts-common` features.
> `php-ts-mode` has been tested with [v0.21.1][] of [tree-sitter-php][].
[treesit]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Language-Grammar.html
[tree-sitter-php]: https://github.com/tree-sitter/tree-sitter-php
[v0.21.1]: https://github.com/tree-sitter/tree-sitter-php/releases/tag/v0.21.1

## How to install

If you haven't installed Tree-sitter yet, please read [How to Get Started with Tree-Sitter - Mastering Emacs][]. At this point, Tree-sitter may be too early for those who cannot compile and install it themselves. You will end up recompiling it with every future update of [tree-sitter-php][].

[How to Get Started with Tree-Sitter - Mastering Emacs]: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter

### Grammer installation

If you don't already have `php-ts-mode` installed, please evaluate the Lisp code below.

```elisp
(add-to-list 'treesit-language-source-alist
'(php "https://github.com/tree-sitter/tree-sitter-php" "master" "php/src"))
```

Running `M-x treesit-install-language-grammar [RET] php` will compile and install the latest [tree-sitter-php][].

## How to develop

1. Chekout [tree-sitter-php](https://github.com/tree-sitter/tree-sitter-php) to your computer.
1. Chekout [tree-sitter-php][] to your computer.
2. Do `make install`

## Copyright
Expand Down
4 changes: 4 additions & 0 deletions php-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,9 @@ Currently there are `php-mode' and `php-ts-mode'."
(when (treesit-ready-p 'php)
(add-to-list 'auto-mode-alist '("\\.php[s345]?\\'" . php-ts-mode)))

;;;###autoload
(add-to-list 'treesit-language-source-alist
'(php "https://github.com/tree-sitter/tree-sitter-php" "master" "php/src"))

(provide 'php-ts-mode)
;;; php-ts-mode.el ends here

0 comments on commit 8e60a23

Please sign in to comment.