GNU bug report logs - #77256
Treesit language-at-point

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 25 Mar 2025 18:44:02 UTC

Severity: normal

Fixed in version 31.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Juri Linkov <juri <at> linkov.net>
Cc: Yuan Fu <casouri <at> gmail.com>, Vincenzo Pupillo <v.pupillo <at> gmail.com>, 77256 <at> debbugs.gnu.org
Subject: bug#77256: Treesit language-at-point
Date: Wed, 09 Apr 2025 11:02:28 -0400
>> Is it?
>> I can't find any code out there that seems to care what is its default
>> value (all users set it but doesn't look at it, AFAICT).
>
> This case looks problematic:
>
>                  ;; LANG can be nil.  We don't want to use the fallback
>                  ;; in `treesit-language-at', so here we call
>                  ;; `treesit-language-at-point-function' directly.
>                  (let* ((lang (and treesit-language-at-point-function
>                                    (funcall treesit-language-at-point-function
>                                             pos)))

Ah, indeed you're right.

> But I believe this whole 'let*' can be replaced by just
> the 'treesit-parsers-at' call.  I hope Yuan could confirm this.

[ Not familiar enough with this code, so I'll let Yuan chime in.  ]

> If no more code outside relies on the default value,
> the default function could be added like this:
[...]
> -  (if treesit-language-at-point-function
> -      (funcall treesit-language-at-point-function position)
> -    (treesit-parser-language
> -     (car (treesit-parsers-at position)))))
> +  (funcall treesit-language-at-point-function position))

Usually, I use something like:

    (funcall (or treesit-language-at-point-function
                 #'treesit-language-at-point-default)
             position)

when I make such a change, so as to preserve some compatibility with
code that sets the var to nil.

> BTW, I noticed now that indentation of the default value
> in defvar-local is incorrect and differs from defvar and defcustom.
> Here is the fix:
>
> diff --git a/lisp/subr.el b/lisp/subr.el
> index be847aab28a..164ed2a6f63 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -197,7 +197,7 @@ defvar-local
>  Like `defvar' but additionally marks the variable as being automatically
>  buffer-local wherever it is set.
>  \n(fn SYMBOL &optional VALUE DOCSTRING)"
> -  (declare (debug defvar) (doc-string 3) (indent 2))
> +  (declare (debug defvar) (doc-string 3) (indent defun))
>    ;; Can't use backquote here, it's too early in the bootstrap.
>    (let ((value (car-safe args))
>          (docstring (car-safe (cdr-safe args))))

Good call, feel free to push, thanks.


        Stefan





This bug report was last modified 91 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.