Comments (14)
@eccentric-j I opened #17 to optionally be able to ensure newlines. So for example you can configure this as:
require('femaco').setup({
ensure_newline = function(base_filetype)
return base_filetype == 'norg'
end,
})
and then you don't have to disable the formatting.
Let me know if that works for you.
from nvim-femaco.lua.
Thanks for reporting! I'm not able to reproduce this, are you on latest FeMaco
, nvim-treesitter
and neorg
?
If so could you send me what the output of:
lua =vim.treesitter.get_node_text(require('nvim-treesitter.query').get_matches(0, 'injections')[1].content.node, 0)
and
lua =vim.treesitter.get_node_range(require('nvim-treesitter.query').get_matches(0, 'injections')[1].content.node)
are. Assuming that this is the first injection in your file. If not change the 1
to what's needed to match the code-block your on.
from nvim-femaco.lua.
Will get those values, but for clarity, what is the intended way to accept what's in the float and send it back to the main file?
I was using :wq
, is that correct?
from nvim-femaco.lua.
Yes, all of :q
, :wq
and w
should work (where the last just updates without closing).
from nvim-femaco.lua.
Tried running that command, but got an error. I run this after editing the first code block in a norg document with FeMaco?
E5108: Error executing lua [string ":lua"]:1: attempt to index field 'content' (a nil value)
stack traceback:
[string ":lua"]:1: in main chunk
from nvim-femaco.lua.
Thanks for trying, I suspect the index is not correct. Would you mind running the following instead to print all the injections:
local bufnr = 1
for _, match in ipairs(require('nvim-treesitter.query').get_matches(bufnr, 'injections')) do
for capture_name, capture in pairs(match) do
local node = capture.node
print(capture_name)
print(' text: ', vim.treesitter.get_node_text(node, bufnr))
print(' range: ', vim.treesitter.get_node_range(node))
end
print()
end
adjusting the bufnr
to the neorg buffer. For example you can but this in a file and source it with :source %
.
from nvim-femaco.lua.
Set the bufnr to 0 for current buffer
norg_meta
text: title: Neo Vim Configuration
^Idescription:
^Iauthor: eccentric-J
^Icreated: 2022-09-16
^Itangle: {
^I languages: {
^I fennel: ./fnl/config/core.fnl
^I }
^I scope: tagged
^I}
range: 1 1 11 0
_tagname
text: document.meta
range: 0 1 0 14
language
text: vim
range: 79 10 79 13
_tagname
text: code
range: 79 5 79 9
content
text: " Execute the command and get its output
let cmd = a:cmd
redir => output
silent exe cmd
redir END
range: 80 4 85 0
language
text: fennel
range: 124 9 124 15
_tagname
text: code
range: 124 4 124 8
content
text: [{:name "null-ls" :root "/Users/j/projects/crunchy-price-calc"}]
range: 125 3 126 0
language
text: shell
range: 208 8 208 13
_tagname
text: code
range: 208 3 208 7
content
text: make
range: 209 2 210 0
language
text: fennel
range: 214 8 214 14
_tagname
text: code
range: 214 3 214 7
content
text: ;; DO NOT EDIT THIS FILE
;; Generated from ../neovim.norg
range: 215 2 217 0
language
text: fennel
range: 220 8 220 14
_tagname
text: code
range: 220 3 220 7
content
text: (local configdir (vim.fn.stdpath "config"))
range: 221 2 222 0
language
text: fennel
range: 229 8 229 14
_tagname
text: code
range: 229 3 229 7
content
text: (let [rtp (vim.api.nvim_get_option "runtimepath")
custompaths [(.. configdir "/fnl")
(.. configdir "/lua")]
customrtp (table.concat custompaths ",")]
(vim.api.nvim_set_option "runtimepath" (.. customrtp "," rtp)))
range: 230 2 235 0
language
text: fennel
range: 242 8 242 14
_tagname
text: code
range: 242 3 242 7
content
text: (global fennel (require :config.fennel))
range: 243 2 244 0
language
text: fennel
range: 250 8 250 14
_tagname
text: code
range: 250 3 250 7
content
text: (let [fnldir (.. configdir "/fnl")]
(each [_ dir (ipairs ["/?.fnl" "/?/init.fnl"])]
(tset fennel :path (.. fnldir dir ";" fennel.path))))
range: 251 2 254 0
language
text: fennel
range: 261 8 261 14
_tagname
text: code
range: 261 3 261 7
content
text: (table.insert package.loaders 1 fennel.searcher)
range: 262 2 263 0
language
text: fennel
range: 268 8 268 14
_tagname
text: code
range: 268 3 268 7
content
text: (local cfg (require :config.core))
range: 269 2 270 0
language
text: fennel
range: 275 8 275 14
_tagname
text: code
range: 275 3 275 7
content
text: cfg
range: 276 2 277 0
from nvim-femaco.lua.
Oh hold, I see now, the @end
is not replaced, it's at the end of the last line of the code block. Which makes sense you removed the last newline of the floating buffer. Since we also support inline injections we can't assume that there should be a newline at the end of the content, so you need to keep it there. Does that make sense?
You can try again but just end with a newline.
from nvim-femaco.lua.
I think I follow, I opened the femaco UI, kept the newline at the end, and tried to insert text above it but it still joined the the @end
to the end of the newly entered line
from nvim-femaco.lua.
I've tested with a few other languages and it does seem to work a bit better. For some reason not working with fennel.
Does the same happen to you with fennel or is it unique to my config?
from nvim-femaco.lua.
Could it be that you have some formatter which removes newlines at the end of a file upon save for fennel? It does not happen for me but I have no setup for fennel.
from nvim-femaco.lua.
That's what I was thinking too. Will try disabling it in those buffers.
from nvim-femaco.lua.
Created a toggle system for the autoformatting and disabled it in the FeMaco buffer. With autoformatting disabled, it was working so it must have been stripping out the whitespace on pre-save.
That said, there is another issue I've noticed where the indentation is off after saving in neorg:
from nvim-femaco.lua.
If it is useful for you, maybe we can add an optional setting to always include the newline when updating the buffer. Then you perhaps wouldn't have to disable formatting (which is a pity).
What's the new issue actually?
from nvim-femaco.lua.
Related Issues (18)
- Add alternate styling to render window in-buffer using virtual lines HOT 3
- Error: attempt to call field 'get_node_range' (a nil value) HOT 8
- Detect FeMaco buffer on LSP attach HOT 1
- Dim main buffer to focus on code HOT 1
- [feat] use same buffer for multiple code chunks (+ collaboration ideas) HOT 6
- Expand `float_opts` with user's options HOT 4
- Handle language specific settings HOT 2
- Incorrect indentation in org-mode HOT 2
- nvim-treesitter changed @language to @_lang in injections.scm for markdown HOT 7
- Can `FeMaco` add a mechanism for clean temp file HOT 2
- Extend functionality to any buffer with injected language blocks? HOT 13
- Question: future of nvim-FeMaco.lua HOT 2
- Error when use command `:Femaco` HOT 5
- Question: When I use FeMaco to input a code, it will automatically insert `v:null` HOT 5
- Nothing happend after call `:FeMaco` HOT 1
- Split or separate buffer instead of floating window HOT 3
- Support for inline injections
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-femaco.lua.