Code Monkey home page Code Monkey logo

Comments (6)

LudoPinelli avatar LudoPinelli commented on July 1, 2024 2

Done!
I called them "titled lines" and made sure they are as flexible as the boxes. I hope they reach your expectation, but if not please let me know! :)

from comment-box.nvim.

LudoPinelli avatar LudoPinelli commented on July 1, 2024 1

Sorry for the very late answer. It was part of the few ideas I had to add, but as you can see I didn't work on the plugin for quite some time... I'll do my best in the coming few weeks to give some updates.

from comment-box.nvim.

StephanRoemer avatar StephanRoemer commented on July 1, 2024 1

No worries, take your time and thanks for getting back to me!

Cheers!

from comment-box.nvim.

okuma10 avatar okuma10 commented on July 1, 2024 1

Since there was no implementation on this I poke around a bit with the function....

local function create_line(choice, centered_line, right_aligned_line)
	local symbols = set_line(choice)
	comment_string = vim.bo.commentstring
	local line = {}
	local lead_space = " "
	local filetype = vim.bo.filetype
    
    -- Sanetize current line text
    local line_text = string.gsub(vim.api.nvim_get_current_line(), "^%s*", "")
    -- Add whitespaces if there is text on line
    if string.len(line_text) > 0 then
        line_text = " " .. line_text .. " "
    end

	if centered_line then
		lead_space = string.rep(
			" ",
			math.floor((settings.doc_width - settings.line_width) / 2 - vim.fn.strdisplaywidth(comment_string))
		)
	elseif right_aligned_line then
		lead_space = string.rep(
			" ",
			settings.doc_width - settings.line_width - vim.fn.strdisplaywidth(comment_string) + 2
		)
	end

	if lead_space == "" then
		lead_space = " "
	end

	comment_string, comment_string_end = comment_string:match("^(.*)%%s(.*)")

	if not comment_string or filetype == "markdown" or filetype == "org" then
		comment_string = ""
	end

	if settings.line_blank_line_above then
		table.insert(line, "")
	end
	table.insert(
		line,
		string.format(
			"%s%s%s%s%s%s%s%s",
			comment_string,
			lead_space,
			symbols.line_start,
			string.rep(symbols.line, ( settings.line_width/2 ) - 2),
            line_text,
			string.rep(symbols.line, ( settings.line_width/2 ) - 2),
			symbols.line_end,
			comment_string_end
		)
	)
	if settings.line_blank_line_below then
		table.insert(line, "")
	end
	return line
end

The result

image

It's a bit ugly since it doesn't take into account the string length, but it works for a quick patch.

from comment-box.nvim.

okuma10 avatar okuma10 commented on July 1, 2024 1

Does that still work with the CBline?

EDIT:
Oh, it's CBl[l,c,r]line . A bit more keys to press but the alignment feature is sweet thanks

from comment-box.nvim.

LudoPinelli avatar LudoPinelli commented on July 1, 2024

Yes, the CBline still works but it's for line without text.

from comment-box.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.