miércoles, 20 de marzo de 2013

occur: Poor man's taglist

From time to time I see some vim screencast and think: "oh, taglist, that was nice...", and yeah, in emacsland we have lots of alternatives, like full blown ecb, or imenu, or idomenu, I guess there might even exist something with speedbar...

But none of them really cuts it for me, I'd need the ecb one without all other ecb features. Or something like that

So here's the plain dead simple elisp I'm using lately. Just occur-mode and a keybinding to update the search. For ruby, it can't find all the dinamic shit in there, but you get a nice overview of what's in your file, and if it's properly indented (which should be) you also get the notion of what's public, private, etc...

Surprisingly, I'm using it more and more, and I can have different regexes for different filetypes. (even tune it to look for 'get\\|post' if I'm editing sinatra things.)

Dead simple, but it kind of works.
(defun rgc-show-ruby-tags ()
  (occur "^\\s-*\\\(class \\\|module \\\|def \\\|[^:]include \\\|private\\b\\\|protected\\b\\\)"))

(define-key ruby-mode-map (kbd "C-c t") 'rgc-show-ruby-tags)

3 comentarios:

Anónimo dijo...

I stumbled upon this idea too, and it is surprisingly useful. My version is for python code (but that's just a different regexp), and has a few fancy features, the best of which is positioning the occur-buffer's cursor on the "current" tag: http://pastebin.com/Vd5VEith

Raimon Grau dijo...


I'm stealing the positioning on current tag feature :)

I'm thinking that setting a variable for different modes as the regexp to search for and using which-function would be a quite easy way to have it available for every language you need.

Anónimo dijo...

Hi Ramon. Do you have something for c language?. I would be nice
listing all the function on a file.