Elisp: Use separate function to handle toggling or newlining

Since the text properties only takes in one map at a time (as far as I
know), the insert/normal state auxillery maps will conflict with each
other. It's easier to have C-m trigger a function that checks its
state and Does The Right Thing instead.
This commit is contained in:
James Nguyen 2017-11-26 12:01:07 -08:00
parent 30d3144048
commit af5fadf798
1 changed files with 11 additions and 3 deletions

View File

@ -36,11 +36,10 @@ BEG and END are the start and end of the output in current-buffer.
VALUE is the Lisp value printed, ALT1 and ALT2 are strings for the
alternative printed representations that can be displayed."
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-m") 'elisp-last-sexp-toggle-display)
(define-key map (kbd "C-m")
'evil-elisp-mode-return-or-last-sexp-toggle-display)
(define-key map [down-mouse-2] 'mouse-set-point)
(define-key map [mouse-2] 'elisp-last-sexp-toggle-display)
(evil-define-key 'insert map (kbd "C-m")
(lookup-key (current-global-map) (kbd "<return>")))
(add-text-properties
beg end
`(printed-value (,value ,alt1 ,alt2)
@ -49,6 +48,15 @@ alternative printed representations that can be displayed."
help-echo "RET, mouse-2: toggle abbreviated display"
rear-nonsticky (mouse-face keymap help-echo
printed-value)))))
(defun evil-elisp-mode-return-or-last-sexp-toggle-display ()
"Trigger RET or call `elisp-last-sexp-toggle-display'."
(interactive)
(if (eq evil-state 'insert)
(call-interactively
(lookup-key (current-global-map) (kbd "C-m")))
(call-interactively 'elisp-last-sexp-toggle-display)))
(defun evil-elisp-mode-setup ()
"Set up `evil' bindings for `elisp-mode'."
(advice-add 'last-sexp-setup-props