Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs function to message the python function I'm in

I'm editing some Python code with rather long functions and decided it would be useful to quickly get the function name without scrolling up. I put this bit of code together to do it. Is there something built in to emacs in general, or the standard python mode in particular, which I can use instead?

(defun python-show-function-name()
  "Message the name of the function the point is in"
  (interactive)
  (save-excursion
    (beginning-of-defun)
    (message (format "%s" (thing-at-point 'line)))))
like image 871
justinhj Avatar asked Apr 23 '09 15:04

justinhj


1 Answers

Did you try py-beginning-of-def-or-class?

(defun python-show-function-name()
  "Message the name of the function the point is in"
  (interactive)
  (save-excursion
    (py-beginning-of-def-or-class)
    (message (format "%s" (thing-at-point 'line)))))

I find it gives me better results than your beginning-of-defun, but if that's not the problem you're having, then maybe I'm just seeing another symptom of the cause of the wonkiness in my other answer.

like image 92
Blair Conrad Avatar answered Oct 30 '22 05:10

Blair Conrad