abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.19k stars 129 forks source link

lispy-eval + cider result overlay. Wierd when the evaluation changes buffers. Proposing checking if buff changed #639

Open benjamin-asdf opened 1 year ago

benjamin-asdf commented 1 year ago
  1. use lispy-eval
  2. lispy-eval-display-style is set to 'overlay (using cider)
  3. eval something like
    (find-file "~")
  4. buffer changes during eval, now in dired buffer.
  5. cider--display-interactive-eval-result will end up asking the user for comment syntax because it is not defined in dired mode

With this version of lispy-eval this is not an issue anymore:

(defun lispy-eval (arg &optional e-str)
  "Eval the current sexp and display the result.
When ARG is 2, insert the result as a comment.
When at an outline, eval the outline."
  (interactive "p")
  (setq lispy-eval-output nil)
  (let ((buff (current-buffer)))
    (condition-case e
    (cond ((eq arg 2)
               (lispy-eval-and-comment))
              ((and (looking-at lispy-outline)
                    (looking-at lispy-outline-header))
               (lispy-eval-outline))
              (t
               (let ((res (lispy--eval e-str)))
         (when (memq major-mode lispy-clojure-modes)
                   (setq res (lispy--clojure-pretty-string res)))
         (when lispy-eval-output
                   (setq res (concat lispy-eval-output res)))
         (cond ((eq lispy-eval-display-style 'message)
            (lispy-message res))
                       ((or (fboundp 'cider--display-interactive-eval-result)
                            (require 'cider nil t))
            (when (equal buff (current-buffer))
              (cider--display-interactive-eval-result
               res (cdr (lispy--bounds-dwim)))))
                       ((or (fboundp 'eros--eval-overlay)
                            (require 'eros nil t))
            (eros--eval-overlay
             res (cdr (lispy--bounds-dwim))))
                       (t
            (error "Please install CIDER >= 0.10 or eros to display overlay"))))))
      (eval-error
       (lispy-message (cdr e))))))