udayvir-singh/tangerine.nvim

github github
fennel
star 59
stars
alert-circle 0
open issues
users 2
subscribers
git-branch 2
forks
CREATED

2022-01-13

UPDATED

2 days ago


:tangerine: Tangerine :tangerine:

Neovim version GNU Neovim in Emacs version

About β€’ Installation β€’ Setup β€’ Commands β€’ API β€’ Development

About

Tangerine provides a painless way to add fennel to your config.

Features

  • :fire: BLAZING fast, compile times in milliseconds
  • :ocean: 200% support for interactive evaluation
  • :bamboo: Control over when and how to compile
  • :ribbon: Natively loads nvim/init.fnl

Comparison to other plugins

HOTPOT :stew:
  • Abstracts too much away from user.
  • Hooks onto lua package searchers to compile [harder to debug]
ANISEED :herb:
  • Excessively feature rich to be used for dotfiles.
  • Blindly compiles all files that it founds, resulting in slow load times.

Installation

  1. Create file plugin/0-tangerine.lua to bootstrap tangerine: ```lua

-- ~/.config/nvim/plugin/0-tangerine.lua

-- pick your plugin manager, default [standalone] local pack = "tangerine" or "packer" or "paq"

local function bootstrap (url) local name = url:gsub(".*/", "") local path = vim.fn.stdpath [[data]] .. "/site/pack/".. pack .. "/start/" .. name

if vim.fn.isdirectory(path) == 0 then
    print(name .. ": installing in data dir...")

    vim.fn.system {"git", "clone", "--depth", "1", url, path}

    vim.cmd [[redraw]]
    print(name .. ": finished installing")
end

end

bootstrap "https://github.com/udayvir-singh/tangerine.nvim"

2. Call tangerine `setup()` function:
```lua
-- ~/.config/nvim/plugin/0-tangerine.lua

require "tangerine".setup {
    [[ config, see below ]]
}
  1. Invoke :FnlCompile manually or add hooks in setup.

:tanabata_tree: Now start writing your config in ~/.config/nvim/init.fnl.

:hibiscus: Optionally you can also install hibiscus for macros.


Packer

You can use packer to manage tangerine afterwards:

(local packer (require :packer))

(packer.startup (fn []
  (use :udayvir-singh/tangerine.nvim)))

Using hibiscus macros:

(require-macros :hibiscus.packer)

(packer-setup {}) ; bootstraps packer

(packer
  (use! :udayvir-singh/tangerine.nvim))

Paq

(local paq (require :paq))

(paq {
  :udayvir-singh/tangerine.nvim
})

Setup

Default config

Tangerine comes with sane defaults so that you can get going without having to add much to your config:

local nvim_dir = vim.fn.stdpath [[config]]

{
    vimrc   = nvim_dir .. "/init.fnl",
    source  = nvim_dir .. "/fnl",
    target  = nvim_dir .. "/lua",
    rtpdirs = {},

    compiler = {
        float   = true,     -- show output in floating window
        clean   = true,     -- delete stale lua files
        force   = false,    -- disable diffing (not recommended)
        verbose = true,     -- enable messages showing compiled files

        globals = {...},    -- list of alowedGlobals
        version = "latest", -- version of fennel to use, [ latest, 1-1-0, 1-0-0, 0-10-0, 0-9-2 ]

        -- hooks for tangerine to compile on:
        -- "onsave" run every time you save fennel file in {source} dir
        -- "onload" run on VimEnter event
        -- "oninit" run before sourcing init.fnl [recommended than onload]
        hooks   = {}
    },

    eval = {
        float  = true,      -- show results in floating window
        luafmt = function() -- function that returns formatter with flags for peaked lua
            return {"/path/lua-format", ...} -- optionally install lua-format by `$ luarocks install --server=https://luarocks.org/dev luaformatter`
        end,

        diagnostic = { 
            virtual = true,  -- show errors in virtual text
            timeout = 10     -- how long should the error persist
        }
    },

    keymaps = {
        eval_buffer = "gE",
        peak_buffer = "gL",
        goto_output = "gO",
        float = {
            next    = "<C-K>",
            prev    = "<C-J>",
            kill    = "<Esc>",
            close   = "<Enter>",
            resizef = "<C-W>=",
            resizeb = "<C-W>-"
        }
    },

    highlight = {
        float   = "Normal",
        success = "String",
        errors  = "DiagnosticError"
    },
}

Example Config

Here is config that I use in my dotfiles:

{
    -- save fnl output in a separate dir, it gets automatically added to package.path
    target = vim.fn.stdpath [[data]] .. "/tangerine",

    -- compile files in &rtp
    rtpdirs = {
        "plugin",
        "colors",
        "$HOME/mydir" -- absolute paths are also supported
    },

    compiler = {
        -- disable popup showing compiled files
        verbose = false,

        -- compile every time changed are made to fennel files or on entering vim
        hooks = ["onsave", "oninit"]
    }
}

