Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document haskell formatter #21

Closed
leg7 opened this issue Nov 2, 2023 · 1 comment
Closed

Document haskell formatter #21

leg7 opened this issue Nov 2, 2023 · 1 comment

Comments

@leg7
Copy link
Contributor

leg7 commented Nov 2, 2023

I spent quite a bit of time making a formatter for ghci (the haskell repl) and I imagine a lot of people are just going to give up trying to make REPLSendVisual work. I think documenting it as an example in the add your own repl or faq section would be very helpful.

Here's what I made:

-- to send a multiline function declaration to ghci you need to
-- surround it like so:
-- 	:{
-- 	code here
-- 	more code
-- 	:}
-- this function formats your visual selection to send it to ghci
function sendLinesGhci(lines)
	local i = 1
	local e = #lines

	while i <= e do
		while lines[i] == '' do
			i = i + 1
		end

		-- If there's more than 1 non empty line left
		if i < e then
			table.insert(lines, i, ':{')
			i = i + 1
			e = e + 1

			while i <= e and lines[i] ~= '' do
				i = i + 1
			end

			table.insert(lines, i, ':}')
			i = i + 1
			e = e + 1
		else -- if there's only 1 left skip it to end the loop
			i = i + 1
		end
	end
	table.insert(lines, '\n')

	return lines
end

local yarepl = require 'yarepl'
yarepl.setup {
	wincmd = 'vertical topleft 80 split',
	metas = {
		ghci = { cmd = 'ghci', formatter = sendLinesGhci },
	},
}

if you want I can make a pr updating the readme.

@milanglacier
Copy link
Owner

Thanks for your contribution. You can create a PR and point the solution to this issue. I would happy to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants