Skip to content

Commit

Permalink
* helm-elisp.el (helm-sexp-eval): Partially fix issue with called-int…
Browse files Browse the repository at this point in the history
…eractively-p (#489).

Not backward compatible, not working with compiled code.
  • Loading branch information
Thierry Volpiatto committed May 7, 2014
1 parent b808850 commit b6289fe
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions helm-elisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,27 @@ First call indent, second complete symbol, third complete fname."
(coerce . helm-symbolify))
"Variable.")

(defun helm-sexp-eval (cand)
(let ((sexp (read cand)))
(condition-case err
(if (> (length (remove nil sexp)) 1)
(eval sexp)
(apply 'call-interactively sexp))
(error (message "Evaluating gave an error: %S" err)
nil))))
(dont-compile
(defun helm-sexp-eval-1 ()
(interactive)
(unwind-protect
(progn
;; Trick called-interactively-p into thinking that `cand' is
;; an interactive call, See `repeat-complex-command'.
(add-hook 'called-interactively-p-functions
#'helm-complex-command-history--called-interactively-skip)
(eval (read (helm-get-selection))))
(remove-hook 'called-interactively-p-functions
#'helm-complex-command-history--called-interactively-skip)))

(defun helm-complex-command-history--called-interactively-skip (i _frame1 frame2)
(and (eq 'eval (cadr frame2))
(eq 'helm-sexp-eval-1
(cadr (backtrace-frame (+ i 2) #'called-interactively-p)))
1))

(defun helm-sexp-eval (_candidate)
(call-interactively #'helm-sexp-eval-1)))

(define-helm-type-attribute 'sexp
'((action
Expand Down

0 comments on commit b6289fe

Please sign in to comment.