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

Proposal to not quit when we are working inside Slime #3

Open
vindarel opened this issue Jun 1, 2021 · 6 comments
Open

Proposal to not quit when we are working inside Slime #3

vindarel opened this issue Jun 1, 2021 · 6 comments

Comments

@vindarel
Copy link

vindarel commented Jun 1, 2021

Hello there,

I tried defmain, and I tried to call the main function from Emacs & Slime. It should be possible, since what defmain does is creating a defun called main which accepts a &rest argv. My goal was to call the main function from a run.lisp script. That way I could avoid writing another function that would be called by main and that would accept the same key arguments from main.

So I evaluated (C-x C-e) or compiled a line like (mypackage::main :debug t) to see what it does, but it closes the Lisp connection.

I suggest we check if we are on Slime and do not quit in that case.
A very simple way is to check the TERM environment variable. On Slime, it's "dumb". I made a trivial system for that: termp.

@svetlyak40wt
Copy link
Member

This is a good idea. Ideally, we should call this helper system like in-ide instead of termp, because there are other environments like SLY, Lem, Closure IDE, LispWorks, etc. I'd create a single function there which will return a keyword for IDE kind or NIL, if this script is running standalone.

@svetlyak40wt
Copy link
Member

By the way, a function defined with defmain will not work like this (mypackage::main :debug t), because it defines a function which accepts args which are unix args – a list of strings.

To solve this issue really well, we need to separate defined body where variables names a used as keywords from the function which parses command-line arguments. And a version to be called should be chosen depending on IDE or non-IDE environent.

@vindarel
Copy link
Author

vindarel commented Jun 2, 2021

How would you find the IDE kind? (is there an environment variable for this?)

@svetlyak40wt
Copy link
Member

I don't see any special environment variables in LispWorks listener. But probably the best way will be to figure out IDE from backtrace stack frames.

For example, in lispworks it contains a call to INTERACTIVE-PANE-TOP-LOOP:

CL-USER 33 > (dbg:output-backtrace :bried)
Call to EVAL
Call to CAPI::CAPI-TOP-LEVEL-FUNCTION
Call to CAPI::INTERACTIVE-PANE-TOP-LOOP
Call to MP::PROCESS-SG-FUNCTION

In SBCL running under the SLYNK:

...
/Users/art/projects/lisp/sly/slynk/slynk.lisp:tlf73fn4: CALL-WITH-LISTENER:
 FN = #<FUNCTION (LAMBDA () :IN SLYNK::SPAWN-CHANNEL-THREAD) {1003B4802B}>
 LISTENER = #<SLYNK-MREPL::MREPL mrepl-1-1>
 OBJECT = #<SLYNK-MREPL::MREPL mrepl-1-1>
 SAVING = NIL
/Users/art/projects/lisp/sly/slynk/slynk.lisp:tlf131fn4: (FLET FORM-FUN-5 IN SPAWN-CHANNEL-THREAD):
 CONNECTION = #<SLYNK::MULTITHREADED-CONNECTION {10027A5C93}>
 G6 = #<SLYNK-MREPL::MREPL mrepl-1-1>
...

@svetlyak40wt
Copy link
Member

The guesser should search for packages such as CAPI, SLYNK, SWANK, etc and then check if some symbols are present in the stackframes.

@vindarel
Copy link
Author

vindarel commented Jun 2, 2021

mmh good ideas, though would you maybe accept a first patch that does like termp? "make it work, make it right"…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants