Re: [code] How to make the folding markers larger?

From: David Tamar <von.tamar.att.outlook.com>
Date: Fri, 22 Feb 2019 18:30:02 +0000

Thanks, Mitchell!
I adjusted the width to 36px and it looks amazing and so clickable!
I've removed the horizontal line and I think it's nearly perfect at this point, so I'm content with the current solution, but I didn't manage to get the event handler work properly.

The function `toggle_fold_show_text` didn't work for some reason, and it also doesn't seem to appear in the autocomplete options nor in the API docs. There's a similar function called `toggle_fold_display_text` which I tried to use instead, but Textadept's Lua interpreter says it's just `nil` as if this function doesn't exist. I guess the function was renamed just recently? (my Textadept version is 10.2)

I then tried to test the event with the basic function `toggle_fold` to merely figure out if the event is being invoked at all. I found out that the event is invoked only if I press on either margin [1] or the empty margin [3] which is between the folding markers and the text itself. However, the event won't trigger at all if I'm pressing on the folding margin [2] itself or on the line numbers' margin [0].

When the event is invoked at margins [1] and [3], it prints correct 0-based line number & margin index, but neither of the functions `toggle_fold`, `toggle_fold_show_text` or `toggle_fold_display_text` manage to fold the clause starting at this line. I tried to use a 1-based line index as well by sending `line + 1` to each of these functions, it didn't work either.

Here's the event that I've placed in my init.lua:
`buffer.fold_display_text_style = buffer.FOLDDISPLAYTEXT_BOXED
events.connect(events.MARGIN_CLICK,
function(margin, position)
  --if margin ~= 2 then return end
  local line = buffer:line_from_position(position)
  ui.print("Line: " .. tostring(line) .. ", margin: " .. tostring(margin)) -- debug
  buffer:toggle_fold(line)
  --buffer:toggle_fold_show_text(line, '[...]')
  --buffer:toggle_fold_display_text(line, '[...]')
end)`

________________________________
From: Mitchell <m.att.foicica.com>
Sent: Friday, February 22, 2019 5:41
To: code.att.foicica.com
Subject: Re: [code] How to make the folding markers larger?

Hi David,

On Fri, 22 Feb 2019, David Tamar wrote:

> Hi everyone. I'm new to Textadept and I'm still learning how it works and configuring it for the last two weeks since I've found it.
>
> I'm trying to increase the size of the folding buttons which appear in the left margin, they're typically boxes containing +/-. The problem with them is that they're way too small for me, my screen is 12.5" with 176 DPI, I have to make them at least twice as large. I tried to search both the Textadept API documentation and the Scintilla documentation for clues but I couldn't find anything on that specifically, and Google wasn't friendly due to the terms describing it.

Try putting in your *~/.textadept/init.lua*:

   buffer.margin_width_n[2] = 24

The default is 12 pixels. You can experiment using the Lua command entry before committing to your *init.lua*.

> I'm also trying to find a way to make the default folding style appear as "[...]" at the end of the folding line (for any language), instead of having that horizontal line beneath it stretching over the whole line (I'm trying to remove that horizontal line as well).

There is no way to automatically do this. You'll have to first set:

   buffer.fold_display_text_style = buffer.FOLDDISPLAYTEXT_BOXED

This enables the ability to show some text at the end of a folded line. Then you'll want to listen for `events.MARGIN_CLICK` events:

   events.connect(events.MARGIN_CLICK, function(margin, position)
     if margin ~= 2 then return end -- only interested in fold margin
     local line = buffer:line_from_position(position)
     buffer:toggle_fold_show_text(line, '[...]')
   end)

You can use anything for the string. You can also tie the functionality to a key command or menu command. You may have to tweak the snippet, as I haven't tested it.

You can hide the fold line with:

   buffer.fold_flags = 0

(It's a bitmask value.)

I hope that helps.

Cheers,
Mitchell

--
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 22 Feb 2019 - 13:30:02 EST

This archive was generated by hypermail 2.2.0 : Sat 23 Feb 2019 - 06:40:13 EST