Search code examples
sublimetextsbclsublimerepl

Exit Debugger in SublimeREPL with sbcl


How do I exit the debugger in a SublimeREPL repl? I'm not very good at guessing keystrokes, and I didn't see anything in the documentation. As an example invoked by sending the current file to the repl:

debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {1001834103}>:
  Package PPCRE does not exist.

    Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {100001B513}>

Easy to fix, but not while stuck in the debugger! The error is not, I say again, not the problem. What is the problem is that I know of no way to exit the debugger and return to the top level of the repl. Of course, this applies to any error in the repl. For instance, the following code in the file window will suffice:

(count-matches "\\w*" "foo bar baz")

This code submitted to the reply with the keystroke(s) of C-,f will, of course, enter the debugger either because you have not Quickloaded the cl-ppcre library or you have, and it's failing because you forgot to prefix your usage with ppcre: As I said, any error will do, trapping you in a repl state that is useless without a way out.


Solution

  • I installed the sbcl v2.3.3 MacPorts port on my Mac (OSX 10.15.7) for the purposes of this answer.

    First, I created a file test.lisp with the contents:

    (count-matches "\\w*" "foo bar baz")
    

    as suggested in the question. Next, I started a REPL by selecting Tools → SublimeREPL → Common Lisp → SBCL. This appeared in a new tab:

    This is SBCL 2.3.3, an implementation of ANSI Common Lisp.
    More information about SBCL is available at <http://www.sbcl.org/>.
    
    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.
    * 
    

    Switching back to test.lisp, I selected Tools → SublimeREPL → Eval in REPL → File and got this:

    * (count-matches "\\w*" "foo bar baz")
    
    ; in: COUNT-MATCHES "\\w*"
    ;     (COUNT-MATCHES "\\w*" "foo bar baz")
    ; 
    ; caught STYLE-WARNING:
    ;   undefined function: COMMON-LISP-USER::COUNT-MATCHES
    ; 
    ; compilation unit finished
    ;   Undefined function:
    ;     COUNT-MATCHES
    ;   caught 1 STYLE-WARNING condition
    
    debugger invoked on a UNDEFINED-FUNCTION @52A00904 in thread
    #<THREAD "main thread" RUNNING {10013B0003}>:
      The function COMMON-LISP-USER::COUNT-MATCHES is undefined.
    
    Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
    
    restarts (invokable by number or by possibly-abbreviated name):
      0: [CONTINUE      ] Retry calling COUNT-MATCHES.
      1: [USE-VALUE     ] Call specified function.
      2: [RETURN-VALUE  ] Return specified values.
      3: [RETURN-NOTHING] Return zero values.
      4: [ABORT         ] Exit debugger, returning to top level.
    
    ("undefined function" "\\w*" "foo bar baz")
    0] 
    

    I then typed in 4 and the prompt changed back to * .

    If I started a fresh SBCL REPL and instead chose Tools → SublimeREPL → Transfer to REPL → File, it copied the contents of the file to the * prompt, and I had to hit Enter for it to evaluate. The same debugger message as above came up, and entering 4 successfully brought me back to the * prompt.


    While searching for lisp on Package Control, I came across Slyblime, a port of Sly to Sublime Text 4 (make sure you are using build number 4000 or greater - Sublime Text → About Sublime Text on Mac, Preferences → About Sublime Text on Windows/Linux). Slyblime is built on top of SublimeREPL and adds additional features. I don't know enough about Lisp to make use of it or judge its utility, I just thought I'd mention it here.