casouri / emacs Goto Github PK
View Code? Open in Web Editor NEWThis project forked from emacs-mirror/emacs
Mirror of GNU Emacs
Home Page: http://www.gnu.org/software/emacs/
License: GNU General Public License v3.0
This project forked from emacs-mirror/emacs
Mirror of GNU Emacs
Home Page: http://www.gnu.org/software/emacs/
License: GNU General Public License v3.0
Hi there!
I've been trying to get this to work for some time now, but I cannot for the life of me get it to work. I'm using an M1 mac, so that might be an issue, but I don't think so.
(tree-sitter-available-p)
returns t
, and i've tried to move the dylibs around in different folders to get emacs to pick up on them. I've been following your RFC page and also the manuals, but no dice.
Non working recipe:
casouri/emacs
on ts branch, reports that it finds tree-sitter >= 0.0batch-new.sh
and move the files in dists
to /usr/local/bin
(among others)src/emacs
(require 'tree-sitter)
M-x ts-c-mode
All syntax highlighting dissapears, and tree-sitter-inspect-mode
shows nil. I assume this is because it cannot find the dylibs, but I'm stumped atm. Could you kindly give me some pointers as to what I'm missing? I'm sorry for the probably very stupid mistake I've made :)
Currently the best idea I can come up with is to periodically query the whole buffer and refresh the tree view. For example, in a Python buffer
class Cat():
def meow(self, pitch):
pass
def attack(self, force):
pass
def eat(self, food):
pass
class Dog():
def woof(self, pitch):
pass
def attack(self, force):
pass
def eat(self, food):
pass
def main():
pass
def error():
pass
def celebrate():
pass
Evaluating
(cl-flet ((get-name (n)
(tree-sitter-node-text
(tree-sitter-node-child-by-field-name n "name"))))
(tree-sitter-get-buffer-create 'tree-sitter-python)
(let ((classes (mapcar #'cdr
(tree-sitter-query-in
'tree-sitter-python
'((class_definition) @class))))
(functions (mapcar #'cdr
(tree-sitter-query-in
'tree-sitter-python
'((function_definition) @func))))
methods
filtered-classes
filtered-functions)
(dolist (class classes)
(let ((functions (mapcar #'cdr
(tree-sitter-query-in
class
'((function_definition) @func)))))
(setq methods (append functions methods))
(push (cons class functions) filtered-classes)))
(setq filtered-functions
(seq-difference functions methods #'tree-sitter-node-eq))
(with-current-buffer (get-buffer-create "*tree*")
(erase-buffer)
(dolist (class (reverse filtered-classes))
(insert (get-name (car class)) "\n")
(dolist (func (cdr class))
(insert "├─ " (get-name func) "\n"))
(forward-line -1)
(delete-char 1)
(insert "└")
(forward-line 1))
(dolist (func filtered-functions)
(insert (get-name func) "\n"))
(display-buffer (current-buffer)))))
displays
Cat
├─ meow
├─ attack
└─ eat
Dog
├─ woof
├─ attack
└─ eat
main
error
celebrate
你好,
我这边拉 emacs 最新代码,编译时 加了 --with-tree-sitter.
但是在使用时,有些疑问。
下面是我 tree-sitter 的一些高亮设置, 现在使用 自带的treesit 又怎么来设置呢?
(use-package tree-sitter
:ensure t
:custom-face
(tree-sitter-hl-face:operator ((t (:inherit default))))
;; (tree-sitter-hl-face:constant ((t (:foreground "LimeGreen"))))
;; c 语言结构体
(tree-sitter-hl-face:property ((t (:inherit font-lock-variable-name-face))))
(tree-sitter-hl-face:function.call ((t (:inherit font-lock-function-name-face
:underline t
:italic t))))
(tree-sitter-hl-face:function.method.call ((t)))
(tree-sitter-hl-face:method.call ((t (:inherit font-lock-function-name-face))))
:config
(global-tree-sitter-mode)
(setq tsc-dyn-get-from '(:github))
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs
:ensure t
:after tree-sitter)
简单复现
(progn
(require 'tree-sitter)
(tree-sitter-get-parser-create 'tree-sitter-elisp))
(tree-sitter-node-at (point))
Emacs
闪退Emacs
不会崩溃,执行结果正常返回。PS:Common Lisp和 html 的执行过程如下
;;; Common Lisp
(progn
(require 'tree-sitter)
(tree-sitter-get-parser-create 'tree-sitter-commonlisp))
(tree-sitter-node-at (point))
;;; HTML
(progn
(require 'tree-sitter)
(tree-sitter-get-parser-create 'tree-sitter-html))
(tree-sitter-node-at (point))
下面是测试文件的内容:
(defun fun ()
"文档字符串.")
(defun fun ()
"文档字符串.")
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>文档</title>
</head>
<body>
</body>
</html>
系统版本:debian 11,Emacs 为本仓库最新版本,语言定义采用 https://github.com/casouri/tree-sitter-module.git 里的脚本进行的编译:
Html 语言定义:https://github.com/tree-sitter/tree-sitter-html
Emacs Lisp 语言定义:https://github.com/Wilfred/tree-sitter-elisp,
Common Lisp 语言定义:https://github.com/theHamsta/tree-sitter-commonlisp
PS:其他的,暂时没有发现什么问题,运行良好,感谢作者的贡献,希望能够早日合并到 master.
Hi. Thank you for all you hard work making this.
I read through the Info manual and saw some "spelling" mistakes so here are all that I found:
37.2 Using Tree-sitter Parser
you have a function tree-sitter-create-parser
that doesn't exist. You probably intended to write tree-sitter-parser-create
instead.37.5 Pattern Matching Tree-sitter Nodes
for function tree-sitter-query-capture
the parameter list is wrong. It says that the beg
and end
parameters mandatory but in fact they are optional.37.5 Pattern Matching Tree-sitter Nodes
for function tree-sitter-query-string
the parameter list is not in the right order. In the info page it is query string language
but the real signature, shown in the help page, is string query language
.tree-sitter-load-name-override_list
. I guess that that underscore in the name of the variable is a mistake.That's all that I found. I wanted to write a pull request but I'm not very good at git so the best I could do is to write this issue here to alert you to there mistakes.
Hi! My question is about the lines:
Lines 1375 to 1380 in a4f90c5
In this branch queries are saved as strings and compiled in the internals on each use. In elisp-tree-sitter, you call tsc-make-query
and use
the object it returns for calls to tsc-query-captures
which is the analog for tree-sitter-query-capture
.
What happens if your query is deformed, or simply has a typo in a node name? We call tree-sitter-query-capture
on each keystroke in tree-sitter-font-lock-fontify-region
. With the compilation occurring ahead-of-time it would fail once, but here wouldn't it barrage you with errors?
Especially with patterns that aren't set in stone and can be modified like font-lock keywords, I think compiling the query when the pattern is added is better than on each execution.
One nice thing though about compiling queries only when queried is that you can call ts_query_delete
straight away. With users compiling queries it would need to be up to garbage collection, I think.
执行
git clone --branch ts https://github.com/casouri/emacs.git ./emacs-ts && cd emacs-ts
./autogen
./configure
make
......
CC emacs.o
In file included from emacs.c:88:
tree-sitter.h: 在函数‘CHECK_TS_PARSER’中:
tree-sitter.h:110:36: 错误:‘Qtree_sitter_parser_p’ undeclared (first use in this function); did you mean ‘Qtree_sitter_parser’?
110 | CHECK_TYPE (TS_PARSERP (parser), Qtree_sitter_parser_p, parser);
| ^~~~~~~~~~~~~~~~~~~~~
| Qtree_sitter_parser
tree-sitter.h:110:36: 附注:每个未声明的标识符在其出现的函数内只报告一次
tree-sitter.h: 在函数‘CHECK_TS_NODE’中:
tree-sitter.h:116:32: 错误:‘Qtree_sitter_node_p’ undeclared (first use in this function); did you mean ‘Qtree_sitter_node’?
116 | CHECK_TYPE (TS_NODEP (node), Qtree_sitter_node_p, node);
| ^~~~~~~~~~~~~~~~~~~
| Qtree_sitter_node
make[1]: *** [Makefile:415:emacs.o] 错误 1
make[1]: 离开目录“/home/xxxx/git-sources/emacs-ts/src”
make: *** [Makefile:463:src] 错误 2
git branch
Suppose I have:
Foo a;
a.ok();
a.x;
I would like to use different faces for "ok" and "x". How could one query to match "ok" here? It seems one could match by grouping "." and field_expression, like this:
(
(field_expression operator: ".")
(field_expression field: (field_identifier) @font-lock-function-name-face)
)
But doesn't seem to work?
hello!
I'm attempting to write a major mode based on your tree-sitter work and had a question regarding named captures. how would I write a query to font-lock a node based on the text of other, unrelated, nodes, e.g.:
((call_expression (member_expression ((identifier) @x (#match "foo" @x))) ((args) @font-lock-keyword-face)))
? my query is causing treesit-font-lock-fontify-region
to throw an error here:
(cond ((facep face)
(put-text-property start end 'face face))
((functionp face)
(funcall face start end node))
(t (error "Capture name %s is neither a face nor a function" face)))
which is correct - x
is neither a face nor a function. but I don't wish to apply font-locking to @x
at all. do I need to write a no-op function (e.g. (defun x (&rest ignored))
) so that (functionp face)
evaluates to t
, or is there some other workaround I should use? (or does this error even need to be thrown at all?)
thanks for all your hard work on treesit - apart from this small issue it's been amazingly smooth to work with so far!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.