Skip to content

Commit

Permalink
* helm-elisp.el (helm-sexp-eval): Fix compatibility with old emacs (#489
Browse files Browse the repository at this point in the history
).
  • Loading branch information
Thierry Volpiatto committed May 9, 2014
1 parent 42dd994 commit 621e87a
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions helm-elisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -616,27 +616,38 @@ First call indent, second complete symbol, third complete fname."
(coerce . helm-symbolify))
"Variable.")

(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)))
;;; Incompatible change for 24.3 and lower.
;;
(if (version< emacs-version "24.4")
(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 621e87a

Please sign in to comment.