Re: [code] [TextAdept] AllCaps Plugin / Bind Key

From: Mitchell <m.att.foicica.com>
Date: Fri, 10 Apr 2020 08:51:34 -0400 (EDT)

Hi Jonathan,

On Thu, 9 Apr 2020, Jonathan Levi wrote:

> I am looking to make a simple module for TextAdept that will capitalize the
> selected text on a short-cut.
>
> I have done a few things with modifying TextAdept but I am afraid it has
> been long enough I do not remember. And I am not good at Lua.
>
> I know I need to add a `modules/moduleName/init.lua`.
> In there I make a function which somehow modifies the buffer, and then
> somehow I bind a short-cut key to call that function?

For a simple function, you don't even need a module. You can simply bind a key to that function in your *~/.textadept/init.lua*. Something like:

   keys.aa = function() -- Alt+A
     if buffer.selection_empty then return end -- nothing to do
     local text = buffer:get_sel_text()
     text = text:gsub('^%l', function(char) return string.upper(char) end)
     buffer:replace_sel(text)
   end

This is untested, so you may need to tweak as necessary.

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.
Received on Fri 10 Apr 2020 - 08:51:34 EDT

This archive was generated by hypermail 2.2.0 : Sat 11 Apr 2020 - 06:37:17 EDT