aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-08-08 22:59:56 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2008-08-08 22:59:56 -0400
commitf11c0707993bf3f74d85bb298987d0da07a64734 (patch)
treeb00715f5e733a2f64f3cf7ae581678d2f764af0e
parentddfe6bd8deedb1b02ef3333eebbf609d7345a5be (diff)
downloadtextadept-f11c0707993bf3f74d85bb298987d0da07a64734.tar.gz
textadept-f11c0707993bf3f74d85bb298987d0da07a64734.zip
Replaced C code for setting default editor and buffer properties with Lua code.
-rw-r--r--core/events.lua104
-rw-r--r--src/textadept.c109
-rw-r--r--src/textadept.h2
3 files changed, 108 insertions, 107 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
diff --git a/src/textadept.c b/src/textadept.c
index 54546a1d..61f32f96 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -185,7 +185,6 @@ GtkWidget* new_scintilla_window(sptr_t buffer_id) {
signal(editor, "key_press_event", t_keypress);
signal(editor, "command", t_command);
signal(editor, SCINTILLA_NOTIFY, t_notification);
- set_default_editor_properties(SCINTILLA(editor));
l_add_scintilla_window(editor);
gtk_widget_grab_focus(editor); focused_editor = editor;
if (buffer_id) {
@@ -193,6 +192,7 @@ GtkWidget* new_scintilla_window(sptr_t buffer_id) {
new_scintilla_buffer(SCINTILLA(editor), false, false);
} else new_scintilla_buffer(SCINTILLA(editor), false, true);
l_set_view_global(editor);
+ l_handle_event("set_default_editor_properties");
l_handle_event("view_new");
return editor;
}
@@ -237,15 +237,8 @@ void new_scintilla_buffer(ScintillaObject *sci, bool create, bool addref) {
l_add_scintilla_buffer(doc);
SS(sci, SCI_ADDREFDOCUMENT, 0, doc);
}
- // Setup default styling and properties.
- SS(sci, SCI_STYLESETFONT, 32,
- reinterpret_cast<long>("!Bitstream Vera Sans Mono"));
- SS(sci, SCI_STYLESETSIZE, 32, 8);
- SS(sci, SCI_STYLESETFORE, 32, 0xAA | (0xAA << 8) | (0xAA << 16));
- SS(sci, SCI_STYLESETBACK, 32, 0x33 | (0x33 << 8) | (0x33 << 16));
- SS(sci, SCI_SETSTYLEBITS, 8, 0);
- set_default_buffer_properties(sci);
l_set_buffer_global(sci);
+ l_handle_event("set_default_buffer_properties");
l_handle_event("buffer_new");
}
@@ -375,6 +368,7 @@ void set_menubar(GtkWidget *new_menubar) {
* @param text The text to display.
*/
void set_statusbar_text(const char *text) {
+ if (!statusbar) return;
gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 0);
gtk_statusbar_push(GTK_STATUSBAR(statusbar), 0, text);
}
@@ -385,6 +379,7 @@ void set_statusbar_text(const char *text) {
* @param text The text to display.
*/
void set_docstatusbar_text(const char *text) {
+ if (!docstatusbar) return;
gtk_statusbar_pop(GTK_STATUSBAR(docstatusbar), 0);
gtk_statusbar_push(GTK_STATUSBAR(docstatusbar), 0, text);
}
@@ -545,102 +540,6 @@ static bool w_exit(GtkWidget*, GdkEventAny*, gpointer) {
return false;
}
-// Properties
-
-static long SSS(ScintillaObject *sci, unsigned int msg, const char *wParam=0,
- const char *lParam=0) {
- return scintilla_send_message(sci, msg, reinterpret_cast<long>(wParam),
- reinterpret_cast<long>(lParam));
-}
-
-#define sp(k, v) SSS(sci, SCI_SETPROPERTY, k, v)
-#define color(r, g, b) r | (g << 8) | (b << 16)
-
-/**
- * Sets the default properties for a Scintilla window.
- * @param sci The Scintilla window to set default properties for.
- */
-void set_default_editor_properties(ScintillaObject *sci) {
- sp("textadept.home", textadept_home);
- sp("lexer.lua.home", "/usr/share/textadept/lexers/");
- sp("lexer.lua.script", "/usr/share/textadept/lexers/lexer.lua");
-
- // caret
- SS(sci, SCI_SETCARETFORE, color(0xAA, 0xAA, 0xAA));
- SS(sci, SCI_SETCARETLINEVISIBLE, true);
- SS(sci, SCI_SETCARETLINEBACK, color(0x44, 0x44, 0x44));
- SS(sci, SCI_SETXCARETPOLICY, CARET_SLOP, 20);
- SS(sci, SCI_SETYCARETPOLICY, CARET_SLOP | CARET_STRICT | CARET_EVEN, 1);
- SS(sci, SCI_SETCARETSTYLE, 2);
- SS(sci, SCI_SETCARETPERIOD, 0);
-
- // selection
- SS(sci, SCI_SETSELFORE, 1, color(0x33, 0x33, 0x33));
- SS(sci, SCI_SETSELBACK, 1, color(0x99, 0x99, 0x99));
-
- SS(sci, SCI_SETBUFFEREDDRAW, 1);
- SS(sci, SCI_SETTWOPHASEDRAW, 0);
- SS(sci, SCI_CALLTIPUSESTYLE, 32);
- SS(sci, SCI_USEPOPUP, 0);
- SS(sci, SCI_SETFOLDFLAGS, 16);
- SS(sci, SCI_SETMODEVENTMASK, SC_MOD_CHANGEFOLD);
-
- SS(sci, SCI_SETMARGINWIDTHN, 0, 4 + 2 * // line number margin
- SS(sci, SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<long>("9")));
-
- SS(sci, SCI_SETMARGINWIDTHN, 1, 0); // marker margin invisible
-
- // fold margin
- SS(sci, SCI_SETFOLDMARGINCOLOUR, 1, color(0xAA, 0xAA, 0xAA));
- SS(sci, SCI_SETFOLDMARGINHICOLOUR, 1, color(0xAA, 0xAA, 0xAA));
- SS(sci, SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);
- SS(sci, SCI_SETMARGINWIDTHN, 2, 10);
- SS(sci, SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS);
- SS(sci, SCI_SETMARGINSENSITIVEN, 2, 1);
-
- // fold margin markers
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN);
- SS(sci, SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, 0);
- SS(sci, SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, 0);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW);
- SS(sci, SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, 0);
- SS(sci, SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, 0);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
- SS(sci, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
-
- SS(sci, SCI_SETSCROLLWIDTH, 2000);
- SS(sci, SCI_SETHSCROLLBAR, 1);
- SS(sci, SCI_SETENDATLASTLINE, 1);
- SS(sci, SCI_SETCARETSTICKY, 0);
-}
-
-/**
- * Sets the default properties for a Scintilla document.
- * @param sci The Scintilla window containing the document to set default
- * properties for.
- */
-void set_default_buffer_properties(ScintillaObject *sci) {
- sp("fold", "1");
- sp("fold.by.indentation", "1");
-
- SS(sci, SCI_SETLEXER, SCLEX_LPEG);
- SS(sci, SCI_SETLEXERLANGUAGE, 0, reinterpret_cast<long>("container"));
-
- // Tabs and indentation
- SS(sci, SCI_SETTABWIDTH, 2);
- SS(sci, SCI_SETUSETABS, 0);
- SS(sci, SCI_SETINDENT, 2);
- SS(sci, SCI_SETTABINDENTS, 1);
- SS(sci, SCI_SETBACKSPACEUNINDENTS, 1);
- SS(sci, SCI_SETINDENTATIONGUIDES, 1);
-
- SS(sci, SCI_SETEOLMODE, SC_EOL_LF);
- SS(sci, SCI_AUTOCSETCHOOSESINGLE, 1);
-}
-
// Project Manager
/**
diff --git a/src/textadept.h b/src/textadept.h
index 58c7815a..8c858142 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -47,8 +47,6 @@ void set_menubar(GtkWidget *menubar);
void set_statusbar_text(const char *text);
void set_docstatusbar_text(const char *text);
void ce_toggle_focus();
-void set_default_editor_properties(ScintillaObject *sci);
-void set_default_buffer_properties(ScintillaObject *sci);
GtkWidget* pm_create_ui();
void pm_toggle_focus();