Comments (10)
@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.
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.
When we're at it, it would be nice to also support a "LaTeX command" surrounding (e.g. bar
-> \foo{bar}
).
from mini.nvim.
@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.
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 thespecial_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.
About linewise selection, if I remember correctly, it was a combination of two reasons:
- 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.
- 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.
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.
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.
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.
Wow, awesome! I will be sure to try it out when I find some time. :) Thanks!
from mini.nvim.
Related Issues (20)
- mini.starter: `buf_id` in `refresh()` is not an identifier of valid Starter buffer. HOT 6
- Completion errors with "'width' key must b e a positive Integer" HOT 3
- snippet support for mini.completion HOT 1
- Error when executing <C-w><C-d> HOT 5
- simplify custom sessions autoread HOT 5
- deps performs invalid envsubst invocation HOT 2
- Expose the rest of `H.builtin_textobjects` so users can assign them to a different key HOT 4
- mini.align does not take inlay hint into account. HOT 1
- Beta-testing 'mini.git' HOT 53
- Don't set terminal colors in base16 HOT 1
- mini.statusline: vim.diagnostic.is_enabled null reference HOT 4
- mini.ai newline bug HOT 4
- Completion performance regression HOT 3
- [mini.deps] Visual distinction of breaking commits in confirm buffers? HOT 6
- [mini.test] some way to update screenshots HOT 1
- [mini.test] add generic version of screenshot functionality HOT 6
- [mini.test] screenshot name is prefixed with `.` when run_file() argument starts with `./` HOT 3
- [mini.test] add ability to isolate only one test in a test file to be run in the CLI HOT 5
- [mini.clue] configurable backspace and enter binds HOT 1
- [mini.test] MiniTest.new_child_neovim() add option to proxy to current neovim for debugging purposes HOT 3
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 mini.nvim.