From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: Which Function mode and Python mode Date: Sat, 30 Jun 2007 01:10:12 +0300 Message-ID: <200706300110.12506.pogonyshev@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1183154515 582 80.91.229.12 (29 Jun 2007 22:01:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 29 Jun 2007 22:01:55 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 30 00:01:54 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I4OXI-0008DD-ME for ged-emacs-devel@m.gmane.org; Sat, 30 Jun 2007 00:01:52 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4OXI-00041L-BC for ged-emacs-devel@m.gmane.org; Fri, 29 Jun 2007 18:01:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I4OS2-0003Ie-BP for emacs-devel@gnu.org; Fri, 29 Jun 2007 17:56:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I4OS1-0003Hh-R8 for emacs-devel@gnu.org; Fri, 29 Jun 2007 17:56:25 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4OS1-0003HZ-H6 for emacs-devel@gnu.org; Fri, 29 Jun 2007 17:56:25 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1I4OS0-0003Q6-V6 for emacs-devel@gnu.org; Fri, 29 Jun 2007 17:56:25 -0400 Original-Received: (qmail invoked by alias); 29 Jun 2007 21:56:22 -0000 Original-Received: from unknown (EHLO [80.94.230.116]) [80.94.230.116] by mail.gmx.net (mp032) with SMTP; 29 Jun 2007 23:56:22 +0200 X-Authenticated: #16844820 X-Provags-ID: V01U2FsdGVkX19atN1nHRRaELS6Fvj1hnopv8qK969Mhwq2NBIevF yzfDmt98WUogJW User-Agent: KMail/1.7.2 Content-Disposition: inline X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:74045 Archived-At: 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 * 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."