Giter Club home page Giter Club logo

casouri / emacs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emacs-mirror/emacs

13.0 13.0 2.0 1.3 GB

Mirror of GNU Emacs

Home Page: http://www.gnu.org/software/emacs/

License: GNU General Public License v3.0

Makefile 0.48% C 21.44% Perl 0.15% Emacs Lisp 75.00% Awk 0.04% Shell 0.19% HTML 0.12% C++ 0.40% PostScript 0.18% TeX 0.67% Smalltalk 0.06% Erlang 0.01% NewLisp 0.06% Ruby 0.11% Slash 0.06% SystemVerilog 0.06% Ada 0.05% Prolog 0.09% Objective-C 0.83% Java 0.01%

emacs's People

Contributors

acinnes avatar albinus avatar andreacorallo avatar andreas-schwab avatar belanger avatar dgutov avatar dmantipov avatar drmirror avatar eggert avatar eli-zaretskii avatar jave avatar joaotavora avatar larsmagne avatar lektu avatar leoliu avatar link0ff avatar loveshack avatar mattiase avatar mituharu avatar monnier avatar npostavs avatar paveljanik avatar phst avatar rgmorris avatar sam-s avatar skangas avatar snogglethorpe avatar tsdh avatar wohler avatar yamaoka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

emacs's Issues

Errors in the Info manual

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:

  • under 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.
  • under 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.
  • also under 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.
  • and last you have a variable 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.

query cpp member function call for fontifying

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?

Query compilation?

Hi! My question is about the lines:

emacs/src/tree-sitter.c

Lines 1375 to 1380 in a4f90c5

/* TODO: We could cache the query object, so that repeatedly
querying with the same query can reuse the query object. It also
saves us from expanding the sexp query into a string. I don't
know how much time that could save though. */
TSQuery *ts_query = ts_query_new (lang, source, strlen (source),
&error_offset, &error_type);

Regarding error handling mostly.

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.

treesit 高亮设置

你好,
我这边拉 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)

文档中存在中文字体时会崩溃...

简单复现

  1. 准备一个含有中文字体的文件(我测试了 html,common lisp,elisp)
  2. 输入 M-: 执行
(progn
  (require 'tree-sitter)
  (tree-sitter-get-parser-create 'tree-sitter-elisp))
  1. 执行
    (tree-sitter-node-at (point))
    Emacs 闪退
  2. 如果最初的文件里没有中文,在执行上面操作后,在往文件里添加中文,则此时 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))

下面是测试文件的内容:

  1. Emacs lisp
(defun fun ()
  "文档字符串.")
  1. Common lisp
(defun fun ()
  "文档字符串.")
  1. HTML
<!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.

Support imenu-like feature

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

Tree sitter integration is not triggering

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:

  1. Compile casouri/emacs on ts branch, reports that it finds tree-sitter >= 0.0
  2. Run batch-new.sh and move the files in dists to /usr/local/bin (among others)
  3. Launch emacs from src/emacs
  4. (require 'tree-sitter)
  5. Open some C file
  6. 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 :)

bilde

编译出错:tree-sitter.h: 在函数‘CHECK_TS_PARSER’中:

执行
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

  • ts

error raised when capture name is neither a face nor a function

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.