Giter Club home page Giter Club logo

Comments (10)

echasnovski avatar echasnovski commented on August 11, 2024 5

@lupont, @xigoi, sorry for the long delay. Didn't want to implement such big functionality without tests to check if nothing got broken. And in turn writing tests was a daunting task, so it took a while. But almost all modules are now covered with tests, including 'mini.surround'. So I decided to implement it right away.

The approach I decided to use is through config.custom_surroundings option. Both of your Latex related requests should be possible with the following setup:

require('mini.surround').setup({
  custom_surroundings = {
    l = {
      input = { find = [[\begin{(%w*)}.-\end{%1}]], extract = [[^(\begin{.-}).-(\end{.-})$]] },
      output = function()
        local latex_name = MiniSurround.user_input('Latex object name')
        return { left = ([[\begin{%s}]]):format(latex_name), right = ([[\end{%s}]]):format(latex_name) }
      end,
    },
    L = {
      input = { find = [[\%w+%b{}]], extract = '^(.-{).*(})$' },
      output = function()
        local cmd_name = MiniSurround.user_input('Latex command name')
        if cmd_name == nil then return nil end
        return { left = ([[\%s{]]):format(cmd_name), right = '}' }
      end,
    },
  },
})

Yes, a little bit complex, but that's the price for customization involving querying user for command name.

from mini.nvim.

echasnovski avatar echasnovski commented on August 11, 2024

Hello! Thanks for kind words. They mean a lot! :)

Yep, seems like a worthwhile request: useful and with (seemingly) quite compact implementation.
Played with it a bit and got it working. I have a couple of question regarding a better usage (not really a LaTeX user myself):

  • I feel that adding latex surrounding to hello string should lead to \begin{foo} hello \end{foo} (with spaces around word). Is this indeed the case?
  • Does inner part of {} always consist from alphanumeric characters? Are spaces allowed?
  • Currently (and possibly forever) adding surrounding to multiple lines will lead to adding surrounding after first whitespace of the first line and before last whitespace of last line. But quick browsing of LaTeX examples showed that \begin{}-\end{} are always on separate lines and are indented. I don't think achieving this will be easy with 'mini.surround'.

More thoroughly on last point. If you linewise visually highlight these two lines (for example, with Vip):

Hello
world

and execute sal (add 'l' surrounding) supplying document latex object, this will lead to (assuming this also adds whitespace around textobject):

\begin{document} Hello
world \end{document}

I currently don't plan to implement and support case when this leads to:

\begin{document}
Hello
world
\end{document}

from mini.nvim.

xigoi avatar xigoi commented on August 11, 2024

When we're at it, it would be nice to also support a "LaTeX command" surrounding (e.g. bar -> \foo{bar}).

from mini.nvim.

echasnovski avatar echasnovski commented on August 11, 2024

@lupont, could you try a latex (l) special surrounding in surround-latex branch?
@xigoi, this might be a little bit more complex as this is more like "function call" surrounding, which is a little "special". But I'll see what I can do.

from mini.nvim.

lupont avatar lupont commented on August 11, 2024

Wow, that was so fast! I have tried it a little and it seems to work well. I am by no means a LaTeX expert either, so if anyone reading knows something I don''t, please voice your opinion or concern!

  • I personally prefer not adding spaces, as it seems less noisy to me.
  • To my knowledge, \begin{}/\end{} tags are always alphanumeric.
  • It's a pity that newlines/indentation are difficult - as it would really be valuable when writing LaTeX. I would argue that it's also quite useful for the special_tag when writing *ml. I naïvely attempted to modify the special_latex function by adding \n and <CR>, which obviously did not work. Would you care to share some input as to why it would be difficult/you don't plan to support it?

Thanks a lot for this!

from mini.nvim.

echasnovski avatar echasnovski commented on August 11, 2024

About linewise selection, if I remember correctly, it was a combination of two reasons:

  1. This behavior is more uniform. I don't think that inserting on new lines when in linewise visual selection is appropriate in case of quotes and (at least for me most of the time) parenthesis. Also it simplifies code which is frankly already kind of complicated for my taste.
  2. Most of the time, when inserting surroundings on new lines, it also implies indenting the inner part. Which definitely won't be implemented here.

from mini.nvim.

lupont avatar lupont commented on August 11, 2024

I understand where you're coming from. I would like to prototype the functionality for myself when I get more time on my hands. If I succeed and feel comfortable with the solution, I'll open a PR to share it with you. But I won't expect you to merge it. Thanks again!

from mini.nvim.

echasnovski avatar echasnovski commented on August 11, 2024

If you are comfortable with this, sure, go ahead.
Some modules ('completion', 'surround') are already uncomfortably big and complex, and I really want to try to keep this minimal.
Hmm... Maybe some abstract "extension" mechanism in 'mini.surround' might solve this. But frankly it is not on the radar in the near future.

from mini.nvim.

lupont avatar lupont commented on August 11, 2024

I imagine using uppercase versions of these kinds of operators to mean "add newlines". But that's just an initial thought without much knowledge about the code base.

from mini.nvim.

lupont avatar lupont commented on August 11, 2024

Wow, awesome! I will be sure to try it out when I find some time. :) Thanks!

from mini.nvim.

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.