Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
/ smarttab.kak Public archive

Automatic handling different styles of indentation and alignment.

License

Notifications You must be signed in to change notification settings

andreyorst/smarttab.kak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

smarttab.kak

license

smarttab.kak is a plugin for Kakoune. It provides three different ways for handling indentation and alignment with the tab key.

Installation

Add this to your kakrc:

plug "andreyorst/smarttab.kak"

Source your kakrc, or restart Kakoune. Then execute :plug-install. Or, if you don't want to restart Kakoune or source its config, simply run plug-install andreyorst/smarttab.kak. It will then be enabled automatically.

Without plugin manager

Clone this repo:

git clone https://github.com/andreyorst/smarttab.kak.git

You can put this repo in your autoload directory, or else manually source the smarttab.kak script in your configuration file.

After that, you can use smarttab.kak.

Usage

This plugin adds three commands to toggle between different policies when using the Tab and > keys:

  • noexpandtab - use tab for everything. Tab will insert the \t character, and > will use the \t character when indenting. Aligning cursors with & uses the \t character.
  • expandtab - use space for everything. Tab will insert %opt{indentwidth} amount of spaces, and > will indent with spaces.
  • smarttab - indent with tab, align with space. Tab will insert the \t character if your cursor is inside an indentation area, e.g., before any non-whitespace character, and insert spaces if the cursor is after any non-whitespace character. Aligning cursors with & uses space.
  • autoconfigtab - choose the above based upon one of the existing settings (see later section).

By default, smarttab.kak affects only the Tab and > keys. If you want to deindent lines that are being indented with spaces when hitting Backspace, you can set the softtabstop option. This option specifies how many spaces should be treated as a single tab character when deleting them with a backspace.

In order to automatically enable different modes for different languages, you can use hooks like so:

hook global WinSetOption filetype=c smarttab
hook global WinSetOption filetype=rust expandtab

To adjust smarttab.kak related options, you need to use the ModuleLoaded hook, because all options are defined withing the smarttab module:

hook global ModuleLoaded smarttab %{
    set-option global softtabstop 4
    # you can configure text that is being used to represent curent active mode
    set-option global smarttab_expandtab_mode_name 'exp'
    set-option global smarttab_noexpandtab_mode_name 'noexp'
    set-option global smarttab_smarttab_mode_name 'smart'
}

If you've used plug.kak for installation, it's better to configure smarttab.kak from within the plug command because it can handle lazy loading the configurations for the plugin, as well as configure the editor's behavior:

plug "andreyorst/smarttab.kak" defer smarttab %{
    # when `backspace' is pressed, 4 spaces are deleted at once
    set-option global softtabstop 4
} config %{
    # these languages will use `expandtab' behavior
    hook global WinSetOption filetype=(rust|markdown|kak|lisp|scheme|sh|perl) expandtab
    # these languages will use `noexpandtab' behavior
    hook global WinSetOption filetype=(makefile|gas) noexpandtab
    # these languages will use `smarttab' behavior
    hook global WinSetOption filetype=(c|cpp) smarttab
}

Setting the default mode

In your kakrc add:

hook global BufOpenFile .* _mode_
hook global BufNewFile  .* _mode_

Where the _mode_ is one of the smarttab.kak modes, described above.

autoconfigtab configuration

If you just want to set the behavior based upon your editorconfig settings, you can use the autoconfigtab setting:

hook global BufCreate .* %{
    editorconfig-load
    autoconfigtab
}

This config will choose expandtab or noexpandtab based upon whether indent_style is set as space or tab respectively.

If you'd prefer to use smarttab instead of noexpandtab for indent_style = tab (without affecting indent_style = space), you can manually override the aligntab option to false before running autoconfigtab, as seen in the below config:

hook global BufCreate .* %{
    editorconfig-load
    set-option buffer aligntab false
    autoconfigtab
}

Currently, autoconfigtab does not cover the case where indentwidth is nonzero but aligntab is set to true, as this would mean indenting with spaces and aligning with tabs. In this particular case, tab alignment takes priority and noexpandtab is chosen.

About

Automatic handling different styles of indentation and alignment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published