Hi,

At Mon, 22 Jul 2002 15:36:45 +0900,
Dan Debertin wrote:
> More ruby-mode.el fun today. The following bit of code, when run
> though imenu-add-menubar-index, only creates menu entries for the
> first class. It appears to be the fact that they're in the same module
> that's breaking it:

ruby-imenu-create-index didn't work for nested classes.  I'm
not sure if this works well enough for singletons.


Index: misc/ruby-mode.el =================================================================== RCS file: /cvs/ruby/src/ruby/misc/ruby-mode.el,v retrieving revision 1.53 diff -u -2 -p -r1.53 ruby-mode.el --- misc/ruby-mode.el 28 Jun 2002 14:40:54 -0000 1.53 +++ misc/ruby-mode.el 22 Jul 2002 10:39:15 -0000 @@ -131,26 +131,35 @@ (eval-when-compile (require 'cl)) -(defun ruby-imenu-create-index () - (let ((index-alist '()) - class-name class-begin method-name method-begin decl) - (goto-char (point-min)) - (while (re-search-forward "^\\s *\\(class\\|def\\)\\s *\\([^(\n ]+\\)" nil t) - (setq decl (buffer-substring (match-beginning 1) (match-end 1))) +(defun ruby-imenu-create-index (&optional prefix beg end) + (let ((index-alist '()) (nest '()) name name-begin name-end pos decl sing) + (goto-char (or beg (point-min))) + (while (re-search-forward "^\\s *\\(class\\(\\s +<<\\)?\\|module\\|def\\|alias\\)\\s *\\([^(\n ]+\\)" end t) + (setq sing (match-beginning 2)) + (setq decl (if sing "class" (buffer-substring (match-beginning 1) (match-end 1)))) + (setq name-begin (match-beginning 3)) + (setq name-end (match-end 3)) + (setq name (buffer-substring name-begin name-end)) + (setq pos (match-beginning 0)) (cond - ((string= "class" decl) - (setq class-begin (match-beginning 2)) - (setq class-name (buffer-substring class-begin (match-end 2))) - (push (cons class-name (match-beginning 0)) index-alist) - (ruby-mark-defun) - (save-restriction - (narrow-to-region (region-beginning) (region-end)) - (while (re-search-forward "^\\s *def\\s *\\([^(\n ]+\\)" nil 'move) - (setq method-begin (match-beginning 1)) - (setq method-name (buffer-substring method-begin (match-end 1))) - (push (cons (concat class-name "#" method-name) (match-beginning 0)) index-alist)))) - ((string= "def" decl) - (setq method-begin (match-beginning 2)) - (setq method-name (buffer-substring method-begin (match-end 2))) - (push (cons method-name (match-beginning 0)) index-alist)))) + ((or (string= "def" decl) (string= "alias" decl)) + (if prefix + (setq name + (cond + ((string-match "^self\." name) + (concat (substring prefix 0 -1) (substring name 4))) + (t (concat prefix name))))) + (push (cons name pos) index-alist)) + (t + (if (string= "self" name) + (if prefix (setq name (substring prefix 0 -1))) + (if prefix (setq name (concat (substring prefix 0 -1) "::" name))) + (push (cons name pos) index-alist)) + (ruby-end-of-defun) + (setq beg (point)) + (setq index-alist + (nconc index-alist + (ruby-imenu-create-index (concat name (if sing "." "#")) + name-end beg))) + (goto-char beg)))) index-alist))
-- Nobu Nakada