Code Monkey home page Code Monkey logo

alternate-lite's Introduction

alternate-lite Last release Project Stats

Features

This plugin is meant to be a simplification of Michael Sharpe's alternate.vim plugin.

The design decisions that distinguishes alternate-lite from alternate are the following:

  • Support for project/buffer specific settings
  • Use dictionaries to set variables
  • Lazy definition of functions through autoload plugin
  • :IH commands and related mappings are already defined in my SearchInRuntime plugin.

My main use case for this plugin is to build things like lh-cpp's :GOTOIMPL command.

Commands

alternate-lite implements slightly differently all :A commands provided by original a.vim plugin.

All these commands first deduce an alternate file for the current one. The priority is given to files that exist. Then, they try to jump to the window where this alternate file is displayed, if the file wasn't displayed, it'll be opened:

  • In the current window with :A,
  • In a horizontally split opened window with :AS,
  • In a vertically split opened window with :AV,
  • In a new tab with :AT.

In case several alternate files are found, we'll be asked to choose which one we wish to open or to jump-to.

The previous commands also take an optional parameter: the extension we wish precisally to use to deduce the alternate file.

There is also the :AN command that permits to cycle through the buffers associated to the current buffer. If possible, this command will search for a window where the next buffer is already displayed.

Options

Some usual extensions are already registered. This can be extended globally, locally, on project basis, etc. See lh#ft#option#get().

You can obtain the latest status with a :echo g:alternates.extensions.

Extension map

Globally change the extension mappings

Let's say you want to register .tpp as a new extension for files where C++ template functions would be defined, you'll need to execute (in your .vimrc for instance):

" The actual {extension -> extensions} map
call lh#alternate#register_extension('g', 'h'  , g:alternates.extensions.h + ['tpp'])
call lh#alternate#register_extension('g', 'hpp', g:alternates.extensions.hpp + ['tpp'])
call lh#alternate#register_extension('g', 'tpp', ['h', 'hpp'])

" The {filetype -> extensions} map
let g:alternates.fts.cpp += ['tpp']
" Note: this last command can only be done after a call to any lh#alternate#* function

This says that this new extension may be used in all your projects.

The last line is important and required with filetypes that share some extensions like C, C++, ObjectiveC, and so on. Other filetypes like lex, yacc, OCaml, ASP... aren't concerned.

If you see that g:alternates.fts exists for the filetype to which you wish to register a new extension, then, don't forget to extend the associated list with the new extension.

Change the extension mappings for a given project only

If you prefer to register it only in one project, with lh-vim-lib project feature, you could define instead:

" The actual {extension -> extensions} map
call lh#alternate#register_extension('p', 'h'  , g:alternates.extensions.h + ['tpp'])
call lh#alternate#register_extension('p', 'hpp', g:alternates.extensions.hpp + ['tpp'])
call lh#alternate#register_extension('p', 'tpp', ['h', 'hpp'])

" The {filetype -> extensions} map
LetTo p:alternates.fts.cpp = g:alternates.fts.cpp + ['tpp']
" Note: this last command can only be done after a call to any lh#alternate#* function

In order to override the default values, just don't reuse them.

Directory selection

