Git Product home page Git Product logo

Comments (14)

AckslD avatar AckslD commented on August 31, 2024 1

@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.

AckslD avatar AckslD commented on August 31, 2024

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.

jaidetree avatar jaidetree commented on August 31, 2024

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.

AckslD avatar AckslD commented on August 31, 2024

Yes, all of :q, :wq and w should work (where the last just updates without closing).

from nvim-femaco.lua.

jaidetree avatar jaidetree commented on August 31, 2024

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.

AckslD avatar AckslD commented on August 31, 2024

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.

jaidetree avatar jaidetree commented on August 31, 2024

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.

AckslD avatar AckslD commented on August 31, 2024

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.

jaidetree avatar jaidetree commented on August 31, 2024

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

2022-09-21 10 01 55

from nvim-femaco.lua.

jaidetree avatar jaidetree commented on August 31, 2024

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.

AckslD avatar AckslD commented on August 31, 2024

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.

jaidetree avatar jaidetree commented on August 31, 2024

That's what I was thinking too. Will try disabling it in those buffers.

from nvim-femaco.lua.

jaidetree avatar jaidetree commented on August 31, 2024

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:

image

from nvim-femaco.lua.

AckslD avatar AckslD commented on August 31, 2024

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)

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.