Char matches and highlighting in editing.lua

From: Robert <ro....at.web.de>
Date: Sun, 23 Jan 2011 19:12:41 +0100

Hi,

how about adding support for language specific char matches and
highlighted braces in editing.lua?
This could solve issue 130 [1] and would be similar to the already
existing tables for run commands and comments.
In editing.lua the default is defined and language specific modules
could define their own table, for example

-- Hypertext (or XML or PHP): highlight <> in addition to the default
_m.textadept.editing.braces.hypertext = { -- () [] {} <>
  [40] = 1, [91] = 1, [123] = 1, [60] = 1,
  [41] = 1, [93] = 1, [125] = 1, [62] = 1,
}

-- Hypertext: additionally match "<" with ">"
_m.textadept.editing.char_matches.hypertext = {
  [40] = ')', [91] = ']', [123] = '}', [39] = "'", [34] = '"', [60] = '>'
}

-- Latex: auto-match $ for math, but don't (!) match single quotes
_m.textadept.editing.char_matches.tex = {
  [40] = ')', [91] = ']', [123] = '}', [34] = '"', [36] = '$'
}

I added a check of the current lexer to the respective functions:
local lexer = buffer:get_lexer()
local char_matches = char_matches[lexer] or char_matches

Doing this checking of the current lexer would require changing the
event order in mime_types.lua, l. 150, because buffer_new emits an
update_ui event later:
events.connect('buffer_new', function()
  buffer.set_lexer, buffer.get_lexer = set_lexer, get_lexer
  buffer.get_style_name = get_style_name
end, 1)

Otherwise, in the highlighting function I removed the check of the
current style 'operator' because the hypertext lexer does not have it.
Additionaly, I like the highlighting of braces in strings (e.g. SQL
within a string), but this is probably a matter of taste (e.g. braces
in comments get highlighted as well with this setting).
I changed the luadoc comments a bit, I hope they would make sense like this.
A diff is attached.

Robert

[1]: http://code.google.com/p/textadept/issues/detail?id=130

Received on Sun 23 Jan 2011 - 13:12:41 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:59:15 EST