The option (bpg):[{ft}_]alternates.searchpath can contain a comma separated list of directory alternance policy:

  • A path with a prefix of "wdr:" will be treated as relative to the working directory.

  • A path prefix of "abs:" will be treated as absolute.

  • No prefix or "sfr:" will result in the path being treated as relative to the source file (see sfPath argument).

  • A prefix of "reg:" will treat the pathSpec as a regular expression substitution that is applied to the source file path. The format is:

    reg:<sep><pattern><sep><subst><sep><flag><sep>
    
    • <sep> seperator character, we often use one of [/|%#]
    • <pattern> is what you are looking for
    • <subst> is the output pattern
    • <flag> can be g for global replace or empty

Examples:

  • 'reg:/inc/src/g/' will replace every instance of 'inc' with 'src' in the source file path. It is possible to use match variables so you could do something like: 'reg:|src/\([^/]*\)|inc/\1||' (see 'help :substitute', 'help pattern' and 'help sub-replace-special' for more details

Note: ',' (comma) are used internally so DON'T use it in your regular expressions or other pathSpecs.

TODO

Many features from the original a.vim plugin are still missing, starting with :A* commands. I should eventually define them. For now I just need a simpler tool to define correctly lh-cpp's :GOTOIMPL command.

Installation

  • Requirements: Vim 7.+, lh-vim-lib v4.6.3

  • With vim-addon-manager, install alternate-lite. This is the preferred method because of the various dependencies.

ActivateAddons alternate-lite
  • or with vim-flavor which also supports dependencies:
flavor 'LucHermitte/alternate-lite'
  • or you can clone the git repositories (expecting I haven't forgotten anything):
git clone [email protected]:LucHermitte/lh-vim-lib.git
git clone [email protected]:LucHermitte/alternate-lite.git
  • or with Vundle/NeoBundle (expecting I haven't forgotten anything):
Bundle 'LucHermitte/lh-vim-lib'
Bundle 'LucHermitte/alternate-lite'

Credits

  • Michael Sharpe for his original plugin
  • Directory & regex enhancements added by Bindu Wavell who is well known on vim.sf.net

License

We grant permission to use, copy modify, distribute, and sell this software for any purpose without fee, provided that the above copyright notice and this text are not removed. We make no guarantee about the suitability of this software for any purpose and we are not liable for any damages resulting from its use. Further, we are under no obligation to maintain or extend this software. It is provided on an "as is" basis without any expressed or implied warranty.

alternate-lite's People

Contributors

luchermitte avatar

Stargazers

 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

Forkers

davidvandebunte

alternate-lite's Issues

Alternate to new file

This may be a problem with the underlying library and not this specific plugin. This problem can be worked around. I'll mention it anyway, because I use this plugin so often.
When using alternate-lite from foo.h and the file foo.cpp doesn't exist yet, Alternate will ask which file extension you want to use. The problem is that I don't know how you are supposed to choose an option.
Pressing enter only cancels the dialog and pressing the key in brackets will only get me the first option.
I tried to have just one option for a file extension, but that doesn't seem to work either. I placed this in my .vimrc:
call lh#alternate#register_extension('g', 'cpp', ['h'], 1) call lh#alternate#register_extension('g', 'h', ['cpp'], 1)
Also, pressing escape doesn't cancel the dialog.

Options in autoload

Having the following setting causes errors in the vimrc, after/plugin/xxx.vim and even in after/ftplugin/cpp/xxx.vim

let g:alternates.searchpath = 'sfr:.:

I believe this is because the options are set in the autoload/lh/alternate.vim so they are only created once a function from this file is called - after :GOTOIMPL
From what I could gather options should be set in plugin/alternate.vim instead so they can be overwritten before the first function call. A quick hack worked for me but I don't know enough about vimscript to make a quality pull request.

Move alternates initialization out of autoload

When I started setting this project up, it looked like I'd only need to change alternates.searchpath:

let g:alternates.searchpath='sfr:.,reg:|\(\a\+\)/include/\a\+|\1/src|g|,reg:|\(\a\+\)/src|\1/include/\1|g|'

Unfortunately this produces an error:

E121: Undefined variable: g:alternates

My workaround was to call a function that led to the autoload scripts running:

call lh#alternate#register_extension('g', 'h', ['hpp', 'cpp'])

It seems like it would be reasonable to move the initialization of alternates to the main script to avoid this for other users.

Alternate to file with an existing swap file gives errors

Not sure if there is still development on this plugin. This is a minor bug, but I'll mention it anyway.
When you have file foo.cpp open in vim and you type :AS to move to the header file vim will throw errors if the header file already has an existing swap file. The errors it gives are:

Error detected while processing function 
lh#alternate#_jump[35]..lh#buffer#jump[3]..lh#window#create
_window_with:
line    2:
E325: ATTENTION
Error detected while processing function lh#alternate#_jump:
line   35:
E171: Missing :endif

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.