aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/textadept/keys.lua12
-rw-r--r--modules/textadept/menu.lua2
-rw-r--r--modules/textadept/run.lua91
3 files changed, 74 insertions, 31 deletions
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