Skip to content

indent‐bars config Wiki

Elijah Gabe Pérez edited this page Feb 24, 2025 · 16 revisions

Include information about tested configurations here. Please add to the relevant language/mode section.

Tested config and customization (including tree-sitter)

Include your validated config using tree-sitter here:

Note

As of v0.2, indent-bars can use tree-sitter to avoid adding more bars than necessary inside wrapping elements: typically function call/definition argument lists, and other nested structures. It can also omit styling on "top-level" blank lines in the file, e.g. in the "module" of a python file, and (by default) doesn't descend deeper into strings. In v0.5, scope focus was introduced, allowing alternative bar styling within and outside the current configurable "scope", as determined by tree-sitter.

Python

In use-package style:

with TS wrap detection

  :custom
  (indent-bars-treesit-support t)
  (indent-bars-treesit-wrap '((python argument_list parameters
				      list list_comprehension
				      dictionary dictionary_comprehension
				      parenthesized_expression subscript)))
  (indent-bars-treesit-ignore-blank-lines-types '("module"))

simple list detection, with TS scope

  :custom
  (indent-bars-treesit-support t)
  (indent-bars-no-descend-lists t)
  (indent-bars-treesit-scope '((python function_definition class_definition for_statement
				       if_statement with_statement while_statement)))
  (indent-bars-treesit-ignore-blank-lines-types '("module"))

C/C++

In use-package style:

:custom
(indent-bars-treesit-support t)
(indent-bars-treesit-wrap '((c argument_list parameter_list init_declarator parenthesized_expression)))
; alternative to wrap:
; (indent-bars-no-descend-lists '(?\[ ?\()) ; prevent {} from being treated like lists!

Rust

In use-package style:

:custom
(indent-bars-treesit-support t)
(indent-bars-treesit-wrap '((rust arguments parameters)))
(indent-bars-treesit-scope '((rust trait_item impl_item 
                                   macro_definition macro_invocation 
                                   struct_item enum_item mod_item 
                                   const_item let_declaration 
                                   function_item for_expression 
                                   if_expression loop_expression 
                                   while_expression match_expression 
                                   match_arm call_expression 
                                   token_tree token_tree_pattern 
                                   token_repetition)))

Lua

In use-package style:

:custom
(indent-bars-treesit-support t)
(indent-bars-treesit-wrap '((lua
                             expression_list function_declaration if_statement
                             elseif_statement else_statement while_statement for_statement
                             repeat_statement comment)))

TOML

In use-package style:

:custom
(indent-bars-treesit-support t)
(indent-bars-treesit-wrap '((toml
                             table array comment)))

YAML

In use-package style:

:custom
(indent-bars-treesit-support t)
(indent-bars-treesit-wrap '((yaml
                             block_mapping_pair comment)))

Emacs Lisp

It is possible to use treesit.el parsing capabilities with the emacs-lisp-mode.

To achieve this you can define a function like this:

(defun my/treesit-parser-for-lang-mode (lang-mode-symbol)
    (when (and (treesit-available-p)
               (treesit-language-available-p lang-mode-symbol))
      (treesit-parser-create lang-mode-symbol)))

then add it to the mode hook:

;; In use-package style:
:hook
(emacs-lisp-mode . (lambda () (my/treesit-parser-for-lang-mode 'elisp)))

and use it in your configuration:

:custom
(indent-bars-treesit-support t)
(indent-bars-no-descend-lists t)
(indent-bars-treesit-wrap
 '((elisp
    quote special_form function_definition)))