all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Milan Zamazal <pdm@zamazal.org>
To: emacs-pretest-bug@gnu.org
Subject: bug#2419: 23.0.90; python-mode: Better Imenu
Date: Sat, 21 Feb 2009 11:24:23 +0100	[thread overview]
Message-ID: <87mycg9jfs.fsf@blackbird.nest.zamazal.org> (raw)

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






                 reply	other threads:[~2009-02-21 10:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mycg9jfs.fsf@blackbird.nest.zamazal.org \
    --to=pdm@zamazal.org \
    --cc=2419@emacsbugs.donarmstrong.com \
    --cc=emacs-pretest-bug@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.