Commands

Compiling

:FnlCompileBuffer

Compiles current active fennel buffer

:FnlCompile[!]

Diff compiles all indexed fennel files

If bang! is present then forcefully compiles all source files

:FnlClean[!]

Deletes stale or orphaned lua files in target dir

If bang! is present then it deletes all compiled lua files

Evaluation

:Fnl {expr}

Executes and Evalutate {expr} of fennel

:Fnl (print "Hello World")
  -> Hello World

:Fnl (values some_var)
  -> :return [ 1 2 3 4 ]

:FnlFile {file}

Evaluates {file} of fennel and outputs the result

:FnlFile path/source.fnl

:FnlFile % ;; not recommended

:[range]FnlBuffer

Evaluates all lines or [range] in current fennel buffer

mapped to gE by default.

Peaking

:[range]FnlPeak

Peak lua output for [range] in current fennel buffer

mapped to gL by default.

:FnlGotoOutput

Open lua output of current fennel buffer in a new buffer

mapped to gO by default.

Window

:FnlWinNext [N]

Jump to [N]th next floating window created by tangerine

mapped to CTRL-K in floats by default.

:FnlWinPrev [N]

Jump to [N]th previous floating window created by tangerine

mapped to CTRL-J in floats by default.

:FnlWinResize [N]

Increase or Decrease floating window height by [N] factor

mapped to CTRL-W = to increase and CTRL-W - decrease by default.

:FnlWinClose

Closes current floating window under cursor

mapped to ENTER in floats by default.

:FnlWinKill

Closes all floating windows made by tangerine

mapped to ESC in floats by default.

FAQ

Q: How to make tangerine compile automatically when you open vim

A: add hooks in config:

tangerine.setup {
    compiler = {
        -- if you want to compile before loading init.fnl (recommended)
        hooks = ["oninit"]

        -- if you only want after VimEnter event has fired
        hooks = ["onenter"]
    }
}

Q: How to tuck away compiled output in a separate directory

A: change target in config:

tangerine.setup {
    target = "/path/to/your/dir"
}

Q: How to make impatient work with tangerine

A: just bootstrap and require impatient before calling tangerine:

bootstrap "https://github.com/lewis6991/impatient.nvim"

require [[impatient]]

require [[tangerine]].setup {...}

Q: How to use lua files interchangeably with fennel files

A: lua files can simply be stored in fnl dir:

fnl
β”œβ”€β”€ options.lua
└── autocmd.fnl
; just require both normally
(require :options)
(require :autocmd)

Q: How to fix errors in macros while migrating from hotpot

A: make sure that macro files are suffixed with -macros.fnl.

utils
β”œβ”€β”€ neovim-macros.fnl
└── packer-macros.fnl

see #2 for more information

Api

By default tangerine provides the following api:

:Fnl tangerine.api

-> :return {
     :compile {
       :all    (function 0)
       :buffer (function 1)
       :dir    (function 2)
       :file   (function 3)
       :rtp    (function 4)
       :string (function 5)
       :vimrc  (function 6)
     }
     :clean {
       :rtp      (function 7)
       :target   (function 8)
       :orphaned (function 9)
     }
     :eval {
       :buffer (function 10)
       :file   (function 11)
       :peak   (function 12)
       :string (function 13)
     }
     :win {
       :next    (function 14)
       :prev    (function 15)
       :close   (function 16)
       :killall (function 17)
       :resize  (function 18)
     }
     :goto_output (function 19)
     :serialize   (function 20)
   }

Compiler Api

This section describes function for tangerine.api.compile.{func}

compile-string

Compiles string {str} of fennel, returns string of lua.

Parameters:
{
    :filename <string>
    :globals  <list>
}

compile-file

Compiles fennel {source} and writes output to {target}.

Parameters:
{
    :filename <string>
    :globals  <list>
}

compile-dir

Diff compiles files in {source} dir and outputs to {target} dir.

Parameters:
{
    :force   <boolean>
    :float   <boolean>
    :verbose <boolean>
    :globals <list>
}

{opts.force} disables diffing if set to true

Example:
(tangerine.api.compile.dir 
    :path/fnl 
    :path/lua
    { :force false :float true :verbose true })

compile-buffer

Compiles the current active fennel buffer.

Parameters:
{
    :float    <boolean>
    :verbose  <boolean>
    :filename <string>
    :globals  <list>
}

compile-vimrc

Diff compiles config.vimrc to config.target dir.

Parameters:
{
    :force    <boolean>
    :float    <boolean>
    :verbose  <boolean>
    :filename <string>
    :globals  <list>
}

{opts.force} disables diffing if set to true

compile-rtp

Diff compiles fennel files in config.rtpdirs or {opts.rtpdirs}.

Parameters:
{
    :force    <boolean>
    :float    <boolean>
    :verbose  <boolean>
    :globals  <list>
    :rtpdirs  <list>
}

