Giter Site home page Giter Site logo

Comments (5)

davidgranstrom avatar davidgranstrom commented on June 18, 2024 1

@kflak There has been some discussion recently with the merge of the luasnip snippet format. I would like to include options for snippet generation in this PR

I'm still not so sure how we would handle (autogenerated) mutli-line snippets transparently though, afaik this is not something I've seen before. The only option that I can think of at the moment is to have two version of each snippet and let the user select. This would double the amount of snippets generated though which is already quite extensive..

What I envision is to have different formatting options for snippet generation, maybe different styles e.g. compact, and ignore mul/add would be nice. Maybe multiline could also be an option?

With that said, another possibility would be to write a small function which expands a single line statement into a multiline after the actual snippet has been inserted. Something like this (note not extensively tested, cursor needs to be placed before the opening ( for this to work)

--- Split a single line function call into one parameter per line
function split_single_call()
  local lnum, col = unpack(vim.api.nvim_win_get_cursor(0))
  vim.api.nvim_buf_set_mark(0, '<', lnum, col, {})
  -- find the open paren
  vim.cmd[[normal! f(]]
  vim.cmd[[exe "normal! a\<cr>"]]
  -- find the closing paren
  vim.cmd[[normal! f)]]
  vim.cmd[[exe "normal! i\<cr>\<esc>k"]]
  -- perform the split
  vim.cmd[[s/,/,\r/g]] 
  lnum, col = unpack(vim.api.nvim_win_get_cursor(0))
  vim.api.nvim_buf_set_mark(0, '>', lnum, col, {})
  -- reindent
  vim.cmd[[normal! vgv=]]
end

from scnvim.

davidgranstrom avatar davidgranstrom commented on June 18, 2024

@kflak It would be simple to generate two versions of each snippet, one split on newlines as the example you posted. However, this will also make users have to choose between the two alternatives when expanding each snippet. Maybe this can be configured in the snippets engine somehow, there could be another keybinding for this perhaps.

Keeping the argument description would also be easy to implement. This could be a user setting as you mentioned. Another feature I've been thinking about is to have a setting to not include mul: 1, add: 0 in the snippet, since this can be accomplished easily outside of the method call.

from scnvim.

kflak avatar kflak commented on June 18, 2024

I'm just starting to wrap my head around UltiSnips, so I don't know too mch of how this would work, but I like the idea of setting up two different keybindings, one for each alternative. And dropping mul and add from the snippets would be very nice indeed :-)

from scnvim.

kflak avatar kflak commented on June 18, 2024

Hi,

Just wondering if there has been some movement on this? Otherwise I'd be happy to get some pointers on how to do this myself, so that I could possibly contribute a PR :-)

from scnvim.

kflak avatar kflak commented on June 18, 2024

This is great, I'll give that function a go at some point in the near future! Thanks for the tip.

from scnvim.

Related Issues (20)

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.