Re: Camel case to underscore-separated and back

From: Robert <ro....at.web.de>
Date: Thu, 11 Mar 2010 10:49:31 -0800 (PST)

Thanks for sharing this.
Recently I wanted to split a large file into smaller ones being named
file-1, file-2...
So I started to write some lines of Lua and assigned it to a keyboard
shortcut. After some trials it did everything I wanted: create a new
file, paste the rest of document into the new file, save it as file-
(+1).
Textadept magic!

filename = buffer.filename
n = tonumber(string.match(filename, "%d+"))
n = n + 1
newfilename = string.gsub(filename, "%d+", n)
buffer:document_end_extend ()
buffer:cut()
buffer:save()
_G.textadept.new_buffer()
buffer.paste()
buffer:save_as(newfilename)
buffer:goto_line(1)

- Robert

On Mar 10, 8:51 am, Brian Schott <briancsch....at.gmail.com> wrote:
> I was playing around a bit with the lua shell tonight and came up with
> the following:
>
> -- camel case to underscores
> keys.cU = {function()
> buffer:replace_sel(buffer:get_sel_text():gsub("(%u)", function(s) return
> "_"..string.lower(s) end)) end}
>
> -- underscores to camel case
> keys.cC = {function()
> buffer:replace_sel(buffer:get_sel_text():gsub("_(%w)", string.upper)) end}
>
> Select some text, hit the key combo, and watch in amazement as
> text_that_looks_like_this turns into textThatLooksLikeThis
>
> - Brian
Received on Thu 11 Mar 2010 - 13:49:31 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:40:00 EST