Skip to content

kentookura/forester.nvim

Repository files navigation

🌲 forester.nvim 🌲

main

Filetype plugin for forester, a tool for writing mathematical hypertext

Important

I am currently focusing my efforts on developing the language server for forester. The language server will subsume the vast majority of features of this plugin. After the LSP ships, this plugin will be deprecated/rewritten from scratch.

Features

  • Tree-sitter syntax highlighting. Please report any issues with the grammar in the relevant repository
  • following links and transclusions with gf
  • Searching for trees by title with telescope
  • Creating new trees via autocompletion menu
  • Displaying tree titles with virtual text
  • Address completion

Available user commands:

  • Forester build: Build the currently configured forest. Use Forester config to switch forest.
  • Forester config: Choose the config file from which to source the tree directories
  • Forester browse: Telescope picker, search trees by title. TODO: support browsing by tag/taxon/...
  • Forester new: Create a new tree by specifying a prefix
  • Forester new_random: Create a new tree with a random adress by specifying a prefix
  • Forester transclude_new: transclude a new tree at cursor position
  • Forester link_new: link a new tree at cursor position

screenshot of of the virtual text feature

Installation

With lazy:

  {
    "kentookura/forester.nvim",
    event = "VeryLazy",
    dependencies = {
      { "nvim-telescope/telescope.nvim" },
      { "nvim-treesitter/nvim-treesitter" },
      { "nvim-lua/plenary.nvim" },
    },
  },

  -- optionally, configure the cmp source:
  local foresterCompletionSource = require("forester.completion")

  require("cmp").register_source("forester", foresterCompletionSource)
  require("cmp").setup.filetype("forester", { sources = { { name = "forester", dup = 0 } } })

You might need to run :TSInstall toml and :TSInstall forester.

Configuration

In your forest.toml (or any other config) you should add the list of prefixes:

prefixes = ["foo", "bar"]

When calling :Forester new, you will then be able to choose the prefix of the new tree.

{
  config = function()
    local forester = require("forester")
    vim.g.mapleader = " "

    vim.keymap.set("n", "<leader>n.", "<cmd>Forester browse<CR>", { silent = true })
    vim.keymap.set("n", "<leader>nn", "<cmd>Forester new<CR>", { silent = true })
    vim.keymap.set("n", "<leader>nr", "<cmd>Forester new_random<CR>", { silent = true })
    vim.keymap.set("i", "<C-t>", "<cmd>Forester transclude<CR>", { silent = true })
    vim.keymap.set("i", "<C-l>", "<cmd>Forester link<CR>", { silent = true })
  end,
}

require("nvim-web-devicons").setup({ override_by_extension = { ["tree"] = { icon = "🌲" } } })

Roadmap

  • Find an ergonomic way to make use of forester's builtin templating feature