drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Add symex-common-lisp-modes variable #90

Closed olnw closed 1 year ago

olnw commented 1 year ago

Summary of Changes

This means Symex functions can be used in the Sly/SLIME REPL. I have tested all relevant interactive functions with Sly and SLIME, and everything appears to work, except for symex-evaluate-definition in the SLIME REPL. It works in lisp-mode buffers, but not in the REPL.

Let's say my REPL looks like this, and the square brackets represent the point. In this case, I would get an error if I were to run slime-eval-defun.1

CL-USER> (princ "fo[]o")

However, evaluation is successful in the following examples.

CL-USER> (princ
           "foo")[]
CL-USER> (princ "foo")[]

Since this apparent bug affects slime-eval-defun, it would need to be fixed in SLIME's source. Since this isn't a Symex problem, it shouldn't affect whether this PR gets merged.

1.

end of file on #<dynamic-extent STRING-INPUT-STREAM (unavailable) from "(princ \"fo">
   [Condition of type END-OF-FILE]

Restarts:
 0: [RETRY] Retry SLIME interactive evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD tid=23478 "repl-thread" RUNNING {1004DB3A63}>)

Backtrace:
  0: ((FLET SB-IMPL::CHARACTER-IN :IN SB-IMPL::%INIT-STRING-INPUT-STREAM) #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> T NIL)
  1: (SB-IMPL::READ-STRING #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> #\")
  2: (SB-IMPL::READ-MAYBE-NOTHING #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> #\")
  3: (SB-IMPL::READ-LIST #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> #<unused argument>)
  4: (SB-IMPL::READ-MAYBE-NOTHING #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> #\()
  5: (SB-IMPL::%READ-PRESERVING-WHITESPACE #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> T (NIL) T)
  6: (SB-IMPL::%READ-PRESERVING-WHITESPACE #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> T (NIL) NIL)
  7: (READ #<SB-IMPL::STRING-INPUT-STREAM {7FE7A47FDFB3}> T NIL NIL)
  8: (SB-IMPL::%READ-FROM-STRING "(princ \"fo" T NIL 0 NIL NIL)
  9: ((LAMBDA NIL :IN SWANK:FROM-STRING))
 10: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<FUNCTION (LAMBDA NIL :IN SWANK:FROM-STRING) {10053F6FDB}>)
 11: ((LAMBDA NIL :IN SWANK:INTERACTIVE-EVAL))
 12: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME interactive evaluation request." #<FUNCTION (LAMBDA NIL :IN SWANK:INTERACTIVE-EVAL) {10053F6F7B}>)
 13: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<FUNCTION (LAMBDA NIL :IN SWANK:INTERACTIVE-EVAL) {10053F6F5B}>)
 14: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK:INTERACTIVE-EVAL "(princ \"fo") #<NULL-LEXENV>)
 15: (EVAL (SWANK:INTERACTIVE-EVAL "(princ \"fo"))
 16: (SWANK:EVAL-FOR-EMACS (SWANK:INTERACTIVE-EVAL "(princ \"fo") "COMMON-LISP-USER" 20)
 17: (SWANK::PROCESS-REQUESTS NIL)
 18: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
 19: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
 20: (SWANK/SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1004E5002B}>)
 21: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/home/oliver/stow/Emacs/.emacs.d/elpa/slime-20230222.1526/swank/sbcl.lisp") #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL :IN SWANK::HA..
 22: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-INPUT* . #<SWANK/GRAY::SLIME-INPUT-STREAM {1004BFFDC3}>)) #<FUNCTION (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1004E5004B}>)
 23: (SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {100431E743}> NIL)
 24: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
 25: ((FLET "WITHOUT-INTERRUPTS-BODY-156" :IN SB-THREAD::RUN))
 26: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
 27: ((FLET "WITHOUT-INTERRUPTS-BODY-149" :IN SB-THREAD::RUN))
 28: (SB-THREAD::RUN)
 29: ("foreign function: call_into_lisp_")
 30: ("foreign function: funcall1")

Public Domain Dedication

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)

countvajhula commented 1 year ago

I think that's fine re:eval-definition. As it is intended to evaluate an entire containing definition form (like a function definition or any top-level form), I think it could safely be considered "unsupported" UX from the point of view of the REPL which typically expects expressions as input one at a time. To confirm, I just tried eval-defun in Emacs's built-in REPL (ielm, which you can access from Symex via r in an ELisp buffer), and that results in an error as well.

Making the UX consistent across Common Lisp modes is great. Thank you!