Giter Club home page Giter Club logo

esqueleto.nvim's Introduction

Hi, I'm Carlos

I'm a chilean biochemist interested in understanding living organisms' biochemical evolution through mathematical and computational models. In my spare time I'm a Neovim plugin developer and Julia Language enthusiast, as well as part-time photographer.

What am I up to?

I'm currently working at Protera Bioscience developing tooling and predictive models for madi:TM: SaaS protein-engineering platform.

For a more in-depth view of my experience, please refer to my CV (también disponible en español).

Projects

Science

Neovim

Julia Language

  • SimSpread.jl, a software package for the Julia programming language that implements the SimSpread formalism for link prediction in graphs.

Personal

  • recetario, a compendium of miscellaneous script for all things science, ML, DS, Julia, etc.

Last edit: 2024-06-03

esqueleto.nvim's People

Contributors

amar1729 avatar cvigilv avatar futarimiti avatar itepechi avatar jakebrinkmann avatar raafatturki avatar rlyown avatar yigitsever 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

Watchers

 avatar  avatar

esqueleto.nvim's Issues

fix: error when entering new file whose name matches one of the patterns case insensitively

Hi, another issue found when testing.

Minimum reproducible example:

-- config
require('esqueleto').setup { patterns = { 'main.py' } }

Then, with nvim, create and edit file Main.py (or whatever filename as long as it insensitively matches 'main.py' e.g. MAIN.py, mAIn.PY...), will trigger the following error:

Error detected while processing BufWinEnter Autocommands for "main.py":
Error executing lua callback: ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:18: attempt to concatenate local 'pattern' (a
 nil value)
stack traceback:
        ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:18: in function 'gettemplates'
        ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:86: in function 'inserttemplate'
        ...share/nvim/lazy/esqueleto.nvim/lua/esqueleto/autocmd.lua:21: in function <...share/nvim/lazy/esqueleto.nvim/lua/esqueleto/au
tocmd.lua:18>

And after some debugging, I believe here's the reason:

  1. Patterns provided by users are directly passed as autocmd patterns:

      vim.api.nvim_create_autocmd(
        { "BufWinEnter", "BufReadPost", "FileType" },
        {
          group = group,
          desc = "esqueleto.nvim :: Insert template",
          pattern = opts.patterns,  -- { 'main.py' }
          callback = function()
            local filepath = vim.fn.expand("%")
            local emptyfile = vim.fn.getfsize(filepath) < 4
            if emptyfile then utils.inserttemplate(opts) end
          end
        }
      )

    Though not directly documented in the manual, it seems that autocmd patterns are indeed case-insensitive,
    therefore Main.py matches the main.py and the callback is executed.

  2. Then, within inserttemplate:

    M.inserttemplate = function(opts)
      ...
      -- Identify if pattern matches user configuration
      local pattern = nil
      if not _G.esqueleto_inserted[filepath] then
        -- match either filename or extension. Filename has priority
        if vim.tbl_contains(opts.patterns, filename) then
          pattern = filename
        elseif vim.tbl_contains(opts.patterns, filetype) then
          pattern = filetype
        end
    
        -- Get templates for selected pattern
        local templates = M.gettemplates(pattern, opts.directories)
        ...
      end
    end

    Where vim.tbl_contains, which is case-sensitive, is used to get that pattern. Of course, opts.patterns does not contain Main.py, and pattern, without nil-checks, will be passed to gettemplates to be concatenated with filepaths.

docs(readme): improve to make more compelling and attractive

As of today, the README of the plugin is pretty bland, just providing the possible user to the
information without being compelling or exemplifying why this plugins could be useful.
Additionally, other plugins do similar things (so I should showcase this in case someone would
prefer those alternatives) and I have a clear roadmap of what I would like to do with this
project.

So the tasks for this issue are the following:

  • Improve describing the intention and philosophy of the plugin
    • Emphasis in Vim philosophy, making use of this "common" language a Neovim user should know
    • Showcase the customizability of the plugin
    • Make clear that this is a plugin to (i) use WYSIWYG or (ii) use with a lot of customization
  • Update and improve ROADMAP
    • Maybe extract to other file (?)
  • Add section with similar plugins

feat(ui): implement a template insertion prompt inspired in Emac's Ivy

As a way to make selecting the correct template when esqueleto runs its insertion prompt, this issue is intended to add a new prompt inspired in Emac's Ivy.

