emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

Do not quote generated lambda expressions #121

Closed tarsius closed 3 years ago

tarsius commented 3 years ago
Compiling /home/jonas/.emacs.d/lib/tree-sitter/lisp/tree-sitter-debug.el...

In tree-sitter-debug-mode:
lib/tree-sitter/lisp/tree-sitter-debug.el:109:7: Warning: (lambda nil \.\.\.)
    quoted with ' rather than with #'
Compiling /home/jonas/.emacs.d/lib/tree-sitter/lisp/tree-sitter-extras.el...
Compiling /home/jonas/.emacs.d/lib/tree-sitter/lisp/tree-sitter-hl.el...

In tree-sitter-hl-mode:
lib/tree-sitter/lisp/tree-sitter-hl.el:643:7: Warning: (lambda nil \.\.\.)
    quoted with ' rather than with #'

(No quoting is needed. You could wrap the lambda in function, but that doesn't really do anything, see http://www.gnu.org/software/emacs/manual/html_node/elisp/Anonymous-Functions.html)

ubolonton commented 3 years ago

This can be called multiple times in a buffer, so the add-hook call needs to be idempotent. Using an unquoted lambda form may create a different closure each time, depending on the lexical environment. Therefore quoting is needed.

A better fix would be tracking dependent modes to disable via another mechanism, e.g. a buffer-local variable.

tarsius commented 3 years ago

Ah, silly me I should have noticed the comment.

How about just suppressing the warnings?

Suppress warning about quoted lambda

As the preceding comment says, "Quoting is important, because we don't want a variable-capturing closure", but we also don't want the warnings to distract us from any warnings that might show up over time, so we suppress these warnings.

ubolonton commented 3 years ago

Thanks! I didn't know about with-no-warnings.