Giter Site home page Giter Site logo

vim2hs's Introduction

vim2hs ⦂ Vim → Haskell

"Vim to Haskell": A collection of vimscripts for Haskell development.

Features

  • Written from scratch for clean and organized code, though some parts are borrowed from existing vimscripts.
  • Highlights Haskell code in GitHub Flavored Markdown, and Literate Haskell documents as Markdown.
  • Improved syntax highlighting including Haddock markup in comments, support for HSP and many quasi-quotes such as jmacro, shqq, regex, sql, string interpolation...
  • Liberal syntax highlighting for Cabal package descriptions, yielding less false-positives for mistakes than other syntax files for Cabal.
  • Makes Vim aware of Haskell modules and imports allowing you to gf with the cursor on a module to "go" to its source "file", etc.
  • Support for using HLint both as a compiler and a command, integrated into the quickfix system in Vim.
  • Unicode conceals for various operators and syntax, such as lambda and function composition.
  • Integrates with third-party plugins, but doesn't require them: snippets for UltiSnips and patterns for Tabular.
  • Posts buffers and line-ranges to hpaste.org.
  • Highly configurable, most of the above can be disabled if it gets in the way.

Installation

You need at least Vim 7.3, and for the HPaste command Python 2, not too ancient. Beyond that, just clone this repo and add it to your 'runtimepath'. Vundle is great for automating that, Pathogen is also popular.

See Also

Here are some other Vimscripts that complement vim2hs nicely:

  • Omni completion: neco-ghc
  • Syntax checking and linting: syntastic
  • Type inspection: haskellmode or (better) ghcmod
  • Shakespeare templates highlighting: html-template-syntax
  • Layout as text objects: textobj-indent (vim2hs includes a less powerful version of this that I wrote before I discovered this Vimscript; it might be removed in favor of this one in the future)

Overview

Top-level Definitions

The syntax highlighting of top-level definitions are improved in vim2hs:

Bindings screenshot

This screenshot showcases a number of nice features:

  • Type signatures are highlighted as a whole, even if spanning multiple lines.
  • In function definitions, the name of the function is highlighted differently from its arguments, even if the equal sign is on another line (most or all other syntax highlighters get this wrong).
  • Top-level definitions such as functions, classes and instances and data declarations form folds, as you can see in the foldcolumn to the left of the line numbers. Closed folds are given a consistent foldtext producing a nice overview of the code. Type signatures are intentionally not included in the folds, so as to allow you to read the type of folded definitions.

In this screenshot, "wide conceals" are enabled, which is what makes the type colons and function arrows display as unicode. This option is disabled by default, since it can mess up the visual alignment between lines. To enable it like I have done here, try this:

let g:haskell_conceal_wide = 1

Other options like this that are safer are enabled by default, and can be disabled should you so desire:

" disable all conceals, including the simple ones like
" lambda and composition
let g:haskell_conceal              = 0

" disable concealing of "enumerations": commatized lists like
" deriving clauses and LANGUAGE pragmas,
" otherwise collapsed into a single ellipsis
let g:haskell_conceal_enumerations = 0

Quasi Quoting

Haskell supports embedding arbitrary syntax that is processed at compile-time. Vim supports embedding external syntax highlighting.

Quasi Quotes screenshot

These are all enabled by default but you can selectively opt out by adding the relevant configuration overrides to your ~/.vimrc:

let g:haskell_quasi         = 0
let g:haskell_interpolation = 0
let g:haskell_regex         = 0
let g:haskell_jmacro        = 0
let g:haskell_shqq          = 0
let g:haskell_sql           = 0
let g:haskell_json          = 0
let g:haskell_xml           = 0

HSP & Heist

Haskell Server Pages and Haskell Source with XML pre-processes literal XML in Haskell source code into function application and vim2hs provides limited support for this syntax - I have yet to figure out how to highlight the body of XML elements differently while still highlighting the attributes as Haskell.

HSP screenshot

This is enabled by default and can be disabled thusly:

let g:haskell_hsp = 0

Heist is a simple XML/HTML templating system; simple enough that you could simply use the xml or html filetype in Vim for these templates. However, it includes a number of pre-defined "splices" and a special syntax for "splice interpolation" in attributes. Included with vim2hs is a syntax file for Heist HTML templates and automatic filetype detection for *.tpl files.

Heist screenshot

Strings

Haskell actually supports multi-line strings by escaping the newline, but I don't think it's a widely used feature and I think quasi quoting is better for such purposes. Thus, by default, I have opted to keep string literals from crossing lines so half your source file doesn't highlight as a string while you're entering one. Instead, string literals without a matching end quote highlight as errors.

Strings screenshot

There is a configuration option for this. To enable multi-line strings, use this:

