cvigilv / esqueleto.nvim Goto Github PK
View Code? Open in Web Editor NEWReduce your boilerplate code the lazy-bones way
License: MIT License
Reduce your boilerplate code the lazy-bones way
License: MIT License
Refer to #8 for details.
Would be nice to skip vimscript completely and use only lua in for this fix...
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?
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!
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
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.
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
I've isolated it to this line here, which which works when I modify it to include the pattern.
esqueleto.nvim/lua/esqueleto/init.lua
Line 52 in 7764077
For good measure, here's my exact config:
Please let me know if there's a bug here or if I've got something misconfigured. Thanks!
Seems when I run :Gvdiffsplit (https://github.com/tpope/vim-fugitive) or other git commands, I have skeletons showing in the buffer, instead of the result from fugitive
Issue to add all other issues related to V1.0
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.
Provide the following:
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:
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.
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.
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.
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:
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
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'
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
)
├── 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
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.
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.
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:
The Preview pane should be TreeSitter highlighted if possible.
The Selection pane should be simple and minimal as Ivy.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.