Demo

elisp

Source
http://github.com/semiosis/pen.el/blob/master/src/pen-clojure.el

Custom helm source

The first trick is to modify (helm-cider--apropos-sources) so the candidate :action function instead returns the candidate instead of opening documentation for the candidate.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
(defun helm-cider--apropos-sources-nodoc ()
  (-map
   (lambda (e)
     ;; (setq e (delq (assoc 'action e) e))
     (setq e (delq (assoc 'persistent-action e) e))

     ;; This action means helm will return the value. So helm functions like fzf.
     (setcdr (assq 'action e) (lambda (c) (helm-marked-candidates)))
     e)
   (helm-cider--apropos-sources)))

Cider

If the function has arguments the arguments are interactively asked for in emacs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(defun pen-cider-run-function ()
  (interactive)
  (let* ((ret
          (car
           (helm
            :buffer "*Helm Clojure Symbols*"
            :candidate-number-limit 9999
            :sources (helm-cider--apropos-sources-nodoc)
            ;; (helm-cider--apropos-sources)
            )))
         (shortname (if ret
                        (replace-regexp-in-string
                         "^.*\\/" ""
                         ret)))

         (sig (cider-company-docsig ret))
         (arglist (pen-vector2list
                   (eval-string
                    (concat
                     "'"
                     (replace-regexp-in-string
                      "^.*: (\\(.*\\))$" "\\1"
                      (cider-company-docsig ret))))))
         (arglist (-filter (lambda (s) (not (string-equal "&" s)))
                           arglist)))

    (if ret
        (pen-cider-repl-run-function-interactively ret arglist)
      ;; (cider-run shortname)
      )))

(defun pen-cider-repl-run-function-interactively (funname argnames)
  (let* ((iarglist (mapcar
                    (lambda (e) `(read-string-hist ,(concat (str e) ": ")))
                    argnames)))

    (eval
     `(call-interactively
       (lambda (,@arglist)
         (interactive (list ,@iarglist))
         (let* ((valstr (pen-cmd ,@arglist))
                (clj (concat "(" ,funname " " valstr ")")))
           (cider-nrepl-request:eval clj nil)))))
    (cider-nrepl-request:eval (concat "(" funname ")") nil)))