The layout will be as follows:

  • Top 2/3 will show the template contents (Preview pane)
  • Bottom 1/3 will show a fuzzy finder with all available templates for the corresponding buffer (Selection pane)

The Preview pane should be TreeSitter highlighted if possible.
The Selection pane should be simple and minimal as Ivy.

Extract the autocmd function to be callable

What do you think about extracting the autocmd function to be able to run it manually?
I think this is not much work.

This can be done using nvim.create_user_command. Then you could call the fill-in function from command menu.

Error on basic config

I have this error after following the README at "Usage & Configuration" step. I'm using packer.

Error detected while processing /home/nhatvan1561/.config/nvim/init.lua:
E5113: Error while calling lua chunk: ...ack/packer/start/esqueleto.nvim/lua/esqueleto/config.lua:18: inv
alid type name: table: 0x4165f928
stack traceback:
        [C]: in function 'error'
        vim/shared.lua:608: in function 'validate'
        ...ack/packer/start/esqueleto.nvim/lua/esqueleto/config.lua:18: in function 'updateconfig'
        .../pack/packer/start/esqueleto.nvim/lua/esqueleto/init.lua:9: in function 'setup'
        /home/nhatvan1561/.config/nvim/init.lua:10: in main chunk
Press ENTER or type command to continue

Fill in file contents when creating files from NvimTree

I think you may want to provide a sample skeleton just to show how to add and use one.
It will also allow to see that the plugin works out of the box without trying to make your own skeletons and failing.

I have this config:

require("esqueleto").setup(
    {
      -- Directory where templates are stored
      directory = "~/.config/nvim/skeletons/", --default template directory

      -- Patterns to match when creating new file
      -- Can be either (i) file names or (ii) extension globs.
      -- Exact file name match have priority
      patterns = { "README.md", "*.py", "*.hey", "*.hi", "LICENSE.md" }
    }
)

And I added these files:

> tree .
.
├── LICENSE.md
├── skeleton.hey
└── skeleton.my-test.hi

And I created .hey, .hi and LICENSE.md files via NvimTree and it didn't work.

But it works when I use :e LICENSE.md from command mode.

Integration with Dressing.nvim

Hello there, first of all I do appriciate your work and thanks for the plugin!

Just found out about the plugin, so added the following lines in my configuration (./lua/paks/esqueleto/init.lua)
image

├── lua
│   ├── paks
│   │   ├── esqueleto
│   │   │   ├── init.lua
│   │   │   └── templates
│   │   │       └── LICENSE
│   │   │           └── MIT

Thus I shamelessly stolen the template for the MIT License just to test it out.

It doesn't always work (does not detect the file as an empty file?), probably something wrong on my side, but when it does, with Dressing.nvim I'd get a prompt like the following
image

Thus confirming that at least the configuration is not completly bogus: once selected the file LICENSE is empty.

EDIT 1: Not sure why but filename doesn't always return the filename but, instead, the full path to the file, thus that's the reason it doesn't always work (it does not match the file).

Using %:t instead seems to be working as expected

M.Esqueleto = function()
  -- only prompt if template hasn't been inserted
  local filepath = vim.fn.expand("%:p")
  local filename = vim.fn.expand("%:t") -- <
  local filetype = vim.bo.filetype

EDIT 2: Dressing vim.ui.select is async, thus selection is never set and select returns nil instead.

Latex filetypes?

Hello, I'm enjoying using your plugin. However, I'm stuck with creating a LaTeX template. When I need to create a python or cpp template, everything seems fine, but when it comes to LaTeX, I don't know what pattern to use. I tried 'latex', 'tex'.

