Code Monkey home page Code Monkey logo

mdeval.nvim's Introduction

mdeval.nvim

This plugin allows you evaluate code blocks inside markdown, vimwiki, orgmode.nvim and norg documents.

It attempts to implement the basic functionality of org-mode's evaluating code blocks feature inside Neovim.

Demo

Requirements

This plugin requires Neovim version 0.5+.

It works on Linux, MacOS and Windows (through WSL).

MacOS users should make sure that they have coreutils package installed:

brew install coreutils

Windows users should have installed WSL with compilers/interpreters they want use.

Installation

Install it with your plugin manager.

Then add the following line in your init.lua:

require 'mdeval'.setup()

You should also enable syntax highlighting inside code blocks for your languages using the built-in functionality:

vim.g.markdown_fenced_languages = {'python', 'cpp'}

Usage

To use this plugin, you should move cursor inside a fenced code block with language identifier and execute the :MdEval command. mdeval.nvim will capture the results of the code block execution and inserts them in the markdown file, right after the code block.

Configuration

You can configure mdeval.nvim by running the mdeval.setup function.

Here is an example:

require 'mdeval'.setup({
  -- Don't ask before executing code blocks
  require_confirmation=false,
  -- Change code blocks evaluation options.
  eval_options = {
    -- Set custom configuration for C++
    cpp = {
      command = {"clang++", "-std=c++20", "-O0"},
      default_header = [[
    #include <iostream>
    #include <vector>
    using namespace std;
      ]]
    },
    -- Add new configuration for Racket
    racket = {
      command = {"racket"},        -- Command to run interpreter
      language_code = "racket",    -- Markdown language code
      exec_type = "interpreted",   -- compiled or interpreted
      extension = "rkt",           -- File extension for temporary files
    },
  },
})

By default, the plugin will ask your confirmation before evaluating code. This makes sense, because code evaluation is potentially harm operation. You can disable this feature setting require_confirmation option to false, or allow to execute code blocks without confirmation only for some languages, using allowed_file_types option, for example: allowed_file_types={'rust', 'haskell'}.

Probably, it will be a good idea to define keybindings to call :MdEval. This plugin doesn't add default keybindings, but you can do this in your configuration file, for example:

vim.api.nvim_set_keymap('n', '<leader>c',
                        "<cmd>lua require 'mdeval'.eval_code_block()<CR>",
                        {silent = true, noremap = true})

See the complete list of options in the documentation.

See also

  • Sniprun โ€“ A similar plugin written in Rust with much more features.

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.