unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Which Function mode and Python mode
@ 2007-06-29 22:10 Paul Pogonyshev
  2007-06-30 18:31 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Pogonyshev @ 2007-06-29 22:10 UTC (permalink / raw)
  To: emacs-devel

Hi,

This short patch adds support for Which Function minor mode to Python
mode.  It also adds Python mode to the default list of modes where
Which Function mode is in effect.

Paul


2007-06-29  Paul Pogonyshev  <pogonyshev@gmx.net>

	* progmodes/which-func.el (which-func-modes): Add `python-mode'.

	* progmodes/python.el (python-def-or-class-regexp): New defconst.
	(python-which-func): New function.
	(python-mode): Hook it up to `which-func-functions'.


Index: lisp/progmodes/python.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/python.el,v
retrieving revision 1.62
diff -u -p -r1.62 python.el
--- lisp/progmodes/python.el	14 Jun 2007 00:11:40 -0000	1.62
+++ lisp/progmodes/python.el	29 Jun 2007 21:52:14 -0000
@@ -996,6 +996,27 @@ don't move and return nil.  Otherwise re
 			  (throw 'done t)))))))
       (setq arg (1- arg)))
     (zerop arg)))
+
+(defconst python-def-or-class-regexp
+  (rx (0+ blank) (or "def" "class") (1+ blank)
+      (group symbol-start (+? nonl) symbol-end))
+  "Regular expression matching function or class definition.")
+
+(defun python-which-func ()
+  (let ((components nil))
+    (save-excursion
+      (beginning-of-line)
+      (when (looking-at python-def-or-class-regexp)
+	(setq components (list (match-string-no-properties 1))))
+      (while (python-beginning-of-block)
+	(if (looking-at python-def-or-class-regexp)
+	    (setq components (cons (match-string-no-properties 1) components)))))
+    (when components
+      (apply 'concat
+	     (car components)
+	     (mapcar (lambda (component)
+		       (concat "." component))
+		     (cdr components))))))
  
 ;;;; Imenu.
 
@@ -2248,6 +2269,7 @@ with skeleton expansions for compound st
   (set (make-local-variable 'beginning-of-defun-function)
        'python-beginning-of-defun)
   (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
+  (add-hook 'which-func-functions 'python-which-func nil t)
   (setq imenu-create-index-function #'python-imenu-create-index)
   (set (make-local-variable 'eldoc-documentation-function)
        #'python-eldoc-function)
Index: lisp/progmodes/which-func.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/which-func.el,v
retrieving revision 1.17
diff -u -p -r1.17 which-func.el
--- lisp/progmodes/which-func.el	21 Jan 2007 03:20:44 -0000	1.17
+++ lisp/progmodes/which-func.el	29 Jun 2007 21:52:14 -0000
@@ -76,8 +76,8 @@
   :version "20.3")
 
 (defcustom which-func-modes
-  '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode makefile-mode
-		    sh-mode fortran-mode f90-mode ada-mode)
+  '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode
+		    makefile-mode sh-mode fortran-mode f90-mode ada-mode)
   "List of major modes for which Which Function mode should be used.
 For other modes it is disabled.  If this is equal to t,
 then Which Function mode is enabled in any major mode that supports it."

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-07-12  4:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-29 22:10 Which Function mode and Python mode Paul Pogonyshev
2007-06-30 18:31 ` Stefan Monnier
2007-06-30 21:11   ` Paul Pogonyshev
2007-07-01  2:01     ` Stefan Monnier
2007-07-01 11:09       ` Paul Pogonyshev
2007-07-12  4:37         ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).