Determining the current class

Bug #328846 reported by Ytrewq1
2
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

I'd like some way to easily determine the class that
the Emacs point is in. I looked for a way but didn't
find anything relevant.

For the moment, I've put together something that
attempts to determine the current class and display it
via the echo area. Code follows:

(defun py-show-current-class ()
  (interactive)
  (save-excursion
    (let ((class-name nil))
      (if (py-go-up-tree-to-keyword "class")
          (setq class-name (py-current-defun))
        (setq class-name "None determined"))
      (message (format "Current class: %s" class-name)))))

P.S. I thought of working with which-function-mode, but
the mode line seems too crowded already.

[http://sourceforge.net/tracker/index.php?func=detail&aid=1096977&group_id=86916&atid=581352]

Related branches

Revision history for this message
Ytrewq1 (ytrewq1) wrote :

I just learned about header-line-format in Emacs 21 --
perhaps the current class can be displayed there.

Revision history for this message
Montanaro (montanaro) wrote :

Have you taken a look at Emacs' func-menu package? It's a start,
though I don't think it handles nested scopes. If you were to come
up with a patch for it, it would probably help beyond Python.

(Sorry for the delay responding. I didn't know about this tracker.)

Skip

Revision history for this message
Ytrewq1 (ytrewq1) wrote :

I didn't know about func-menu -- are you
referring to the following?

http://media.wu-wien.ac.at/emacs/func-menu.el

FWIW, since I submitted this report, I've done a
copy-modify job [1] on which-func and created
which-class.el. Using this, the current class
name and function name are displayed in the
header line (at least for Python). I've found
that being able to determine which class and
function point is in at a glance (w/o having
to enter any command) is quite nice.

[1] Yes, a patch would have been nice but
which-func seemed very mode-line-specific...

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Changed in python-mode:
status: New → Confirmed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

re-enabled py-current-defun

Returns the name, as required.

In order to meet the request here,
it jumps to the definition --when customized, wait a customizable delay-- jumps back.

When interactively called, resp. with optional arg, name is printed in the message-buffer.

(defcustom py-which-func-show t
 "If `py-current-defun' should jump to the definition, highlight it while waiting PY-WHICH-FUNC-DELAY seconds, before returning to previous position.

Default is `t'."

:type 'boolean
:group 'python)

(defcustom py-which-func-delay 2
 "When called interactively, `py-current-defun' should wait PY-WHICH-FUNC-DELAY seconds at the definition name found, before returning to previous position. "

:type 'number
:group 'python)

BTW which-func-mode also should work right out of the box

Cheers

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
https://code.launchpad.net/s-x-emacs-werkstatt/

Changed in python-mode:
status: Confirmed → Fix Committed
Changed in python-mode:
milestone: none → 6.0
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.