Re: [code] Possible callback used to manipulate items in gui.filteredlist() and io.snapopen()

From: Mitchell <m.att.foicica.com>
Date: Mon, 8 Apr 2013 11:40:21 -0400 (Eastern Daylight Time)

Ryan,

On Mon, 8 Apr 2013, Ryan Pusztai wrote:

> [snip]
>
>> The good news is that you can just re-define `io.snapopen` to your liking
>> from your init.lua rather than having to re-copy the old snapopen module. I
>> know this may be non-ideal for you, but I'm not sure of a better way to do
>> it.
>>
>
> Can you give a quick example. I am not quite seeing how to re-define this
> and would like to. I am on a domain and it makes my path at least 2
> directories deeper. My "home" paths get pretty long.
> In your example just make up the function to call that would shorten the
> path name. I will come up with the way to implement that. I am just unclear
> about what it would look like to re-define io.snapopen() and any help would
> be greatly appreciated.

At the top of your init.lua (before "_M.textadept = require 'textadept'"):

io.snapopen = function(utf8_paths, filter, exclude_FILTER, ...)
   local list = {}
   for utf8_path in utf8_paths:gmatch('[^\n]+') do
     lfs.dir_foreach(utf8_path, function(file)
       if #list >= io.SNAPOPEN_MAX then return false end
       list[#list + 1] = file:gsub('^%.[/\\]', '')
                             :gsub('^'..os.getenv('USERPROFILE'), '~')
       -- ADDED THIS --------^
     end, filter, exclude_FILTER)
   end
   local width = CURSES and {'--width', gui.size[1] - 2} or ''
   -- CHANGED BELOW
   local file = gui.filteredlist(_L['Open'], _L['File'], list, false,
                                 '--select-multiple', width, ...) or ''
   file = file:gsub('^~', os.getenv('USERPROFILE'))
   io.open_file(file)
end

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.
Received on Mon 08 Apr 2013 - 11:40:21 EDT

This archive was generated by hypermail 2.2.0 : Tue 09 Apr 2013 - 06:49:33 EDT