[code] [textadept] Column Marks for TA

From: Qwerky <mr.qwerky.att.gmail.com>
Date: Thu, 8 Aug 2019 13:12:57 -0600

Hello, TA world!

Like many editors, TextAdept has a capability to indicate the
right-margin of a document, either by a coloured vertical line at that
column, or by a coloured background for columns beyond the margin.  It
also has the capability to display multiple vertical lines to indicate
specified column positions.  But these two mutually exclusive abilities
are an all-or-nothing feature--once set, they apply to all open files.

'Column Marks' for TA provides the ability for each open file to have to
have its own edge-mode (either none, background, line, or multiline),
its own edge-column or multiple column marks, and its own
edge-background/edge-column, or column mark colour.  It also adds a
'Column Marks' menu which allows setting the Edge Mode (Background,
Line, Multiline, None), setting the Edge Column and Edge Colour, and
setting multiple Column Marks and Column Mark Colour.

Additionally, 'Column Marks' provides two functions, 'Next Column Mark'
and 'Previous Column Mark', which may be bound to keys, to move the
caret to the next or previous column mark column.  This is invaluable
for editing columnar-type data.

Secret Hint:  once multiple column marks are set, the edge-mode may be
set to another setting (background, line, none), and the 'Next Column
Mark' and 'Previous Column Mark' functions will continue to operate,
even without the column marks being visible.

Bonus:  'Column Marks' also allows the insert/overtype mode to be set
individually for each file.

'History' for TA has also been updated to save and restore the
edge-mode, edge-column, edge-colour, column-mark-colour, and
column-marks for each file, when 'Column Marks' is installed.  Because
of this, I am including the updated 'History' as well.

To install either 'Column Marks' or 'History', either:

A.  Place the columnmarks.lua or history.lua file in your
/USERHOME/modules/common/ directory, where it should be automatically
'require'd if you have installed the appropriate code from the TextAdept
wiki; or

B.  In your /USERHOME/modules/ directory, create a 'columnmarks' or
'history' directory, copy the columnmarks.lua or history.lua file to
that directory but rename it to 'init.lua', and then 'require' that
directory in your user 'init.lua' file.

Please see the 'NOTES:' section at the beginning of the
'columnmarks.lua' file or 'history.lua' file for settings you may wish
to change.

In particular, 'History' monitors 'events.INITIALIZED', 'events.QUIT',
'events.FILE_OPENED', and 'events.FILE_AFTER_SAVE', in order to load,
update, and save the history file.  However, TA provides no event for a
file being closed, and therefore if a file is closed before the program
is exited, 'History' will not be able to update that file's history.

To overcome this, I have added the monitoring of an
'events.FILE_BEFORE_CLOSE' event to 'History'.  This event is defined in
'History' as "local events_FILE_BEFORE_CLOSE = 'file_before_close'". 
This will, of course, have no effect (nor cause any issue) unless such
an event is emitted elsewhere.  To accomplish this the user may add, if
he so chooses, the single line `events.emit('file_before_close',
buffer.filename)` immediately before the `buffer:delete()` line at the
end of the `io.close_buffer()` function, within the
`/textadept/core/file_io.lua` file.

This may be considered a request to Mitchell to add a file-close event. 
In my own case, the added line is actually
'events.emit(events.FILE_BEFORE_CLOSE, buffer.filename)', having
documented and defined the event in the appropriate locations at the top
of the file, with the lines:

-- @field _G.events.FILE_BEFORE_CLOSE (string)
--   Emitted right before closing a file.
--   Emitted by [`io.close_buffer()`]().
--   Arguments:

--
--   * _`filename`_: The filename of the file being closed.
and
events.FILE_BEFORE_CLOSE = 'file_before_close'
Feedback is welcome.  I hope 'Column Marks' and 'History' will prove 
useful to other users as well.
qwerky


-- 
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 Thu 08 Aug 2019 - 15:12:57 EDT

This archive was generated by hypermail 2.2.0 : Fri 09 Aug 2019 - 06:50:17 EDT