From 1717a7b08f184f7770fe061a5f68a3989038df83 Mon Sep 17 00:00:00 2001 From: James Nguyen Date: Thu, 14 Jan 2021 00:27:12 -0800 Subject: [PATCH] Sly: Advise sly-eval-print-last-expression Credits to nnoodle for implementation. For more details: https://github.com/emacs-evil/evil-collection/pull/441 --- modes/sly/evil-collection-sly.el | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modes/sly/evil-collection-sly.el b/modes/sly/evil-collection-sly.el index f28bb03..c73d2e8 100644 --- a/modes/sly/evil-collection-sly.el +++ b/modes/sly/evil-collection-sly.el @@ -32,6 +32,9 @@ (require 'evil-collection) (require 'sly nil t) +(declare-function sly-last-expression "sly") +(declare-function sly-eval-print "sly") + (defvar sly-connection-list-mode-map) (defvar sly-db-mode-map) (defvar sly-inspector-mode-map) @@ -62,14 +65,29 @@ (apply command args)) (apply command args))) +(defun evil-collection-sly-eval-print-last-expression (string) + "Evaluate sexp before point; print value into the current buffer. + +Evil version of `sly-eval-print-last-expression' that accounts for +`evil-move-beyond-eol'." + (interactive + (list (progn + (when (and (not evil-move-beyond-eol) + (or (evil-normal-state-p) (evil-motion-state-p))) + (unless (or (eobp) (eolp)) + (forward-char))) + (sly-last-expression)))) + (insert "\n") + (sly-eval-print string)) + ;;;###autoload (defun evil-collection-sly-setup () "Set up `evil' bindings for `sly'." (unless evil-move-beyond-eol (advice-add 'sly-eval-last-expression :around 'evil-collection-sly-last-sexp) (advice-add 'sly-pprint-eval-last-expression :around 'evil-collection-sly-last-sexp) - (advice-add 'sly-eval-print-last-expression :around 'evil-collection-sly-last-sexp) - (advice-add 'sly-mrepl-return :around 'evil-collection-sly-last-sexp)) + (advice-add 'sly-mrepl-return :around 'evil-collection-sly-last-sexp) + (advice-add 'sly-eval-print-last-expression :override 'evil-collection-sly-eval-print-last-expression)) (evil-collection-define-key 'normal 'sly-db-mode-map [follow-link] 'mouse-face