Hi,

At Tue, 23 Jul 2002 01:32:40 +0900,
Dan Debertin wrote:
> is not a case of nested classes, but of multiple classes within the
> same module. The menu, however, comes out nested:
> 
> *Rescan*
> Foo
> Foo::Bar
> Foo::Bar::Baz
> Foo::Bar#meth1
> Foo::Bar::Baz#meth2
> 
> Baz is not a nested class under Bar ... right?

Exactly.  ruby-move-to-block was needed to modify to skip RD
style comments.

Still this patch doesn't work well at here documents...


Index: 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 --- ruby-mode.el 28 Jun 2002 14:40:54 -0000 1.53 +++ ruby-mode.el 23 Jul 2002 05:29:00 -0000 @@ -131,26 +131,36 @@ (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 '()) (case-fold-search nil) + 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-block) + (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)) @@ -332,7 +342,7 @@ The variable ruby-indent-level controls (ruby-expr-beg 'expr-qstr) (not (looking-at "%=")) - (looking-at "%[Qqrxw]?\\(.\\)")) + (looking-at "%[QqrxWw]?\\(.\\)")) (goto-char (match-beginning 1)) - (setq expand (not (eq (char-before) ?q))) + (setq expand (not (memq (char-before) '(?q ?w)))) (setq w (buffer-substring (match-beginning 1) (match-end 1))) @@ -342,6 +352,5 @@ The variable ruby-indent-level controls ((string= w "(") (setq re ")(")) ((string= w "<") (setq re "><")) - ((or (and expand (string= w "\\")) - (member w '("*" "." "+" "?" "^" "$"))) + ((and expand (string= w "\\")) (setq w (concat "\\" w)))) (unless (cond (re (ruby-forward-string re indent-point t expand)) @@ -627,26 +636,33 @@ An end of a defun is found by moving for (defun ruby-move-to-block (n) (let (start pos done down) - (setq start (ruby-calculate-indent)) - (if (eobp) - nil - (while (and (not (bobp)) (not (eobp)) (not done)) - (forward-line n) + (while (not (setq start (ruby-calculate-indent))) + (setq pos t) + (forward-line n)) + (if pos (backward-line n)) + (back-to-indentation) + (setq down (looking-at (if (< n 0) ruby-block-end-re ruby-block-beg-re))) + (while (and (not done) (not (if (< n 0) (bobp) (eobp)))) + (forward-line n) + (cond + ((looking-at "^\\s *$")) + ((looking-at "^\\s *#")) + ((and (> n 0) (looking-at "^=begin\\>")) + (re-search-forward "^=end\\>")) + ((and (< n 0) (looking-at "^=end\\>")) + (re-search-backward "^=begin\\>")) + (t + (setq pos (current-indentation)) (cond - ((looking-at "^$")) - ((looking-at "^\\s *#")) - (t - (setq pos (current-indentation)) - (cond - ((< start pos) - (setq down t)) - ((and down (= pos start)) - (setq done t)) - ((> start pos) - (setq done t))))) - (if done - (progn - (back-to-indentation) - (if (looking-at ruby-block-mid-re) - (setq done nil))))))) + ((< start pos) + (setq down t)) + ((and down (= pos start)) + (setq done t)) + ((> start pos) + (setq done t))))) + (if done + (progn + (back-to-indentation) + (if (looking-at ruby-block-mid-re) + (setq done nil)))))) (back-to-indentation))
-- Nobu Nakada