diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-04-08 12:28:54 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-04-08 12:28:54 +0200 |
commit | ea2466fe69bd082d379e95e1567f3de0b76de243 (patch) | |
tree | 70f1bdcf7d402f2ae013caebf5f4cef5f6c2baed /context/data/textadept/context/modules | |
parent | e32f57c9c5968f0c09130f6e24e28a96d6e1393d (diff) | |
download | context-ea2466fe69bd082d379e95e1567f3de0b76de243.tar.gz |
2017-04-08 12:15:00
Diffstat (limited to 'context/data/textadept/context/modules')
4 files changed, 639 insertions, 0 deletions
diff --git a/context/data/textadept/context/modules/textadept-context-files.lua b/context/data/textadept/context/modules/textadept-context-files.lua new file mode 100644 index 000000000..81db92060 --- /dev/null +++ b/context/data/textadept/context/modules/textadept-context-files.lua @@ -0,0 +1,119 @@ +local info = { + version = 1.002, + comment = "file handler for textadept for context/metafun", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +local lexer = require("scite-context-lexer") +local context = lexer.context + +local char, format = string.char, string.format + +-- What is _CHARSET doing ... I don't want any messing with conversion at all. Scite is +-- more clever with e.g. pdf. How can I show non ascii as escapes. + +io.encodings = { + "UTF-8", + "ASCII", + "UTF-16", +} + +-- We need this for for instance pdf files (faster too): + +local sevenbitascii = { } +for i=127,255 do + sevenbitascii[char(i)] = format("0x%02X",i) +end + +local function setsevenbitascii(buffer) + -- we cannot directly assign sevenbitascii to buffer + local representation = buffer.representation + for k, v in next, sevenbitascii do + representation[k] = v + end +end + +-- Here we rebind keys. For this we need to load the alternative runner framework. I will +-- probably change the menu. + +local oldrunner = textadept.run +local runner = require("textadept-context-runner") + +local function userunner(runner) + keys [OSX and 'mr' or 'cr' ] = runner.process or runner.run + keys [OSX and 'mR' or (GUI and 'cR' or 'cmr')] = runner.check or runner.compile + keys [OSX and 'mB' or (GUI and 'cB' or 'cmb')] = runner.preview or runner.build + keys [OSX and 'mX' or (GUI and 'cX' or 'cmx')] = runner.quit or runner.stop + textadept.menu.menubar [_L['_Tools']] [_L['_Run']] [2] = runner.process or runner.run + textadept.menu.menubar [_L['_Tools']] [_L['_Compile']] [2] = runner.check or runner.compile + textadept.menu.menubar [_L['_Tools']] [_L['Buil_d']] [2] = runner.preview or runner.build + textadept.menu.menubar [_L['_Tools']] [_L['S_top']] [2] = runner.quit or runner.stop + return poprunner +end + +userunner(runner) + +-- We have a different way to set up files and runners. Less distributed and morein the way we +-- do things in context. + +local dummyrunner = function() end +local extensions = textadept.file_types.extensions +local specifications = runner.specifications +local setters = { } +local defaults = { + check = dummyrunner, + process = dummyrunner, + preview = dummyrunner, +} + +setmetatable(specifications, { __index = defaults }) + +function context.install(specification) + local suffixes = specification.suffixes + if suffixes then + local lexer = specification.lexer + local setter = specification.setter + local encoding = specification.encoding + for i=1,#suffixes do + local suffix = suffixes[i] + if lexer and extensions then + extensions[suffix] = lexer + end + specifications[suffix] = specification + if lexer then + setters[lexer] = function() + if encoding == "7-BIT-ASCII" then + setsevenbitascii(buffer) + end + if setter then + setter(lexer) + end + end + end + end + end +end + +local function synchronize(lexer) + local setter = lexer and setters[lexer] + if setter then + local action = context.synchronize + if action then + action() + end + userunner(runner) + setter(lexer) + else + userunner(oldrunner) + end +end + +events.connect(events.FILE_OPENED,function(filename) + synchronize(buffer.get_lexer(buffer)) +end) + +events.connect(events.LEXER_LOADED,function(lexer) + synchronize(lexer) +end) diff --git a/context/data/textadept/context/modules/textadept-context-runner.lua b/context/data/textadept/context/modules/textadept-context-runner.lua new file mode 100644 index 000000000..f06786b00 --- /dev/null +++ b/context/data/textadept/context/modules/textadept-context-runner.lua @@ -0,0 +1,254 @@ +local info = { + version = 1.002, + comment = "prototype textadept runner for context/metafun", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +-- This is an adapted version of the run code by mitchell.att.foicica.corunner. The main +-- reason I started patching is that long lines got broken in the middle so we needed +-- to have a more clever line splitter that saves half of a line for later. Then I +-- decided to come up with a few more variants so in the end ... it's just too tempting +-- make something that exactly suits out needs. In fact, maybe I'll do that some day: +-- take core textadept and make a dedicated variant for the kind of processing that we +-- do and make it suitable for document authors (the manual says that is doable). In that +-- case I can also use a lot of already written helpers. +-- +-- The error scanner is not needed. If I need one, it will be using a lexers applied +-- afterwards because working on half lines is not going to work out well anyway. +-- +-- Here I removed iconv calls as in context we use utf (less hassle with fonts too). One +-- can always use the original approach. +-- +-- The events seems to have hard coded names, Also, the name of the message buffer cannot +-- be changes because otherwise we get a message when the session is restored. I don't +-- care about locales. +-- +-- Somehow th eprocess hangs when I refresh the pdf viewer, this doesn't happen in scite so +-- the underlying code is for the moment less reliant. + +local match, gsub, find, format = string.match, string.gsub, string.find, string.format +local assert, type = assert, type + +local original = textadept.run +local runner = { } + +runner.MARK_WARNING = original.MARK_WARNING +runner.MARK_ERROR = original.MARK_ERROR + +local specifications = { } +runner.specifications = specifications + +events.CHECK_OUTPUT = 'build_output' -- 'check_output' +events.PROCESS_OUTPUT = 'run_output' -- 'process_output' +events.PREVIEW_OUTPUT = 'compile_output' -- 'preview_output' + +local eventtags = { + check = events.CHECK_OUTPUT, + process = events.PROCESS_OUTPUT, + preview = events.PREVIEW_OUTPUT, +} + +local OUTPUT_BUFFER = '[Message Buffer]' -- CONSOLE + +local currentprocess = nil +local xbuffer = nil + +local function find_buffer(buffer_type) + for i=1,#_BUFFERS do + local buffer = _BUFFERS[i] + if buffer._type == buffer_type then + return buffer + end + end +end + +local function print_output(str) + local print_buffer = find_buffer(OUTPUT_BUFFER) + if not print_buffer then + if not ui.tabs then + view:split() + end + print_buffer = buffer.new() + print_buffer._type = OUTPUT_BUFFER + events.emit(events.FILE_OPENED) + else + for i=1,#_VIEWS do + local view = _VIEWS[i] + if view.buffer._type == OUTPUT_BUFFER then + ui.goto_view(view) + break + end + end + if view.buffer._type ~= OUTPUT_BUFFER then + view:goto_buffer(print_buffer) + end + end + print_buffer:append_text(str) + print_buffer:goto_pos(buffer.length) + print_buffer:set_save_point() + return true -- quits +end + +local function clear_output() + xbuffer = buffer + local print_buffer = find_buffer(OUTPUT_BUFFER) + if print_buffer then + print_buffer:clear_all() + end +end + +local function is_output(buffer) + return buffer._type == OUTPUT_BUFFER +end + +local function process(buffer,filename,action) + local event = eventtags[action] + if not event then + return + end + if not filename then + filename = buffer.filename + end + if filename == buffer.filename then + buffer:annotation_clear_all() -- needed ? + io.save_file() + end + local suffix = match(filename,'[^/\\.]+$') + local specification = specifications[suffix] + if not specification then + return + end + local command = specification[action] + if type(command) == "string" then + -- we're ok, some day also more specific table support, e.g. when we want + -- to hook in a log lexer + else + return + end + clear_output() + local pathpart = '' + local basename = filename + if find(filename,'[/\\]') then + pathpart, basename = match(filename,'^(.+[/\\])([^/\\]+)$') + end + -- beter strip one from the end + local nameonly = match(basename,'^(.+)%.') + -- more in sync which what we normally do + command = gsub(command,'%%(.-)%%', { + filename = filename, + pathname = dirname, + dirname = dirname, + pathpart = dirname, + basename = basename, + nameonly = nameonly, + suffix = suffix, + }) + -- for fun i'll add a ansi escape sequence lexer some day + local function emit_output(output) + events.emit(event,output) + end + local function exit_output(status) + events.emit(event,format("\n\n> exit: %s, press esc to return to source\n",status)) + end + events.emit(event,format("> command: %s\n",command)) + currentprocess = assert(spawn(command, pathpart, emit_output, emit_output, exit_output)) +end + +function runner.check(filename) + process(buffer,filename,"check") +end + +function runner.process(filename) + process(buffer,filename,"process") +end + +function runner.preview(filename) + process(buffer,filename,"preview") +end + +function runner.quit() + if currentprocess then + assert(currentprocess:kill()) + end +end + +local function char_added(code) + if code == 10 and currentprocess and currentprocess:status() == 'running' and buffer._type == OUTPUT_BUFFER then + local line_num = buffer:line_from_position(buffer.current_pos) - 1 + currentprocess:write((buffer:get_line(line_num))) + end + return true -- quits +end + +function runner.goto_error(line, next) + -- see original code for how to do it +end + +local function key_press(code) + if xbuffer and keys.KEYSYMS[code] == 'esc' then + view:goto_buffer(xbuffer) + return true + end +end + +local function double_click() + if xbuffer and is_output(buffer) then + view:goto_buffer(xbuffer) + return true + end +end + +-- Tricky: we can't reset an event (because we need to know the function which is +-- local. So, a first solution injected a false into the table which will trigger +-- a break and then I found out that returning true has the same effect. + +events.connect(events.COMPILE_OUTPUT, print_output, 1) +events.connect(events.RUN_OUTPUT, print_output, 1) +events.connect(events.BUILD_OUTPUT, print_output, 1) +events.connect(events.CHAR_ADDED, char_added, 1) +events.connect(events.KEYPRESS, key_press, 1) +events.connect(events.DOUBLE_CLICK, double_click, 1) + +return runner + +-- The ui.print function is a bit heavy as each flush will parse the whole list of buffers. +-- Also it does some tab magic that we don't need or want. There is the original ui.print for +-- that. FWIW, speed is not an issue. Some optimizations: + +-- function _print(buffer_type,one,two,...) +-- ... +-- print_buffer:append_text(one) +-- if two then +-- print_buffer:append_text(two) +-- for i=1, select('#', ...) do +-- print_buffer:append_text((select(i,...))) +-- end +-- end +-- print_buffer:append_text('\n') +-- ... +-- end +-- +-- And a better splitter: +-- ... +-- local rest +-- local function emit_output(output) +-- for line, lineend in output:gmatch('([^\r\n]+)([\r\n]?)') do +-- if rest then +-- line = rest .. line +-- rest = nil +-- end +-- if lineend and lineend ~= "" then +-- events.emit(event, line, ext_or_lexer) +-- else +-- rest = line +-- end +-- end +-- end +-- ... +-- if rest then +-- events.emit(event,rest,ext_or_lexer) +-- end +-- events.emit(event, '> exit status: '..status) +-- ... diff --git a/context/data/textadept/context/modules/textadept-context-settings.lua b/context/data/textadept/context/modules/textadept-context-settings.lua new file mode 100644 index 000000000..53b5c896f --- /dev/null +++ b/context/data/textadept/context/modules/textadept-context-settings.lua @@ -0,0 +1,131 @@ +local info = { + version = 1.002, + comment = "presets for textadept for context/metafun", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +local lexer = require("scite-context-lexer") +local context = lexer.context + +if context then + + function context.synchronize() + local buffer = buffer + local property = lexer.property + local property_int = lexer.property_int + + buffer:set_fold_margin_colour (true, property_int["color.light"]) + buffer:set_fold_margin_hi_colour (true, property_int["color.white"]) + buffer:set_sel_fore (false, property_int["color.dark"]) + buffer:set_sel_back (true, property_int["color.selection"]) + + local MARK_BOOKMARK = textadept.bookmarks.MARK_BOOKMARK + local MARK_WARNING = textadept.run.MARK_WARNING + local MARK_ERROR = textadept.run.MARK_ERROR + + -- buffer.marker_fore[MARK_BOOKMARK] = property_int["color.white"] + buffer.marker_back[MARK_BOOKMARK] = property_int["color.blue"] + -- buffer.marker_fore[MARK_WARNING] = property_int["color.white"] + buffer.marker_back[MARK_WARNING] = property_int["color.orange"] + -- buffer.marker_fore[MARK_ERROR] = property_int["color.white"] + buffer.marker_back[MARK_ERROR] = property_int["color.red"] + for i = 25, 31 do + buffer.marker_fore[i] = property_int["color.white"] + buffer.marker_back[i] = property_int["color.grey"] + buffer.marker_back_selected[i] = property_int["color.dark"] + end + + local INDIC_BRACEMATCH = textadept.editing .INDIC_BRACEMATCH + local INDIC_HIGHLIGHT = textadept.editing .INDIC_HIGHLIGHT + local INDIC_PLACEHOLDER = textadept.snippets.INDIC_PLACEHOLDER + local INDIC_FIND = ui.find.INDIC_FIND + + buffer.indic_fore [INDIC_FIND] = property_int["color.gray"] + buffer.indic_alpha[INDIC_FIND] = 255 + buffer.indic_fore [INDIC_BRACEMATCH] = property_int["color.orange"] + buffer.indic_style[INDIC_BRACEMATCH] = buffer.INDIC_BOX -- hard to see (I need to check scite) + buffer.indic_fore [INDIC_HIGHLIGHT] = property_int["color.gray"] + buffer.indic_alpha[INDIC_HIGHLIGHT] = 255 + buffer.indic_fore [INDIC_PLACEHOLDER] = property_int["color.gray"] + + -- buffer:brace_highlight_indicator(false, INDIC_BRACEMATCH) + + -- buffer.call_tip_fore_hlt = property_int["color.blue"] + buffer.edge_colour = property_int["color.grey"] + + buffer.tab_width = 4 + buffer.use_tabs = false + buffer.indent = 4 + buffer.tab_indents = true + buffer.back_space_un_indents = true + buffer.indentation_guides = not CURSES and buffer.IV_LOOKBOTH or buffer.IV_NONE + + buffer.sel_eol_filled = true + -- buffer.sel_alpha = + buffer.multiple_selection = true + buffer.additional_selection_typing = true + -- buffer.multi_paste = buffer.MULTIPASTE_EACH + -- buffer.virtual_space_options = buffer.VS_RECTANGULARSELECTION + buffer.VS_USERACCESSIBLE + buffer.rectangular_selection_modifier = buffer.MOD_ALT + buffer.mouse_selection_rectangular_switch = true + + -- buffer.additional_sel_alpha = + -- buffer.additional_sel_fore = + -- buffer.additional_sel_back = + + -- how to turn of the annoying background behind the current line ... + + -- buffer.additional_caret_fore = + -- buffer.additional_carets_blink = false + -- buffer.additional_carets_visible = false + buffer.caret_line_visible = false -- not CURSES and buffer ~= ui.command_entry + buffer.caret_line_visible_always = false + -- buffer.caret_period = 0 + -- buffer.caret_style = buffer.CARETSTYLE_BLOCK + buffer.caret_width = 10 + buffer.caret_sticky = buffer.CARETSTICKY_ON + buffer.caret_fore = property_int["color.black"] + buffer.caret_line_back = property_int["color.light"] + -- buffer.caret_line_back_alpha = + + buffer.view_ws = buffer.WS_INVISIBLE + buffer.view_eol = false + + buffer.annotation_visible = buffer.ANNOTATION_BOXED + + -- local NUMBER_MARGIN = 0 + -- local MARKER_MARGIN = 1 + -- local FOLD_MARGIN = 2 -- there are more + -- + -- buffer.margin_type_n [NUMBER_MARGIN] = buffer.MARGIN_NUMBER + -- buffer.margin_width_n[NUMBER_MARGIN] = (CURSES and 0 or 4) + -- + 4 * buffer:text_width(buffer.STYLE_LINENUMBER,'9') -- magic + -- buffer.margin_width_n[MARKER_MARGIN] = CURSES and 1 or 4 + -- buffer.margin_width_n[FOLD_MARGIN] = CURSES and 1 or 12 + -- + -- buffer.margin_mask_n[FOLD_MARGIN] = buffer.MASK_FOLDERS + + buffer.wrap_mode = buffer.WRAP_NONE + + buffer.margin_back_n[0] = property_int["color.linenumber"] -- doesn't work + + buffer.property = { + -- ["style.linenumber"] = property["style.linenumber"], -- somehow it fails + } + + buffer.property_int = { + -- nothing + } + + -- keys [OSX and 'mr' or 'cr' ] = textadept.run.run + -- keys [OSX and 'mR' or (GUI and 'cR' or 'cmr')] = textadept.run.compile + -- keys [OSX and 'mB' or (GUI and 'cB' or 'cmb')] = textadept.run.build + -- keys [OSX and 'mX' or (GUI and 'cX' or 'cmx')] = textadept.run.stop + + end + + context.synchronize() + +end diff --git a/context/data/textadept/context/modules/textadept-context-types.lua b/context/data/textadept/context/modules/textadept-context-types.lua new file mode 100644 index 000000000..c638a49ee --- /dev/null +++ b/context/data/textadept/context/modules/textadept-context-types.lua @@ -0,0 +1,135 @@ +local info = { + version = 1.002, + comment = "filetypes for textadept for context/metafun", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +-- todo: add the same ones as we have in scite + +local lexer = require("scite-context-lexer") +local context = lexer.context +local install = context.install + +install { + lexer = "scite-context-lexer-tex", + suffixes = { + "tex", + "mkii", + "mkiv", "mkvi", "mkix", "mkxi" + }, + check = [[mtxrun --autogenerate --script check "%basename%"]], + process = [[mtxrun --autogenerate --script context "%basename%"]], -- --autopdf takes long to stop (weird, not in scite) + preview = [[]], + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-xml", + suffixes = { + "xml", "xsl", "xsd", "fo", "dtd", "xslt", + "lmx", "exa", "ctx", "export", + "rlb", "rlg", "rlv", "rng", + "xfdf", + "htm", "html", "xhtml", + "svg", + "xul" + }, + check = [[tidy -quiet -utf8 -xml -errors "%basename%"]], + process = [[mtxrun --autogenerate --script context "%basename%"]], -- --autopdf takes long to stop (weird, not in scite) + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-mps", + suffixes = { + "mp", "mpx" + }, + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-lua", + suffixes = { + "lua", "luc", + "cld", "tuc", "luj", "lum", "tma", "lfg", "luv", "lui" + }, + check = [[mtxrun --autogenerate --script "%basename%"]], + process = [[mtxrun --autogenerate --script "%basename%"]], + preview = [[mtxrun --autogenerate --script "%basename%"]], + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-txt", + suffixes = { + "txt" + }, + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-pdf", + suffixes = { + "pdf" + }, + encoding = "7-BIT-ASCII", + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-web", + suffixes = { + "w", + "ww" + }, + setter = function(lexer) + -- whatever + end, +} + +install { + lexer = "scite-context-lexer-cpp", + suffixes = { + "h", "c", + "hh", "cc", + "hpp", "cpp", + "hxx", "cxx" + }, + setter = function(lexer) + -- whatever + end, +} + +install { + "scite-context-lexer-bibtex", + suffixes = { + "bib" + }, + setter = function(lexer) + -- whatever + end, +} + +install { + "scite-context-lexer-sql", + suffixes = { + "sql" + }, + setter = function(lexer) + -- whatever + end, +} |