diff options
author | 2008-08-08 22:59:56 -0400 | |
---|---|---|
committer | 2008-08-08 22:59:56 -0400 | |
commit | f11c0707993bf3f74d85bb298987d0da07a64734 (patch) | |
tree | b00715f5e733a2f64f3cf7ae581678d2f764af0e /core/events.lua | |
parent | ddfe6bd8deedb1b02ef3333eebbf609d7345a5be (diff) | |
download | textadept-f11c0707993bf3f74d85bb298987d0da07a64734.tar.gz textadept-f11c0707993bf3f74d85bb298987d0da07a64734.zip |
Replaced C code for setting default editor and buffer properties with Lua code.
Diffstat (limited to 'core/events.lua')
-rw-r--r-- | core/events.lua | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/core/events.lua b/core/events.lua index c708af62..d43a0ff5 100644 --- a/core/events.lua +++ b/core/events.lua @@ -415,3 +415,107 @@ function error(...) end textadept.print = error + +--- +-- Sets the default properties for a Scintilla window. +-- Called as an event; no handler available. +function set_default_editor_properties() + local c, buffer = textadept.constants, buffer + + -- properties + buffer.property['textadept.home'] = _HOME + buffer.property['lexer.lua.home'] = _HOME..'/lexers/' + buffer.property['lexer.lua.script'] = _HOME..'/lexers/lexer.lua' + + -- caret + buffer.caret_fore = 11184810 -- 0xAA | 0xAA << 8 | 0xAA << 16 + buffer.caret_line_visible = true + buffer.caret_line_back = 4473924 -- 0x44 | 0x44 << 8 | 0x44 << 16 + buffer:set_x_caret_policy(1, 20) -- CARET_SLOP + buffer:set_y_caret_policy(13, 1) -- CARET_SLOP | CARET_STRICT | CARET_EVEN + buffer.caret_style = 2 + buffer.caret_period = 0 + + -- selection + buffer:set_sel_fore(1, 3355443) -- 0x33 | 0x33 << 8 | 0x33 << 16 + buffer:set_sel_back(1, 10066329) -- 0x99 | 0x99 << 8 | 0x99 << 16 + + buffer.margin_width_n[0] = 4 + 3 * -- line number margin + buffer:text_width(c.STYLE_LINENUMBER, '9') + + buffer.margin_width_n[1] = 0 -- marker margin invisible + + -- fold margin + buffer:set_fold_margin_colour(1, 11184810) -- 0xAA | 0xAA << 8 | 0xAA << 16 + buffer:set_fold_margin_hi_colour(1, 11184810) -- 0xAA | 0xAA << 8 | 0xAA << 16 + buffer.margin_type_n[2] = c.SC_MARGIN_SYMBOL + buffer.margin_width_n[2] = 10 + buffer.margin_mask_n[2] = c.SC_MASK_FOLDERS + buffer.margin_sensitive_n[2] = true + + -- fold margin markers + buffer:marker_define(c.SC_MARKNUM_FOLDEROPEN, c.SC_MARK_ARROWDOWN) + buffer:marker_set_fore(c.SC_MARKNUM_FOLDEROPEN, 0) + buffer:marker_set_back(c.SC_MARKNUM_FOLDEROPEN, 0) + buffer:marker_define(c.SC_MARKNUM_FOLDER, c.SC_MARK_ARROW) + buffer:marker_set_fore(c.SC_MARKNUM_FOLDER, 0) + buffer:marker_set_back(c.SC_MARKNUM_FOLDER, 0) + buffer:marker_define(c.SC_MARKNUM_FOLDERSUB, c.SC_MARK_EMPTY) + buffer:marker_define(c.SC_MARKNUM_FOLDERTAIL, c.SC_MARK_EMPTY) + buffer:marker_define(c.SC_MARKNUM_FOLDEREND, c.SC_MARK_EMPTY) + buffer:marker_define(c.SC_MARKNUM_FOLDEROPENMID, c.SC_MARK_EMPTY) + buffer:marker_define(c.SC_MARKNUM_FOLDERMIDTAIL, c.SC_MARK_EMPTY) + + -- various + buffer.buffered_draw = true + buffer.two_phase_draw = false + buffer.call_tip_use_style = 32 + buffer.use_popup = 0 + buffer:set_fold_flags(16) + buffer.mod_event_mask = c.SC_MOD_CHANGEFOLD + buffer.scroll_width = 2000 + buffer.h_scroll_bar = true + buffer.end_at_last_line = true + buffer.caret_sticky = false +end + +--- +-- Sets the default properties for a Scintilla document. +-- Called as an event; no handler available. +-- If an error occurs, this is disastrous because the error handler creates a +-- new buffer (to display the message), but this function is called again for +-- that buffer, and an infinite loop ensues. So if an error occurs, catch it +-- and print it to stderr. +function set_default_buffer_properties() + local function run() + local textadept, buffer = textadept, buffer + -- default font + buffer.style_font[32] = "!Bitstream Vera Sans Mono" + buffer.style_size[32] = 8 + buffer.style_fore[32] = 11184810 -- 0xAA | 0xAA << 8 | 0xAA << 16 + buffer.style_back[32] = 3355443 -- 0x33 | 0x33 << 8 | 0x33 << 16 + buffer.style_bits = 8 + + -- folding + buffer.property['fold'] = '1' + buffer.property['fold.by.indentation'] = '1' + + -- lexers + buffer.lexer = textadept.constants.SCLEX_LPEG + buffer:set_lexer_language('container') + + -- tabs and indentation + buffer.tab_width = 2 + buffer.use_tabs = true + buffer.indent = 2 + buffer.tab_indents = true + buffer.back_space_un_indents = true + buffer.indentation_guides = 1 + + -- various + buffer.eol_mode = textadept.constants.SC_EOL_LF + buffer.auto_c_choose_single = true + end + local ret, errmsg = pcall(run) + if not ret then io.stderr:write(errmsg) end +end |