zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.42k stars 1.16k forks source link

How to Justify selected text ? #3147

Open ghost opened 4 months ago

ghost commented 4 months ago

What is the equivalent of Nano's ^J for justifying text in Micro ?

Screenshot_20240220-094758.png

Also Thank you very very much for creating a beautiful text editor like this. ❤️

dustdfg commented 3 months ago

I believe it is a work for plugin (If you are about hard wrap which persist in the file). @taconi does prettier https://github.com/taconi/plugin-channel/issues/37 solves this?

If you need softwrap you can use softwrap and wordwrap options

taconi commented 3 months ago

The prettier plugin uses the prettier tool and I know that it formats markdown files, maybe this plugin with some config help to solve this. The other plugin with the same name also uses prettier if the other one helps.

You can also use the manager plugin to create your own formatters:

-- ~/.config/micro/init.lua
MANAGER_FORMATTERS_ENABLED = true

formatters = {
  -- yarn global add markdownlint-cli
  { cmd = 'markdownlint --dot --fix %f', onSave = true, filetypes = { 'markdown' } },
}
slashdevslashurandom commented 2 months ago

Seems kinda annoying that the solution is to install a plugin that depends on a tool written in node.js. I tried to write a plug-in that would do that, but could not figure how to access util.StringWidth from Lua code (which would be necessary to figure out how long a string is, because Lua's string functions don't care about UTF-8).

dmaluka commented 2 months ago

I tried to write a plug-in that would do that, but could not figure how to access util.StringWidth from Lua code (which would be necessary to figure out how long a string is, because Lua's string functions don't care about UTF-8).

We can add exporting util.StringWidth to Lua, if needed. It should be trivial to implement.

Or perhaps you can get by with using the buffer cursor's GetVisualX() method, which uses util.StringWidth underneath?

slashdevslashurandom commented 2 months ago

That sounds like it would be a reasonable addition in general, as, for example, anyone who would want to write a plug-in that prints or outputs a table would also want to know the width of strings of text.