Giter Site home page Giter Site logo

smarttab.kak's Introduction

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.

smarttab.kak's People

Contributors

andreyorst avatar clarfonthey avatar ordoviz avatar valpackett avatar vbauerster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

smarttab.kak's Issues

How to set default mode?

I understand that this plugin provides commands. I can run these commands manually from within a Kakoune buffer. But how do I set one of the commands in my kakrc so it becomes the default? For example, I added expandtab at the end of my kakrc, but it didn't work. Also, I don't think I can set expandtab as an option a la, set-option global expandtab. So how can I do it?

Thanks

Indentation is always 8 spaces wide.

Hi,

I installed the plugin with kak following your example:

plug "andreyorst/smarttab.kak" %{
    set-option global softtabstop 4 # or other preferred value
}

then: :plug-install

Installation done, I close kakoune and open a new one. When I start to write and press tab is always 8 spaces wide.

The only other addon installed is fzf.

--

Not really related but where should I declare the option expandtab? I'm new to kakoune and don't find the correct place or way to declare it (excepting doing it manually).

Overwrite default mode only when .editorconfig file is present

I want to use smarttab as the default option, but allow overwriting it when an editorconfig file is present.

I've tried the following setup:

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

but it doesn't seem to do what I want (I'm not knowledgeable enough about kakoune to figure out how to properly configure it).

Is there a way to make this work with smarttab.kak?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.