diff options
-rw-r--r-- | core/gui.lua | 4 | ||||
-rw-r--r-- | core/locale.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.de.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.es.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.fr.conf | 5 | ||||
-rw-r--r-- | core/locales/locale.ru.conf | 3 | ||||
-rw-r--r-- | doc/07_Modules.md | 14 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 12 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 2 | ||||
-rw-r--r-- | modules/textadept/run.lua | 91 |
10 files changed, 94 insertions, 46 deletions
diff --git a/core/gui.lua b/core/gui.lua index a69ccbd6..3687aae0 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -54,7 +54,6 @@ end -- displayed before being printed to. -- @param buffer_type String type of message buffer. -- @param ... Message strings. --- @usage gui._print(_L['[Error Buffer]'], error_message) -- @usage gui._print(_L['[Message Buffer]'], message) -- @name _print function gui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end @@ -438,8 +437,7 @@ events_connect(events.QUIT, function() '--no-newline') == '2' end) -events_connect(events.ERROR, - function(...) gui._print(_L['[Error Buffer]'], ...) end) +events_connect(events.ERROR, gui.print) --[[ The tables below were defined in C. diff --git a/core/locale.conf b/core/locale.conf index 9a96a8df..0b3486e7 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -53,7 +53,6 @@ Col: = Col: Quit without saving? = Quit without saving? The following buffers are unsaved: = The following buffers are unsaved: Quit _without saving = Quit _without saving -[Error Buffer] = [Error Buffer] % core/keys.lua Keychain: = Keychain: @@ -180,6 +179,8 @@ Command _Entry = Command _Entry Select Co_mmand = Select Co_mmand _Run = _Run _Compile = _Compile +_Next Error = _Next Error +_Previous Error = _Previous Error _Adeptsense = _Adeptsense _Complete Symbol = _Complete Symbol Show _Documentation = Show _Documentation diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index d904b357..2fd53632 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -54,7 +54,6 @@ Col: = Spalte: Quit without saving? = Beenden ohne zu speichern? The following buffers are unsaved: = Die folgenden Buffer sind ungespeichert: Quit _without saving = Beenden ohne zu speichern -[Error Buffer] = [Fehler-Buffer] % core/keys.lua Keychain: = Keychain: @@ -170,6 +169,8 @@ Command _Entry = Befehlseingabe Select Co_mmand = Befehl auswählen _Run = Ausführen _Compile = Kompilieren +_Next Error = Nächstes Fehler +_Previous Error = Voriges Fehler _Adeptsense = _Adeptsense _Complete Symbol = Symbol vervollständigen Show _Documentation = Dokumentation anzeigen diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index c78c90c6..75cebba6 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -54,7 +54,6 @@ Col: = Col: Quit without saving? = ¿Salir sin guardar? The following buffers are unsaved: = Los siguientes buffers no han sido guardados: Quit _without saving = Salir _sin guardar -[Error Buffer] = [Buffer de errores] % core/keys.lua Keychain: = Combinación de teclas: @@ -181,6 +180,8 @@ Command _Entry = _Línea de comandos Select Co_mmand = _Seleccionar comandos _Run = _Ejecutar _Compile = _Compilar +_Next Error = Error sig_uiente +_Previous Error = Error _anterior _Adeptsense = _Adeptsense _Complete Symbol = _Completar símbolo Show _Documentation = _Mostrar documentación diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index 162ef267..42d9f5b1 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -54,7 +54,6 @@ Col: = Col: Quit without saving? = Quitter sans enregistrer? The following buffers are unsaved: = Les buffers suivants ne sont pas sauvegardés: Quit _without saving = Quitter _sans enregistrer -[Error Buffer] = [Buffer des erreurs] % core/keys.lua Keychain: = Keychain: @@ -181,6 +180,8 @@ Command _Entry = Ligne de _commande Select Co_mmand = Sélectionner co_mmande _Run = _Lancer _Compile = _Compiler +_Next Error = Erreur _suivant +_Previous Error = Erreur _précédent _Adeptsense = _Adeptsense _Complete Symbol = _Compléter symbole Show _Documentation = Ouvrir _documentation @@ -194,7 +195,7 @@ Snap_open = Snap_open Snapopen _User Home = Snapopen dossier _utilisateur Snapopen _Textadept Home = Snapopen dossier _Textadept Snapopen _Current Directory = Snapopen dossier _courant -_Snippets = _Snippets +_Snippets = S_nippets _Insert Snippet... = _Insérer snippet... _Expand Snippet/Next Placeholder = _Étendre snippet/Marque snippet suivante _Previous Snippet Placeholder = Marque snippet _précédente diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index 682adbea..9880a32e 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -54,7 +54,6 @@ Col: = Столбец: Quit without saving? = Выйти без сохранения? The following buffers are unsaved: = Данные буферы не сохранены: Quit _without saving = Выйти _без сохранения -[Error Buffer] = [Буфер ошибок] % core/keys.lua Keychain: = Комбинации клавиш: @@ -170,6 +169,8 @@ Command _Entry = Командная _строка Select Co_mmand = Выбрать _команду _Run = _Запустить _Compile = _Скомпилировать +_Next Error = Следующая Ошибка +_Previous Error = Предыдущая Ошибка _Adeptsense = _Adeptsense _Complete Symbol = _Завершить символ Show _Documentation = Показать _документацию diff --git a/doc/07_Modules.md b/doc/07_Modules.md index 93347868..81fc55df 100644 --- a/doc/07_Modules.md +++ b/doc/07_Modules.md @@ -32,12 +32,14 @@ perhaps a custom context menu. These features are discussed below. Most language-specific modules have a command that compiles and/or runs the code in the current file. Pressing `Ctrl+Shift+R` (`⌘⇧R` on Mac OSX | `M-^R` in curses) executes the command for compiling code and `Ctrl+R` (`⌘R` | `^R`) -executes the command for running code. Double-clicking on any error messages -will jump to where the errors occurred. Note: In order for these features to -work, the language you are working with must have its compile and run commands -and error format defined. If the language-specific module does not exist or does -not [define][] commands or an error format, it can be done [manually][] in your -[user-init file][]. +executes the command for running code. Any recognized errors in the output are +marked. Pressing `Ctrl+Alt+E` (`^⌘E` | `M-X`) attempts to jump to the source of +the next recognized error and `Ctrl+Alt+Shift+E` (`^⌘⇧E` | `M-S-X`) attempts to +jump to the previous one. Double-clicking on errors will also jump to their +sources. Note: In order for these features to work, the language you are working +with must have its compile and run commands and error format defined. If the +language-specific module does not exist or does not [define][] commands or an +error format, it can be done [manually][] in your [user-init file][]. [define]: api/_M.html#Compile.and.Run [manually]: http://foicica.com/wiki/run-supplemental diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index c5f4cec1..ed2ae3d7 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -83,6 +83,8 @@ local M = {} -- Ctrl+Shift+E |⌘⇧E |M-S-C |Select command -- Ctrl+R |⌘R |^R |Run -- Ctrl+Shift+R |⌘⇧R |M-^R |Compile +-- Ctrl+Alt+E |^⌘E |M-X |Next Error +-- Ctrl+Alt+Shift+E|^⌘⇧E |M-S-X |Previous Error -- Ctrl+Space |⌥⎋ |^Space |Complete symbol -- Ctrl+H |^H |M-H<br/>M-S-H|Show documentation -- Tab |⇥ |Tab |Expand snippet or next placeholder @@ -312,7 +314,7 @@ local utils = M.utils -- Unassigned keys (~ denotes keys reserved by the operating system): -- c: A B C H p Q ~ V X Y ) ] } -- a: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ_ ) ] } *+-/=\n\s --- ca: aAbBcCdDeE F jJkKlLmM N PqQ t xXy zZ_"'()[]{}<>* / \s +-- ca: aAbBcCdD F jJkKlLmM N PqQ t xXy zZ_"'()[]{}<>* / \s -- -- CTRL = 'c' (Control ^) -- ALT = 'a' (Alt) @@ -327,7 +329,7 @@ local utils = M.utils -- Unassigned keys (~ denotes keys reserved by the operating system): -- m: A B C ~ JkK ~M p ~ t U V XyY ) ] } ~~\n -- c: cC D gG H J K L oO qQ xXyYzZ_ ) ] } * / --- cm: aAbBcC~DeE F ~HiIjJkKlL~MnN pPq~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n +-- cm: aAbBcC~D F ~HiIjJkKlL~MnN pPq~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n -- -- CTRL = 'c' (Control ^) -- ALT = 'a' (Alt/option ⌥) @@ -353,7 +355,7 @@ local utils = M.utils -- Unassigned keys (~ denotes keys reserved by the operating system): -- c: g~~ ~ -- cm: bcd g~~ k ~ pq t v xyz --- m: e J qQ sS u vVw xXyYzZ +-- m: e J qQ sS u vVw yYzZ -- Note: m[befhstv] may be used by Linux/BSD GUI terminals for menu access. -- -- CTRL = 'c' (Control ^) @@ -471,6 +473,10 @@ keys[not OSX and (not CURSES and 'cE' or 'mC') or 'mE'] = utils.select_command keys[not OSX and 'cr' or 'mr'] = m_textadept.run.run keys[not OSX and (not CURSES and 'cR' or 'cmr') or 'mR'] = m_textadept.run.compile +keys[not OSX and (not CURSES and 'cae' or 'mx') + or 'cme'] = {m_textadept.run.goto_error, false, true} +keys[not OSX and (not CURSES and 'caE' or 'mX') + or 'cmE'] = {m_textadept.run.goto_error, false, false} -- Adeptsense. keys[not OSX and ((not CURSES or WIN32) and 'c ' or 'c@') or 'aesc'] = m_textadept.adeptsense.complete diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 2c9c3244..a727b1e0 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -120,6 +120,8 @@ local menubar = { SEPARATOR, {_L['_Run'], m_textadept.run.run}, {_L['_Compile'], m_textadept.run.compile}, + {_L['_Next Error'], {m_textadept.run.goto_error, false, true}}, + {_L['_Previous Error'], {m_textadept.run.goto_error, false, false}}, SEPARATOR, { title = _L['_Adeptsense'], {_L['_Complete Symbol'], m_textadept.adeptsense.complete}, diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 38eb6301..6f220385 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -10,9 +10,13 @@ local M = {} -- extension. -- -- [language-specific modules]: _M.html#Compile.and.Run +-- @field MARK_ERROR_BACK (number) +-- The background color, in "0xBBGGRR" format, used for a line containing a +-- recognized run or compile error. -- @field cwd (string, Read-only) -- The working directory for the most recently executed compile or run -- command. +-- It is used for error messages with relative file paths. -- @field _G.events.COMPILE_OUTPUT (string) -- Called after executing a language's compile command. -- By default, compiler output is printed to the message buffer. To override @@ -31,6 +35,8 @@ local M = {} -- * `output`: The string output from the command. module('_M.textadept.run')]] +M.MARK_ERROR_BACK = not CURSES and 0x8080CC or 0x0000FF + -- Events. local events, events_connect, events_emit = events, events.connect, events.emit events.COMPILE_OUTPUT, events.RUN_OUTPUT = 'compile_output', 'run_output' @@ -93,23 +99,17 @@ local function get_error_details(message) return nil end +local MARK_ERROR = _SCINTILLA.next_marker_number() + -- Prints the output from a run or compile command. --- If the output is an error message, an annotation is shown in the source file --- if the file is currently open in another view. +-- If the output is a recognized error message, mark it. -- @param lexer The current lexer. -- @param output The output to print. local function print_output(lexer, output) gui.print(output) - local error_details = get_error_details(output) - if not error_details or not error_details.message then return end - for i = 1, #_VIEWS do - local filename = _VIEWS[i].buffer.filename - if filename and filename:find(error_details.filename..'$') then - gui.goto_view(i) - buffer.annotation_text[error_details.line - 1] = error_details.message - buffer.annotation_style[error_details.line - 1] = 8 -- error_details - return - end + if get_error_details(output) then + -- Current position is one line below the error due to gui.print()'s '\n'. + buffer:marker_add(buffer.line_count - 2, MARK_ERROR) end end @@ -191,30 +191,65 @@ events_connect(events.RUN_OUTPUT, print_output) -- @name error_detail M.error_detail = {} +-- Returns whether or not the given buffer is a message buffer. +local function is_msg_buf(buf) return buf._type == _L['[Message Buffer]'] end --- --- Goes to line number *line_num* in the file an error occurred at based on the --- error message at position *pos* in the buffer and displays an annotation with --- the error message. --- This is typically called by an event handler for when the user double-clicks --- on an error message. --- @param pos The position of the caret in the buffer. --- @param line_num The line number the caret is on with the error message. +-- Goes to the source of the recognized compile/run error on line number *line* +-- in the message buffer, or if `nil`, the next or previous recognized error +-- depending on boolean *next*. +-- Displays an annotation with the error message, if available. +-- @param line The line number in the message buffer that contains the +-- compile/run error to go to. +-- @param next Optional flag indicating whether to go to the next recognized +-- error or the previous one. Only applicable when *line* is `nil` or `false`. -- @see error_detail -function goto_error(pos, line_num) - if buffer._type ~= _L['[Message Buffer]'] and - buffer._type ~= _L['[Error Buffer]'] then - return +-- @see cwd +-- @name goto_error +function M.goto_error(line, next) + local cur_buf, msg_view, msg_buf = _BUFFERS[buffer], nil, nil + for i = 1, #_VIEWS do + if is_msg_buf(_VIEWS[i].buffer) then msg_view = i break end + end + for i = 1, #_BUFFERS do + if is_msg_buf(_BUFFERS[i]) then msg_buf = i break end end - local error_details = get_error_details(buffer:get_line(line_num)) - if not error_details then return end - gui.goto_file(M.cwd..error_details.filename, true, preferred_view, true) - local line, message = error_details.line, error_details.message + if not msg_view and not msg_buf then return end + if msg_view then gui.goto_view(msg_view) else view:goto_buffer(msg_buf) end + + -- If no line was given, find the next error marker. + if not line and next ~= nil then + local buffer = buffer + local f = buffer['marker_'..(next and 'next' or 'previous')] + line = f(buffer, buffer:line_from_position(buffer.current_pos) + + (next and 1 or -1), 2^MARK_ERROR) + if line == -1 then + line = f(buffer, next and 0 or buffer.line_count, 2^MARK_ERROR) + if line == -1 then if CURSES then view:goto_buffer(cur_buf) end return end + end + end + buffer:goto_line(line) + + -- Goto the error and show an annotation. + local err = get_error_details(buffer:get_line(line)) + if not err then if CURSES then view:goto_buffer(cur_buf) end return end + _M.textadept.editing.select_line() + gui.goto_file(M.cwd..err.filename, true, preferred_view, true) + local line, message = err.line, err.message buffer:goto_line(line - 1) if message then buffer.annotation_text[line - 1] = message buffer.annotation_style[line - 1] = 8 -- error end end -events_connect(events.DOUBLE_CLICK, goto_error) +events_connect(events.DOUBLE_CLICK, function(pos, line) M.goto_error(line) end) + +local CURSES_MARK = _SCINTILLA.constants.SC_MARK_CHARACTER + string.byte(' ') +-- Sets view properties for error markers. +local function set_error_properties() + if CURSES then buffer:marker_define(MARK_ERROR, CURSES_MARK) end + buffer.marker_back[MARK_ERROR] = M.MARK_ERROR_BACK +end +if buffer then set_error_properties() end +events_connect(events.VIEW_NEW, set_error_properties) return M |