:let g:haskell_multiline_strings = 1

HLint

HLint is provided as a compiler for Vim.

:compiler hlint
:make

As a convenience there's also a command that does the above and then resets the compiler to its previous value.

:HLint

Either way any HLint suggestions and warnings will be put in Vim's quickfix list and you can jump between them with :cn and :cp, although I recommend setting up FuzzyFinder and using its :FufQuickfix command instead.

HPaste

To pastebin the contents of the current buffer do this:

:HPaste

The newly created paste URL will be put in the + register, meaning your normal desktop clipboard.

Alternatively, you can select a range of lines with Vim's VISUAL modes and type the same as above, which should result in this:

:'<,'>HPaste

Which of course will paste the selected lines only.

If you get tired of entering your author name every time you can configure it globally like so:

let g:hpaste_author = 'donri'

UltiSnips

If you're using the excellent UltiSnips Vimscript, vim2hs provides some useful snippets for Haskell programming. You can list all active snippets by hitting Ctrl+Tab in INPUT mode.

Tabular

Another useful Vimscript is Tabular. If it's installed, vim2hs adds some named patterns useful for maintaining layout in Haskell code. You can list all named patterns by tab-completing after entering the :Tabularize command. You probably want to configure some mappings or commands for the ones you find useful.

To disable them, use this configuration:

let g:haskell_tabular = 0

vim2hs's People

Contributors

aavogt avatar andy-morris avatar chreekat avatar dag avatar dolio avatar mvv avatar ocharles avatar rhysd avatar unkindpartition 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  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  avatar  avatar  avatar  avatar  avatar

vim2hs's Issues

cpp unfinished

Currently only does precondit but should also do macro/include and anything else as either error or just preproc.

Wrapped signatures not highlighted

I often use this style for long type signatures:

buildLib
  :: Verbosity -> PackageDescription -> LocalBuildInfo
  -> Library -> ComponentLocalBuildInfo -> IO ()

Currently vim2hs doesn't recognize this as a signature.

Help file resource

Is there any help file where I can find info about keyboard shortucts for performing different operations while using vim2hs.. like code folding and expanding for example. I couldn't find any help file detailing this information in the source...

Syntax highlighting sees operators that look like comments as comments

(-->) is one example (a ManageHook operator in XMonad).

The following is highlighted with everything to the left (inclusive) of the operator as comment:

myManageHook = composeAll
    [ foo --> bar
    , baz --> bat
    ]

I'm not sure how (as the rules are deceivingly complex) but normal vim highlighting gets it right.

Follow tibbe's style guide better

I thought I was following it mostly, but seems I either misread it or it changed since I first read it (probably the former).

The main concern is that vim2hs is meant to be used with shiftwidth=2 and then does things like &sw * 2 for function body indentation, so you can dedent a where once to get the style advocated in tibbe's guide.

However I've since realized tibbe's guide suggests shiftwidth=4 for everything except exceptions like where. It would therefore be better to make vim2hs work with that, and then automatically dedent where by &sw / 2 instead.

https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md

There might be other areas where we could improve as well. I don't like everything in the style guide and have done some things differently in vim2hs because of personal taste, but it's probably better to standardize on something, anything.

Syntax highlighting performance

When using the syntax highlighting from vim2hs I experience significant lag, even just moving the cursor up and down. My old highlighting file didn't suffer from this. Have you noticed any performance problems? Can you compare with this highlighting file and see if you have a noticeable difference?

https://gist.github.com/3122151

Some DecsQ splices incorrectly highlighted?

Supposedly any valid expression is a valid top-level TH splice, syntactically, presumably including infix application/operators. The current assumption is that a splice begins with an identifier, which is probably not the full story. I also recall noticing that code using the options package was incorrectly highlighted, for some reason (multi-lines?).

multi-line strings

Either add a switch or better yet detect if a string escapes a newline.

fold typedefs

Seems Vim is willing to either fold typedefs, or syntax highlight them, but not both at the same time. Maybe a workaround could be to use syn-match instead of syn-keyword.

indentation doesn't really work as advertised

Opening the bindings.hs test file and reindenting the whole thing I get the following:

main =
                putStrLn $ yell str
                where
                        str = "hello"

yell :: String
-> String
yell s = map toUpper s

data Something
                = Something
                | Other

isLarge :: (Ord a, Num a) => a -> String
isLarge x
| x > 10    = "yep"
| otherwise = "nope"

instance Functor [] where
                fmap :: (a -> b)
                -> f a -> f b
                fmap = map

($) :: (a -> b) -> a -> b
f $ x =  f x

buildLib
:: Verbosity -> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()

which is very different from the screenshot, not to mention syntactically broken.

Tested with Vim 7.3 using vim -u vimrc where vimrc is as follows:

set rtp+=~/.vim/bundle/vim2hs
set nocompatible expandtab
filetype plugin indent on

What settings am I and/or documentation missing?

more configurable :HPaste

  • Option to never ask for a channel, or always use a preconfigured one
  • Option to use the filename for title

Snippets for Heist templates

Should probably "extend" the html/xml snippets shipped with UltiSnips, and possibly add snippets for builtin Heist splices.

lhs tex

Add support for TeX in Literate Haskell, possibly autodetected like in Pygments (first non-whitespace is \ or %).

Highlight data constructors ?

For now data constructors are not highlighted. I was thinking it may be useful especially in pattern matching code, are there any particular reason to not behave data constructors differently than ordinary functions?

heist

Default splices (bind, apply etc) and attr splices ${}, ftdetect .tpl .xtpl

The Big Rewrite

Vim2hs is a bit of a kitchen sink that I've been using for experimenting with Haskell in Vim, and that I've thus intentionally avoided announcing officially anywhere.

I want to extract the good parts of it into separate Vim addons, make those more polished, fully documented and more idiomatic for Vim addons, and independent of each other when that makes sense.

  • Haskell filetype replacement: vim-haskell
    • Give the user more control without custom options, for example don't enforce conceallevel or foldmethod etc but instead document how to set those if you want to use those features
    • Maybe try making options like HSP buffer-local and set those automatically based on pragmas in the file
    • Maybe try context-based highlighting such that e.g. the whole of a data declaration gets a base color, like how type signatures are highlighted in vim2hs. This might be slow though, and gets tricky with things like type families.
    • Alternatively maybe aim for fast syntax highlighting with less complex regexps
    • Fold more! In particular, nested folds. Things like case-exprs could conceivably be folded. Might be slow if using syntax folding, maybe use foldexpr instead.
    • Experimenting with embedded syntax in QQs was fun, but how much are they used? Which are used more? How much does it slow down things? We're also missing the perhaps most used QQs, those from Yesod.
      • Maybe make QQ syntax providers pluggable and separate addons, maybe via user events
  • Cabal filetype repleacement: vim-cabal
  • Heist filetype: vim-heist, if I feel like it (as I don't really use Heist myself)
  • HPaste plugin: vim-hpaste
    • Properly map filetypes
    • Replace the prompts with arguments to :HPaste with sensible defaults (g:hpaste_author || $USER, no channel, file name as title)
    • Consider using the hpasteit program from Hackage
  • HLint compiler support: vim-hlint, if at all
    • Contribute a syntax checker to Syntastic, useful in combination with the hdevtools syntax checker which doesn't do hlint (unlike ghc-mod)
    • ghcmod-vim has something similar to our :HLint, but I don't think it uses Vim's compiler feature
  • UltiSnips: look into contributing them upstream or to the snipmate-snippets collection once snipmate is ported to UltiSnips
  • Tabular patterns: maybe vim-tabular-haskell, but maybe better polish up my AlignByCurrentSymbol as a generic Vim addon not just for Haskell
  • Layout as text objects: drop it, tell people to use vim-textobj-indent instead. There might be an opportunity to make a brand new vim-textobj-haskell though, something like Chris Done's syntax-mode for emacs, but vim-textobj-fold could also be useful with better folding in vim-haskell.
  • Automatic Haskell tags: vim-haskell-tags
    • lushtags is great but doesn't work with ^] etc
    • Make the generator setting a list instead and use the first one whose executable is installed

Generically applicable:

  • Properly license everything
  • By idiomatic for Vim addons I mean for example dropping the obsessive use of autoloading and functions and function arguments; Vimscript is not designed for writing structured, modular code like that
  • Use \v for cleaner regexps

Infix operators incorrectly highlighted

Infix operators without spaces on both sides are not highlighted:

apa = x++x ++x++ x

Infix constructors are not highlighted:

bepa = 1 :+: 1

Or is highlighted as hsDelimiter:

cepa = 1||1 || 1

(|) is also highlighted as hsDelimiter, but I don't think there is such
a delimiter in Haskell.

keywords should be context-sensitive

I'm currently using the Keyword group to highlight non-reserved syntactical keywords, but these are only keywords in specific contexts; for example "qualified" is only a keyword after an "import", and for that matter an "import" is a keyword after a "foreign" but otherwise a reserved statement keyword.

vimdocs

Explain all configuration options, tabular patterns etc.

HPaste languages not explicitly mapped to filetype

Currently the hpaste plugin simply uses the filetype setting as the language when posting to hpaste.org, but it's very possible that some of the supported languages have different names, and for unsupported languages it should fall back to raw text.

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.