{opts.force} disables diffing if set to true

Example:
(tangerine.api.compile.rtp {
    :force   false
    :float   true
    :verbose true
    :rtpdirs [ "colors" "plugin" "$HOME/mydir" ]})

compile-all

Diff compiles all indexed fennel files in config.

Parameters:
{
    :force    <boolean>
    :float    <boolean>
    :verbose  <boolean>
    :globals  <list>
    :rtpdirs  <list>
}

{opts.force} disables diffing if set to true

Cleaning Api

Provides functions to clean stale / orphaned lua files in target dirs.

This section describes function for tangerine.api.clean.{func}

clean-target

Deletes orphaned? {target} after comparing against {source}.

Parameters:
{
    :force <boolean>
}

{opts.force} deletes {target} without comparing if set to true

clean-rtp

Deletes all orphaned lua files in config.rtpdirs or {opts.rtpdirs}.

Parameters:
{
    :force    <boolean>
    :float    <boolean>
    :verbose  <boolean>
    :rtpdirs  <list>
}

{opts.force} deletes all compiled files if set to true

clean-orphaned

Deletes all orphaned lua files indexed inside target dirs.

Parameters:
{
    :force    <boolean>
    :float    <boolean>
    :verbose  <boolean>
    :rtpdirs  <list>
}

{opts.force} deletes all compiled files if set to true

Evaluation Api

This section describes function for tangerine.api.eval.{func}

eval-string

Evaluates string {str} of fennel, pretty prints the output.

Parameters:
{
    :float    <boolean>
    :virtual  <boolean>
    :filename <string>
    :offset   <number> ;; line offset for errors
}

eval-file

Evaluates {path} of fennel, pretty prints the output.

Parameters:
{
    :float    <boolean>
    :virtual  <boolean>
    :filename <string>
}

eval-buffer

Evalutes lines {start} to {end} in current fennel buffer.

Parameters:
{
    :float    <boolean>
    :virtual  <boolean>
    :filename <string>
}

eval-peak

Peak lua output for lines {start} to {end} inside a scratch buffer.

Parameters:
{
    :float    <boolean>
    :virtual  <boolean>
    :filename <string>
}

Utils Api

goto_output

Open lua source of current fennel buffer in a new buffer.

serialize

Returns human-readable representation of {...}.

Example:
(tangerine.api.serialize example)
-> ":return [ 1 2 3 4 ]"

Windows Api

Provides functions to interact with floating windows created by tangerine.

This section describes function for tangerine.api.win.{func}

win-next

Switch to next floating window by 1 or N {steps?}.

win-prev

Switch to previous floating window by 1 or N {steps?}.

win-resize

Changes height of current floating window by {factor} of N.

win-close

Closes current floating window, switching to nearest neighbor afterwards.

win-killall

Closes all floating windows created by tangerine.

Fennel Api

fennel-load

Provides underlying fennel used by tangerine

{version} can be one of [ "latest" "1-1-0" "1-0-0" "0-10-0" "0-9-2" ]

Development

Requirements

Program Description
pandoc generates vimdoc
lua runs included fennel
make runs build instructions
watchexec build on changes (optional)
bash runs shell scripts
utils coreutils findutils gawk curl

only GNU/utils work, 9base or busybox should not work

Building from source

git clone https://github.com/udayvir-singh/tangerine.nvim
cd tangerine.nvim

make <git-hooks>
make <target>

see make help or below for information on targets.

Make Targets

Target Description
:fnl compiles fennel files
:deps copy required deps in lua folder
:vimdoc runs panvimdoc to generate vimdocs
:fnldoc generates module level documentation
:build combines :fnl :deps :vimdoc :fnldoc
:watch-build watches source dir, runs :build on changes
:clean deletes build and install dir
:install install tangerine on this system
:runner compiles test runner library
:test runs unit tests, will erase nvim config

To build tangerine run:

$ make clean build
# or
$ make watch-build

To install tangerine run:

$ make install

Git Hooks

Target Description
git-pull safely fetches git repo, prevents conflicts with local changes
git-skip makes git ignore changes to build files
git-unskip reverts git-skip, makes build files trackable
Example workflow:
$ make git-skip # first thing that you should be running

# makes changes to tangerine
$ ...
$ make clean build

# commit changes 
$ git commit -a -m "<msg>"

# cleanly fetch from origin
$ make git-pull

LOC Helpers

Helpers to generate detailed summary about lines of code in source files:

$ make loc-{language}
Supported Languages:
  • fennel / test
  • bash
  • markdown
  • makefile
  • yaml
Examples:
$ make loc-fennel

$ make loc-bash

End Credits

  • myself: for making this plugin
  • myself: for refactoring this plugin
  • myself: for bloating this plugin...
:: γŠγ‚Œγ¨γ—γ¦η™½ηœΌγγ‚‰γ™γ‚‹θ›™γ‹γͺ ::