The name of a function is often used for reference when writing this blog.

M-x a-function-name then M-o, we can see there is a selection panel:

o: default i: open the file according to the environment d: definition h: help

With the function wr/ivy-yank-function-name-action, you can copy the function name using the correct format.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun wr/ivy-yank-function-name-action (x)
    "Send name of function to kill-ring.
  See `ivy-set-actions`"
    (with-temp-buffer
      (progn
        (insert "~")
        (insert x)
        (insert "~")
        (kill-ring-save (point-min) (point-max)))))

  (ivy-set-actions
   'counsel-M-x
   '(("c" wr/ivy-yank-function-name-action "copy function name")))

You can also set actions for non-interactive commands such as wr/ivy-yank-function-name-action using the following snippet:

1
2
3
(ivy-set-actions
   'counsel-describe-function
   '(("c" wr/ivy-yank-function-name-action "copy function name"))