joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.23k stars 139 forks source link

Need help to write a function my-sly-wait (for eepitch) #550

Open edrx opened 1 year ago

edrx commented 1 year ago

Hi people,

is this a good place to ask for help? The manual mentions a sly-devel mailing list, but I couldn't find it...

I am trying to make eepitch[1] work with Sly. I wrote the code below, and it needs a fix in the line with the "TODO: fix this". I need to replace the

  (save-window-excursion (sly))

by this,

  (save-window-excursion (sly) (my-sly-wait))

where the (my-sly-wait) only returns after the Sly connection is established and the (sly-mrepl--find-buffer) buffer is ready... how do I write that (my-sly-wait)?

If anyone wants to know why I need this, this reason is because I need to make (find-slyprocess) be a "shell-like function" in the sense of [2]: it shouldn't change anything in the current window configuration besides the buffer in the current window, that should become the (sly-mrepl--find-buffer) buffer... and I think that adding a "(my-sly-wait)" would be the easiest way to achieve that.

The links are:

[1] http://angg.twu.net/eepitch.html [2] http://angg.twu.net/eev-intros/find-eepitch-intro.html#2.3

and my current code is below. Thanks in advance! =)

(defun find-slyprocess-reuse ()
  "Go to a Sly REPL buffer (when we want to reuse an old one).
This is an internal function used by `find-slyprocess'."
  (find-ebuffer (sly-mrepl--find-buffer) :end))

(defun find-slyprocess-create ()
  "Go to a Sly REPL buffer (when we want to create a new one).
This is an internal function used by `find-slyprocess'."
  (let ((sly-command-switch-to-existing-lisp 'never)
    (sly-auto-select-connection 'never)
    (sly-lisp-implementations '((sbcl ("sbcl"))))
    (sly-default-lisp 'sbcl))
    (save-window-excursion (sly))   ; TODO: fix this
    (find-slyprocess-reuse)))

(defun find-slyprocess ()
  "Go to a Sly REPL buffer, This function is used by `eepitch-sly'."
  (interactive)
  (require 'sly)
  (sly-setup)
  (if (and (sly-current-connection)
       (sly-mrepl--find-buffer))
      (find-slyprocess-reuse)
    (find-slyprocess-create)))

(defun eepitch-sly () (interactive)
  (eepitch '(find-slyprocess)))
edrx commented 1 year ago

I think I've solved it: https://lists.gnu.org/archive/html/help-gnu-emacs/2022-12/msg00775.html