Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 178 lines (152 sloc) 6.876 kb
530d89f Thierry Volpiatto Enable lexical-binding in all files.
thierryvolpiatto authored
1 ;;; helm-eval.el --- eval expressions from helm. -*- lexical-binding: t -*-
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
2
064302a Thierry Volpiatto Update copyrights.
thierryvolpiatto authored
3 ;; Copyright (C) 2012 ~ 2014 Thierry Volpiatto <thierry.volpiatto@gmail.com>
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
4
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 ;;; Code:
b740a4b Thierry Volpiatto Finish replacing cl symbols and requiring cl-lib, no compile error.
thierryvolpiatto authored
19 (require 'cl-lib)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
20 (require 'helm)
320fe95 Thierry Volpiatto * helm-eval.el: require eldoc.
thierryvolpiatto authored
21 (require 'eldoc)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
22
ba17f09 Thierry Volpiatto Move all defcustoms and faces in their respectives groups and files.
thierryvolpiatto authored
23
24 (defgroup helm-eval nil
25 "Eval related Applications and libraries for Helm."
26 :group 'helm)
27
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
28 (defcustom helm-eldoc-in-minibuffer-show-fn
29 'helm-show-info-in-mode-line
ba17f09 Thierry Volpiatto Move all defcustoms and faces in their respectives groups and files.
thierryvolpiatto authored
30 "A function to display eldoc info.
31 Should take one arg: the string to display."
32 :group 'helm-eval
33 :type 'symbol)
34
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
35 (defcustom helm-show-info-in-mode-line-delay 12
ba17f09 Thierry Volpiatto Move all defcustoms and faces in their respectives groups and files.
thierryvolpiatto authored
36 "Eldoc will show info in mode-line during this delay if user is idle."
37 :type 'integer
38 :group 'helm-eval)
39
40
7d8197a Thierry Volpiatto Fix warnings at compilation.
thierryvolpiatto authored
41 (declare-function eldoc-current-symbol "eldoc")
42 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
43 (declare-function eldoc-get-var-docstring "eldoc" (sym))
44 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
45
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
46 ;;; Evaluation Result
47 ;;
48 ;;
49 ;; Internal
50 (defvar helm-eldoc-active-minibuffers-list nil)
51
52 (defvar helm-eval-expression-map
b740a4b Thierry Volpiatto Finish replacing cl symbols and requiring cl-lib, no compile error.
thierryvolpiatto authored
53 (let ((map (make-sparse-keymap)))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
54 (set-keymap-parent map helm-map)
55 (define-key map (kbd "<C-return>") 'helm-eval-new-line-and-indent)
e6daefc Thierry Volpiatto * helm-eval.el: Fix keymap conflict with tab.
thierryvolpiatto authored
56 (define-key map (kbd "<M-tab>") 'lisp-indent-line)
8e72c21 Thierry Volpiatto * helm-dabbrev.el: Allow usage in minibuffer, delay action and allow-nes...
thierryvolpiatto authored
57 (define-key map (kbd "<C-tab>") 'helm-lisp-completion-at-point)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
58 (define-key map (kbd "C-p") 'previous-line)
59 (define-key map (kbd "C-n") 'next-line)
60 (define-key map (kbd "<up>") 'previous-line)
61 (define-key map (kbd "<down>") 'next-line)
62 (define-key map (kbd "<right>") 'forward-char)
63 (define-key map (kbd "<left>") 'backward-char)
64 map))
65
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
66 (defvar helm-source-evaluation-result
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
67 '((name . "Evaluation Result")
f5d52ce Thierry Volpiatto * helm-eval.el (helm-source-evaluation-result): Allow evaling within ede...
thierryvolpiatto authored
68 (init . (lambda () (require 'edebug)))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
69 (dummy)
70 (multiline)
71 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
40ada5b Thierry Volpiatto Fix unused args source in some filtered candidates functions.
thierryvolpiatto authored
72 (filtered-candidate-transformer . (lambda (candidates _source)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
73 (list
74 (condition-case nil
75 (with-helm-current-buffer
76 (pp-to-string
f5d52ce Thierry Volpiatto * helm-eval.el (helm-source-evaluation-result): Allow evaling within ede...
thierryvolpiatto authored
77 (if edebug-active
78 (edebug-eval-expression
79 (read helm-pattern))
bc4fb13 Thierry Volpiatto Finally reindent with the cl indentation behavior of 24.4.50.
thierryvolpiatto authored
80 (eval (read helm-pattern)))))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
81 (error "Error")))))
82 (action . (("Copy result to kill-ring" . (lambda (candidate)
927f9be Thierry Volpiatto * helm-eval.el (helm-source-evaluation-result): Simplify action 1.
thierryvolpiatto authored
83 (kill-new
84 (replace-regexp-in-string
85 "\n" "" candidate))))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
86 ("copy sexp to kill-ring" . (lambda (candidate)
87 (kill-new helm-input)))))))
88
89 (defun helm-eval-new-line-and-indent ()
90 (interactive)
91 (newline) (lisp-indent-line))
92
93 (defun helm-eldoc-store-minibuffer ()
94 "Store minibuffer buffer name in `helm-eldoc-active-minibuffers-list'."
95 (with-selected-window (minibuffer-window)
86a50f9 Thierry Volpiatto * helm-eval.el: Simplify according to eldoc-eval.
thierryvolpiatto authored
96 (push (current-buffer) helm-eldoc-active-minibuffers-list)))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
97
98 (defun helm-eldoc-show-in-eval ()
99 "Return eldoc in mode-line for current minibuffer input."
86a50f9 Thierry Volpiatto * helm-eval.el: Simplify according to eldoc-eval.
thierryvolpiatto authored
100 (let ((buf (window-buffer (active-minibuffer-window))))
c7913c1 Thierry Volpiatto * helm-eval.el (helm-eldoc-show-in-eval): Avoid error messages in emacs ...
thierryvolpiatto authored
101 (condition-case err
102 (when (member buf helm-eldoc-active-minibuffers-list)
9b3b7b4 Thierry Volpiatto * helm-eval.el (helm-eldoc-show-in-eval): Get rid of `minibuffer-complet...
thierryvolpiatto authored
103 (with-current-buffer buf
104 (let* ((sym (save-excursion
105 (unless (looking-back ")\\|\"")
106 (forward-char -1))
107 (eldoc-current-symbol)))
108 (info-fn (eldoc-fnsym-in-current-sexp))
109 (doc (or (eldoc-get-var-docstring sym)
110 (eldoc-get-fnsym-args-string
111 (car info-fn) (cadr info-fn)))))
112 (when doc (funcall helm-eldoc-in-minibuffer-show-fn doc)))))
9b50655 Thierry Volpiatto Keep fixing unused args
thierryvolpiatto authored
113 (error (message "Eldoc in minibuffer error: %S" err) nil))))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
114
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
115 (defun helm-show-info-in-mode-line (str)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
116 "Display string STR in mode-line."
117 (save-selected-window
118 (with-current-buffer helm-buffer
119 (let ((mode-line-format (concat " " str)))
120 (force-mode-line-update)
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
121 (sit-for helm-show-info-in-mode-line-delay))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
122 (force-mode-line-update))))
123
124 ;;; Calculation Result
125 ;;
126 ;;
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
127 (defvar helm-source-calculation-result
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
128 '((name . "Calculation Result")
129 (dummy)
40ada5b Thierry Volpiatto Fix unused args source in some filtered candidates functions.
thierryvolpiatto authored
130 (filtered-candidate-transformer . (lambda (candidates _source)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
131 (list
132 (condition-case nil
133 (calc-eval helm-pattern)
134 (error "error")))))
135 (action ("Copy result to kill-ring" . kill-new))))
136
137 ;;;###autoload
138 (defun helm-eval-expression (arg)
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
139 "Preconfigured helm for `helm-source-evaluation-result'."
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
140 (interactive "P")
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
141 (helm :sources 'helm-source-evaluation-result
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
142 :input (when arg (thing-at-point 'sexp))
143 :buffer "*helm eval*"
82d2db7 `helm-eval-expression` uses `read-expression-history' instead of its own
Le Wang authored
144 :history 'read-expression-history
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
145 :keymap helm-eval-expression-map))
146
4e6ddbb Thierry Volpiatto Make declarations with defvar.
thierryvolpiatto authored
147 (defvar eldoc-idle-delay)
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
148 ;;;###autoload
149 (defun helm-eval-expression-with-eldoc ()
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
150 "Preconfigured helm for `helm-source-evaluation-result' with `eldoc' support. "
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
151 (interactive)
8e72c21 Thierry Volpiatto * helm-dabbrev.el: Allow usage in minibuffer, delay action and allow-nes...
thierryvolpiatto authored
152 (let ((timer (run-with-idle-timer
153 eldoc-idle-delay 'repeat
154 'helm-eldoc-show-in-eval)))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
155 (unwind-protect
9bc2702 Thierry Volpiatto Reindent all again.
thierryvolpiatto authored
156 (minibuffer-with-setup-hook
157 'helm-eldoc-store-minibuffer
158 (call-interactively 'helm-eval-expression))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
159 (and timer (cancel-timer timer))
160 (setq helm-eldoc-active-minibuffers-list
161 (cdr helm-eldoc-active-minibuffers-list)))))
162
163 ;;;###autoload
164 (defun helm-calcul-expression ()
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
165 "Preconfigured helm for `helm-source-calculation-result'."
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
166 (interactive)
4166d8a Thierry Volpiatto Replace "helm-c-" prefix by "helm-" in all files.
thierryvolpiatto authored
167 (helm-other-buffer 'helm-source-calculation-result "*helm calcul*"))
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
168
169 (provide 'helm-eval)
170
37b4201 Thierry Volpiatto Fix dependencies and autoloads. Reorder.
thierryvolpiatto authored
171 ;; Local Variables:
a7ee65b Thierry Volpiatto Disable compile warnings and add new keyword to helm.
thierryvolpiatto authored
172 ;; byte-compile-warnings: (not cl-functions obsolete)
37b4201 Thierry Volpiatto Fix dependencies and autoloads. Reorder.
thierryvolpiatto authored
173 ;; coding: utf-8
174 ;; indent-tabs-mode: nil
175 ;; End:
176
ce61153 Thierry Volpiatto * helm-config.el: Move eval-expression to helm-eval.el
thierryvolpiatto authored
177 ;;; helm-eval.el ends here
Something went wrong with that request. Please try again.