diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2015-04-16 17:49:39 +0200 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2015-04-16 17:49:39 +0200 |
commit | 316208d7df5a935bcdc1c118723bf5430d201347 (patch) | |
tree | 3d9ba9850d57b07999dbd7c816d5fa2452ab1884 /helm-elisp.el | |
parent | e8985352c23c4938a1ddc3db8061542d5e734e36 (diff) |
Use helm-source for timers and complex-commands.
* helm-elisp.el: Add classes for timer.
No need to use type in complex commabd history.
* helm-source.el: Add type for timers.
Diffstat (limited to 'helm-elisp.el')
-rw-r--r-- | helm-elisp.el | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/helm-elisp.el b/helm-elisp.el index 6c69411e..92d3c453 100644 --- a/helm-elisp.el +++ b/helm-elisp.el @@ -685,61 +685,6 @@ Filename completion happen if string start after or between a double quote." (coerce . helm-symbolify)) "Variable.") -(defun helm-btf--usable-p () - "Return t if current version of `backtrace-frame' accept 2 arguments." - (condition-case nil - (and (backtrace-frame 1 'condition-case) t) - (wrong-number-of-arguments nil))) - -(if (helm-btf--usable-p) ; Check if BTF accept more than one arg. - ;; Emacs 24.4. - (dont-compile - (defvar helm-sexp--last-sexp nil) - ;; This wont work compiled. - (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-sexp--last-sexp))) - (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))) - ;; Emacs 24.3 - (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))))) - -(define-helm-type-attribute 'sexp - '((action - ("Eval" . (lambda (candidate) - (and (boundp 'helm-sexp--last-sexp) - (setq helm-sexp--last-sexp candidate)) - (run-with-timer 0.1 nil #'helm-sexp-eval candidate))) - ("Edit and eval" . - (lambda (cand) - (minibuffer-with-setup-hook - (lambda () (insert cand)) - (call-interactively #'eval-expression))))) - (persistent-action . helm-sexp-eval)) - "Sexp.") - (define-helm-type-attribute 'timer '((action ("Cancel Timer" . (lambda (_timer) @@ -756,27 +701,31 @@ Filename completion happen if string start after or between a double quote." ;;; Elisp Timers. ;; ;; -(defvar helm-source-absolute-time-timers - '((name . "Absolute Time Timers") - (candidates . timer-list) - (filtered-candidate-transformer - . (lambda (candidates _source) - (cl-loop for timer in candidates +(defclass helm-absolute-time-timers-class (helm-source-sync helm-type-timers) + ((candidates :initform timer-list) + (filtered-candidate-transformer + :initform + (lambda (candidates _source) + (cl-loop for timer in candidates collect (cons (helm-elisp--format-timer timer) timer)))) - (allow-dups) - (volatile) - (type . timer))) + (allow-dups :initform t) + (volatile :initform t))) + +(defvar helm-source-absolute-time-timers + (helm-make-source "Absolute Time Timers" 'helm-absolute-time-timers-class)) + +(defclass helm-idle-time-timers-class (helm-source-sync helm-type-timers) + ((candidates :initform timer-idle-list) + (allow-dups :initform t) + (volatile :initform t) + (filtered-candidate-transformer + :initform + (lambda (candidates _source) + (cl-loop for timer in candidates + collect (cons (helm-elisp--format-timer timer) timer)))))) (defvar helm-source-idle-time-timers - '((name . "Idle Time Timers") - (candidates . timer-idle-list) - (allow-dups) - (volatile) - (filtered-candidate-transformer - . (lambda (candidates _source) - (cl-loop for timer in candidates - collect (cons (helm-elisp--format-timer timer) timer)))) - (type . timer))) + (helm-make-source "Idle Time Timers" 'helm-idle-time-timers-class)) (defun helm-elisp--format-timer (timer) (format "%s repeat=%s %s(%s)" @@ -794,23 +743,74 @@ Filename completion happen if string start after or between a double quote." (defun helm-timers () "Preconfigured `helm' for timers." (interactive) - (helm-other-buffer '(helm-source-absolute-time-timers - helm-source-idle-time-timers) - "*helm timers*")) + (helm :sources '(helm-source-absolute-time-timers + helm-source-idle-time-timers) + :buffer "*helm timers*")) ;;; Complex command history ;; ;; +(defun helm-btf--usable-p () + "Return t if current version of `backtrace-frame' accept 2 arguments." + (condition-case nil + (and (backtrace-frame 1 'condition-case) t) + (wrong-number-of-arguments nil))) + +(if (helm-btf--usable-p) ; Check if BTF accept more than one arg. + ;; Emacs 24.4. + (dont-compile + (defvar helm-sexp--last-sexp nil) + ;; This wont work compiled. + (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-sexp--last-sexp))) + (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))) + ;; Emacs 24.3 + (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))))) + (defvar helm-source-complex-command-history - '((name . "Complex Command History") - (candidates . (lambda () - ;; Use cdr to avoid adding - ;; `helm-complex-command-history' here. - (cl-loop for i in command-history - unless (equal i '(helm-complex-command-history)) - collect (prin1-to-string i)))) - (type . sexp))) + (helm-build-sync-source "Complex Command History" + :candidates (lambda () + ;; Use cdr to avoid adding + ;; `helm-complex-command-history' here. + (cl-loop for i in command-history + unless (equal i '(helm-complex-command-history)) + collect (prin1-to-string i))) + :action (helm-make-actions + "Eval" (lambda (candidate) + (and (boundp 'helm-sexp--last-sexp) + (setq helm-sexp--last-sexp candidate)) + (run-with-timer 0.1 nil #'helm-sexp-eval candidate)) + "Edit and eval" + (lambda (cand) + (minibuffer-with-setup-hook + (lambda () (insert cand)) + (call-interactively #'eval-expression)))) + :persistent-action #'helm-sexp-eval)) ;;;###autoload (defun helm-complex-command-history () |