Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling and documentation suggestions #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The configuration file is looked for in sequence at the following locations:

The first file found, if any, is loaded.

The *OUT* buffer is an ephemeral buffer that can be used as a scratchpad, as a sort of extended clipboard, and also to receive the output of programs launched by the editor from the current buffer. In addition, any errors ple encounters while executing key-bindings are reported in the *OUT* buffer.

A sample `ple_init.lua` file is provided. It defines an editor command to execute the current line as a shell command and insert the result in the current buffer at the cursor.

--
Expand All @@ -74,19 +76,19 @@ Cursor movement
^A, ^E go to beginning, end of line
^B, ^F go backward, forward
^N, ^P go to next line, previous line
^K, ^J go to next word, previous word
^K, ^J go to next word, previous word
^U, ^V page up, page down
^X< go to beginning of buffer
^X> go to end of buffer
^S forward search (plain text, case sensitive)
^R search again (string previously entered with ^S)
^X^G prompt for a line number, go there

Edition
^D, Delete delete character at cursor
^H, bcksp delete previous character
^space, ^@ mark (set beginning of selection)
^W wipe (cut selection or cut line if no selection)
^W wipe (cut selection or cut line if no selection)
^Y yank (paste)
^X5 replace
^X7 replace again (with same strings)
Expand All @@ -95,17 +97,19 @@ Files, buffers
^X^F prompt for a filename, read the file in a new buffer
^X^W prompt for a filename, write the current buffer
^X^S save the current buffer
^X^B create a new, empty buffer
^X^B switch to a named buffer or create a new buffer
^X^N switch to the next buffer
^X^P switch to the previous buffer
^X^I display a list of buffers

Misc.
^X^C exit the editor
^G abort the current command
^Z undo
^X^Z redo
^L redisplay the screen (useful if the screen was
garbled or its dimensions changed)
^Z undo
^X^Z redo
^O toggle between the current buffer and *OUT*
^L redisplay the screen (useful if the screen was
garbled or its dimensions changed)
F1, ^X^H this help text

```
Expand Down
34 changes: 16 additions & 18 deletions ple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,11 @@ function e.prevbuffer()
core.fullredisplay()
end--nextbuffer

function e.outbuffer()
function e.outbuffer(notoggle)
-- switch to *OUT* buffer.
-- if already in OUT buffer, switch back to previous buffer
local b = core.buf
if b.filename == "*OUT*" then return e.prevbuffer() end
if b.filename == "*OUT*" and not notoggle then return e.prevbuffer() end
return e.newbuffer("*OUT*")
end --outbuffer

Expand Down Expand Up @@ -1008,8 +1008,7 @@ Misc.
^G abort the current command
^Z undo
^X^Z redo
^O switch back and forth between the current buffer
and the *OUT* buffer
^O toggle between the current buffer and *OUT*
^L redisplay the screen (useful if the screen was
garbled or its dimensions changed)
F1, ^X^H this help text
Expand Down Expand Up @@ -1101,13 +1100,14 @@ local function editor_loadinitfile()
return nil
end--editor_loadinitfile

function editor.error_handler(r)
e.outbuffer()
e.settext(
"\nAN ERROR HAS OCCURRED! \n\n"
local function default_error_handler(r)
e.outbuffer(true)
e.goeot()
e.insert(
"\n" .. string.rep("_", 72) .. "\n\n"
.. "AN ERROR HAS OCCURRED! \n\n"
.. "It is recommended to exit the editor\n"
.. "(you may try to save your buffers first)\n"
.. string.rep("_", 72) .. "\n"
.. "(you may try to save your buffers first)\n\n"
.. r
)
end
Expand All @@ -1128,15 +1128,13 @@ local function editor_loop(ll, fname)
local act = editor.bindings[k]
if act then
msg(kname)
if editor.error_handler then
ok, r = xpcall(act, debug.traceback)
if ok then
core.lastresult = r
else
editor.error_handler(r)
end
ok, r = xpcall(act, debug.traceback)
if ok then
core.lastresult = r
elseif editor.error_handler then
editor.error_handler(r)
else
core.lastresult = act()
default_error_handler(r)
end
elseif (k >= 32) and (k > 0xffff or k < 0xffea) then
core.lastresult = e.insch(k)
Expand Down