jakemason / ouroboros.nvim Goto Github PK
View Code? Open in Web Editor NEWAllows quickly switching between header and implementation files for C/C++ in Neovim.
License: MIT License
Allows quickly switching between header and implementation files for C/C++ in Neovim.
License: MIT License
Hi
I have a project that contains in two different folders, the same files.
The plugin does not switch correctly between *.h and *.cpp if another file was opened earlier.
For example
folder1/rtsp.h
folder1/rtsp.cpp
folder2/rtsp.h
folder2/rtsp.cpp
If I open folder1/rtsp.h then switch to folder1/rtsp.cpp (:Ouroboros) it works correctly, then I open folder2/rtsp.h and try to switch (:Ouroboros), the switch will be to the earlier opened buffer ( folder1/rtsp.cpp).
It would be nice if you were asked to create a file/open an empty buffer if the header file can't be found.
What do you think? Does that make sense? Thanks!
using tables to store valid extensions and their corresponding alternates may be easier to scale and require less changes into the code to add new options
if((extension ~= "cpp") and (extension ~= "hpp") and
(extension ~= "c") and (extension ~= "h") and
(extension ~= "cc")) then
utils.log("Ouroboros doesn't work on a file ending in: ." .. extension .. ". Aborting.")
return
end
if(extension == "cpp" or extension == "hpp") then
desired_extension = utils.ternary(extension == "cpp", "hpp", "cpp")
elseif(extension == "c" or extension == "h") then
desired_extension = utils.ternary(extension == "c", "h", "c")
elseif(extension == "cc") then
desired_extension = "h"
end
-- vs
local extensions = {}
local c_cpp_exts_list = {
cpp = {
sources = {'cpp', 'C', 'cxx'},
header = {'hpp', 'hxx'},
},
c = {
sources = {'c', 'cc'},
headers = {'h'},
},
}
for ft, exts in pairs(c_cpp_exts) do
for _, i in ipairs(exts.sources) do
extentions[i] = exts.headers
end
for _, i in ipairs(exts.headers) do
extentions[i] = exts.sources
end
end
if not extensions[extension] then
utils.log("Ouroboros doesn't work on a file ending in: ." .. extension .. ". Aborting.")
return
end
desired_extension = extensions[extension]
This may even help to extend support to other languages that also have header/implementation structures like Objective-C/Objective-C++
Currently if you open in a split, and choose to keep that around, Ouroboros can't help you anymore. You'd have to manually navigate your open buffers.
It would be nice if you add a command which:
:Ouroboros
does.So basically if I already have a split open with my corresponding header/source, it'll switch to that.
Hi,
Thank you for building this. Is there any way to open the .h/.cc file in a split plane, instead of having a buffer be opened on top? Thanks!
It would look a bit cleaner if the file path of the second file was displayed in the same path format as the first one.
What I mean is that when I open a few files nvim -O {a,b,c}.hpp
their paths in the status bar are displayed simply as a.hpp
, while the belonging cpp file's path gets displayed as ./a.cpp
.
My mapping is this:
vim.keymap.set('n', '<C-h>', ':Ouroboros<CR>', { silent = true })
Hey
Trying to create a file, I am getting an error thrown that reads:
Error: E5108: Error executing lua Vim:E739: Cannot create directory /XXXXXXXXXX/cppcache/src: file already exists
stack traceback:
[C]: in function 'mkdir'
.../.local/share/nvim/lazy/ouroboros/lua/ouroboros/init.lua:86: in function 'on_confirm'
/usr/share/nvim/runtime/lua/vim/ui.lua:103: in function 'input'
.../.local/share/nvim/lazy/ouroboros/lua/ouroboros/init.lua:81: in function 'switch'
[string ":lua"]:1: in main chunk
I noticed in the switch function, you have an extra -
I think vim.fn.mkdir(path, "-p")
In the neovim docs they do not https://neovim.io/doc/user/builtin.html#E739
if exists("g:loaded_ouroboros")
finish
endif
let g:loaded_ouroboros = 1
ftplugins are source every time a corresponding filetype it is useful to set local options or local commands having a global control variable prevents this.
command! -buffer -nargs=0 Ouroboros lua ouroboros.list()
commands should be enable in their corresponding scopes, global if they works across multiple buffers or local if they are expected to work only in the local buffer
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.