all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#2419: 23.0.90; python-mode: Better Imenu
@ 2009-02-21 10:24 Milan Zamazal
  0 siblings, 0 replies; only message in thread
From: Milan Zamazal @ 2009-02-21 10:24 UTC (permalink / raw)
  To: emacs-pretest-bug

In GNU Emacs 23.0.90.1 (x86_64-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2009-02-03 on blackbird, modified by Debian
 (emacs-snapshot package, version 1:20090202-1)

The Imenu support as currently implemented in python-mode is not very
useful:

1. It is easier to use I-search than clicking through the offered
   choices.

2. When I call `M-x imenu', it usually can't find the definition of the
   identifier at the current point.

FWIW, I use the following Imenu index building function which fixes both
the problems by using single-string items, with reverse order of the
identifiers within the string.  Perhaps something like this could be
useful for other people as well.

(defun my-python-imenu-create-index ()
  (let ((index '())
        (suffix '()))
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward "^\\([ \t]*\\)\\(def\\|class\\) \\([a-zA-Z_0-9]+\\)" nil t)
        (let ((indentation (length (match-string 1)))
              (name (match-string-no-properties 3)))
          (while (and suffix (<= indentation (caar suffix)))
            (setq suffix (cdr suffix)))
          (let* ((current-suffix (if suffix (cdar suffix) ""))
                 (name+suffix (concat name current-suffix)))
            (push (cons indentation (concat "." name+suffix)) suffix)
            (push (cons name+suffix (match-end 3)) index))))
      (goto-char (point-min))
      (while (re-search-forward "^\\([a-zA-Z_0-9]+\\) *=" nil t)
        (push (cons (match-string-no-properties 1) (match-end 1)) index)))
    (sort* index 'string< :key 'car)))

Regards,

Milan Zamazal






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-21 10:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-21 10:24 bug#2419: 23.0.90; python-mode: Better Imenu Milan Zamazal

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.