Code Monkey home page Code Monkey logo

yaifa's Introduction

Yaifa: Yet another indent finder, almost...

This plug-in will try to detect the kind of indentation used in your file and set the indenting options to the appropriate values. It recognizes three types of indentation:

  1. Space: Only spaces are used to indent.
  2. Tab: Only tabs are used.
  3. Mixed: A combination of tabs and space is used. e.g.: a tab stands for 8 spaces, but each indentation level is 4 spaces.

In order to guess the indentation of the buffer, it looks for increments in the indentation level and into the involved lines to see the type of indentation and the number of spaces of the change. The type of indentation with the most lines is used to set the options.

If Yaifa ever guesses wrong indentation, send me immediately a mail, if possible with the offending file, or open an issue on GitHub.

This script is based on Philippe Fremy's Python script Indent Finder, hence the "almost" part of the name.

yaifa's People

Contributors

jakseb avatar joeytwiddle avatar raimondi avatar

Stargazers

 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

yaifa's Issues

Doesn't work on new files

The plugin doesn't apply indention settings to new files (check e.g. vim foo).

As I see it, there's two ways to fix that:

  1. Add BufNewFile to the existing BufReadPost autocmd in https://github.com/Raimondi/yaifa/blob/master/plugin/yaifa.vim#L39
  2. Keep the default vimrc indention settings/do nothing whenever indention settings cannot be identified for a file. Essentially this would allow you to remove most of the existing yaifa settings and save a bit of performance & code.

Personally I like option 2 more, but maybe I overlooked something.

Side Note: https://github.com/Raimondi/yaifa/blob/master/doc/yaifa.txt#L124 is not about yaifa_disabled.

Other than that thanks a lot for this nice plugin! Keep on hacking! :-)

Prints first line of file when reloading python files

I've noticed that when reloading a python file (or also when navigating through the history), yaifa causes the first line of the file to be printed. To reproduce, simply open up any non-empty python file, and do :e.

For this to work, filetype plugins must be on, but removing my custom python ftplugin does not fix this, so that is probably not it. Removing all my .vimrc except filetype plugin on and removing all plugins except yaifa does not help either.

Tracing this in the code, it is somehow caused by this line:

\ . ' | unlet! b:indent_options_set'

I'm not actually sure what that says or is supposed to do, but removing it fixes the problem. This line was introduced in 93b2c0e, but that says to only move code, but the line was not present in the old file, so that does not really help me.

I thought that the \ might be intended as a line continuation, but putting it at the end of the previous line gives errors, and removing it and just joining the lines does not fix the problem...

I'm just going to try removing that line for now and see what happens.

Pathogen Support: Rearrange files

Most importantly, to put yaifa.vim into a subdirectory, plugin.

Pathogen is a plugin that'll search ~/.vim/bundle/ and add ~/.vim/bundle/foo/{plugin,doc,after,colors,...} to the runtime path, so that it's very easy. It's also great for version control, especially those with submodules (or related). That way many plugins are a git clone away from being installed.

Otherwise, no complaints. Awesome job!

editorconfig cooperation/support?

I'm not entirely sure what this approach would look like, but here goes:

It'd be very cool if yaifa could read the editorconfig file and derive the indentation settings from that. Or instead of reading it directly, using a "core" external program.

There is the editorconfig.vim plugin which provides this functionality. However installing both plugins results in conflicting settings when a file doesn't conform to what's in the editorconfig file. Maybe it has enough of an API to support direct integration?

So I figure something like this:

  • Indentation settings set from editorconfig take priority
  • Any settings that aren't set, use the heuristics from this plugin to fill in the gaps
  • Modelines fit into this somehow (always win?)

Errors when enabling debug output

I just installed latest master and enabled debug output:

let g:yaifa_debug=2

Then, when starting vim on some C-file, I get:

Error detected while processing function <SNR>40_apply_settings[14]..yaifa#magic[20]..yaifa#analyze_lines:
line   38:
E117: Unknown function: s:l2str
E116: Invalid arguments for function <SNR>40_log

This error repeats quite a few times.

Somehow, it cannot find the s:l2str function, though I can see it is actually defined in autoload/yaifa.vim as expected. I'm not sure why it cannot find it.

As a workaround, I renamed the function (and calls) to yaifa#l2str and then it works as expected. I'm not quite sure how vim scoping works, I'm just groping in the dark here, maybe this means more to others :-)

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.