1

Currently emacs has useful imenu thing which allow me to see list of functions in current buffer. To achieve this i need to type M-x, then type imenu, then press return key, then it will display prompt in minibuffer "Index item:" and i need to type func, then it displays another minibuffer prompt with aoutocompletion of all functions in current buffer. This is very good and useful, but now i'd like to reduce amount of typing and to macrosify somehow first part of sequence. I tried this approach:

(defun my-imenu-go-function-list ()
  (interactive)
  (imenu "func"))

(global-set-key (kbd "C-x C-o") 'my-imenu-go-function-list)

Another try:

(defun my-imenu-go-function-list ()
  (interactive)
  (imenu)
  (execute-kbd-macro [?f ?u ?n ?c return]))

But none worked, is there another possibility ?

Drew
  • 29,895
  • 7
  • 74
  • 104
Dfr
  • 4,075
  • 10
  • 40
  • 63
  • Did you try `helm-semantic`? It's superior to `imenu` in every way I think. And there's better stuff than `helm-semantic`, depending on the major-mode. – abo-abo Dec 14 '14 at 21:23
  • @Seb answered your question about your code. If you want a quick way to get to Imenu entries, you might want to try [**Icicles**](http://www.emacswiki.org/Icicles). In *Icicle* mode, `C-c =` (command [`icicle-imenu`](http://www.emacswiki.org/Icicles_-_Other_Search_Commands#IciclesImenu)) gives you an Imenu browser, and your input can match Imenu entries in many ways, including substring, fuzzy, and regexp matching. – Drew Dec 15 '14 at 02:37

2 Answers2

2

sebs' answer displays an extremely neat trick I'd not seen before; however the following would be a bit more direct:

(imenu (assoc "func" (imenu--make-index-alist)))

It does depend upon a private (by convention) function, though, so YMMV. I can't see an obvious API for returning this alist value.

phils
  • 71,335
  • 11
  • 153
  • 198
1

You need to call your function interactively.

Try the following. It should work.

UPDATED:

(defun my-imenu-go-function-list ()
  (interactive) 
  (let ((unread-command-events  (listify-key-sequence "func\n") ))
  (call-interactively 'imenu)))

If you are in Windows you might have to change the carriage return to "\r" or "\r\n"

sebs
  • 4,566
  • 3
  • 19
  • 28
  • Thank you, at least this doesn't give me an error, but it looks like "func" argument is somehow ignored here and i still need to type `func` – Dfr Dec 15 '14 at 05:15