all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60602: 29.0.60; treesit-simple-indent doesn't work for top-level nodes
@ 2023-01-06 13:40 Piotr Trojanek
  2023-01-06 14:55 ` Dmitry Gutov
  2023-01-09  3:13 ` Yuan Fu
  0 siblings, 2 replies; 7+ messages in thread
From: Piotr Trojanek @ 2023-01-06 13:40 UTC (permalink / raw)
  To: 60602

This problem can be reproduced with a correctly configured c-ts-mode,
which fails to indent the first line of a code like this, i.e. with
extra space at the very beginning of file and cursor positioned at
"main"):

===
   int main (int argc, char *argv[])
{
  return 0;
}
===

The intent of c-ts-mode--indent-styles is clearly to indent this line
to 0th column:

(defun c-ts-mode--indent-styles (mode)
  ...
         `(((parent-is "translation_unit") parent-bol 0)

However, when indenting this line treesit-simple-indent is called with
node=translation_unit and parent=nil. It exits too early and doesn't
consider any indentation rules:

(defun treesit-simple-indent (node parent bol)
  "..."
  (if (null parent)
      (progn (when treesit--indent-verbose
               (message "PARENT is nil, not indenting"))
             (cons nil nil))

Note that other tree-sitter modes have similar indentation rules, e.g.
ruby-ts-mode.el:

   ;; Slam all top level nodes to the left margin
   ((parent-is "program") parent 0)

and same for typescript-ts-mode.el:

  ((parent-is "program") parent-bol 0)

Perhaps the early exit from treesit-simple-indent could be removed, so
the indentation rules can decide how to handle a nil parent.

In GNU Emacs 29.0.60 (build 4, x86_64-pc-linux-gnu, GTK+ Version
 3.24.24, cairo version 1.16.0) of 2023-01-06 built on mobile
Repository revision: 7420b6dcc379617ca9691049c16bfb2d158f9496
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --prefix=/opt/emacs-29 --with-tree-sitter'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-06  0:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-06 13:40 bug#60602: 29.0.60; treesit-simple-indent doesn't work for top-level nodes Piotr Trojanek
2023-01-06 14:55 ` Dmitry Gutov
2023-01-09  3:13 ` Yuan Fu
2023-01-20 21:40   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-20 21:45     ` Dmitry Gutov
2023-01-20 21:52       ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-06  0:09         ` Stefan Kangas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.