My file structure is just like in the set up example (I wanted to put it in here, but something is wrong with indentation it tree :( ).

How can I fix this problem or what is the logic behind patterns namings?

Manage templates in a similar fashion to how `ftplugin` works

ftplugin consists of a series of directories for a specific filetype; inside this, you can add vim scripts to set options and/or add functionality. This issue intends to change the current design (pretty messy tbh) and move to a design inspired by this directory structure and function.

For this, we need to scrap the matching of regex patterns (*.py, for example) and change this to respond to filetype (vim.bo.filetype). For filename-matching patterns, we will maintain the current design of matching the whole file name but move the templates into a directory with this name.

So, the design will change from:

skeletons
├── skeleton.cli.jl
├── skeleton.jl
├── skeleton.license-Apache20.md
├── skeleton.license-GNUGPLv3.md
├── skeleton.license-MIT.md
├── skeleton.license-Unlicense.md
├── skeleton.module.jl
└── skeleton.tests.jl

To:

skeleton
├── julia
│  ├── cli
│  ├── default
│  ├── module
│  └── tests
└── LICENSE
   ├── Apache20
   ├── GNUGPLv3
   ├── MIT
   └── Unlicensed

fix: dont prompt in "nofile" buffertype

Whenever Neovim create a new window for Hover, it creates a "nofile" markdown ft window, which
launchs esqueleto's prompt. This is not intended and has to be fixed.

Remove need to specify 'patterns'?

Hello! Thanks for writing esqueleto. Great plugin! I've been using it to replace some homegrown logic from my dotfiles. Thanks! I'll be sending a few bits of feedback as issues your way, hope that's helpful :)

My first would be - I'm not sure why it's necessary to specify the pattern list. In my config, I've ended up with something like:

return {
    "cvigilv/esqueleto.nvim",
    config = function()
        require("esqueleto").setup({
            directories = vim.fn.stdpath("config") .. "/skeleton",
            patterns = vim.fn.readdir(vim.fn.stdpath("config") .. "/skeleton"),
        })
    end,
}

Why would I ever not want every subdir from the directories I've specified in the patterns list? Is there a reason I wouldn't include one? I think, unless I've missed something, this is something esqueleto could calculate out-of-the-box, isn't it? Certainly from reading the README I can't see any situation where those two lists wouldn't match. Maybe if that's true, you could auto-calculate this and remove the user burden to specify it?

Missing "pattern" part of template directory so fails to load template.

Hello,

Thanks for the plugin! I get an error when I try to insert a python skeleton. If I have ...../skeletons/python/test.py in my skeletons, and pattern = {'python'} in my esqueleto config, it throws this error when I try to

image

I've isolated it to this line here, which which works when I modify it to include the pattern.

filepath = directory .. filepath

For good measure, here's my exact config:

image

Please let me know if there's a bug here or if I've got something misconfigured. Thanks!

'Wildcard' is not used correctly

Hello. Me again! Thanks again for your hard work writing esqueleto.

One small piece of feedback - you might want to reconsider the word 'wildcard'. I'm not sure if you're a native English speaker, but as used in esqueleto and the associated docs, this isn't quite the right word for the concept you're going for, I think. Generally, a wildcard is a card/concept/word which can stand for anything (for example, * and ? in most shells) - that isn't what the wildcards in esqueleto are, if I've understood correctly, they are more like 'placeholders' or (ironically) 'templates'.

It's obviously not a big issue, and I think you explain it clearly in the docs so not a big worry, but if you have the opportunity to change this without breaking existing behaviour, it might be worth considering. Just a thought... I won't be offended if you close this :)

Thanks again for all your hard work on this great plugin!

bug: Empty or no selection shouldn't throw an error

Hello,
I am not a strong lua/neovim developer, otherwise I would dig into this and find a fix.

Type number and <Enter> or click with the mouse (q or empty cancels): Error detected while processing BufNewFile Autocommands for "*
":
Error executing lua callback: ...brew/Cellar/neovim/0.9.5/share/nvim/runtime/filetype.lua:24: Error executing lua: ...brew/Cellar/ne
ovim/0.9.5/share/nvim/runtime/filetype.lua:25: BufNewFile Autocommands for "*"..FileType Autocommands for "markdown": Vim(append):Er
ror executing lua callback: ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:173: bad argument #1 to 'fs_realpath' (strin
g expected, got nil)
stack traceback:
        [C]: in function 'fs_realpath'
        ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:173: in function 'on_choice'
        ...ew/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/ui.lua:52: in function 'select'
        ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:172: in function 'selecttemplate'
        ...l/share/nvim/lazy/esqueleto.nvim/lua/esqueleto/utils.lua:199: in function 'inserttemplate'

Consider support triggering by file extension.

There are header files and implementation files for c/c++. With current file type or file name trigger, it's impossible to set different file templates for header files and implementations.

It seems a good idea to support trigger by file extension(with precedence between file name and file type if supported), which will solve the above issue. For other scenarios, it's a lot easier to define a new extension than to define a new file type.

feat: implement more excommands

Provide the following:

  • Excommand to create templates from given file
  • Excommand to create template from scratch
  • Excommand to modify template

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.