From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.bugs Subject: bug#11711: 24.0.95; [PATCH] added imenu and which-func support to rst.el Date: Fri, 15 Jun 2012 04:15:27 +0900 (JST) Organization: Red Hat Japan, Inc. Message-ID: <20120615.041527.616439723447762585.yamato@redhat.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1339701382 30769 80.91.229.3 (14 Jun 2012 19:16:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 14 Jun 2012 19:16:22 +0000 (UTC) To: 11711@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 14 21:16:21 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SfFWg-0001eN-O4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jun 2012 21:16:14 +0200 Original-Received: from localhost ([::1]:45678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFWg-000873-By for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jun 2012 15:16:14 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFWc-00086n-O5 for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:16:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfFWa-0006Sk-Sq for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:16:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFWa-0006Sg-Ow for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:16:08 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SfFZO-0003tl-JB for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Masatake YAMATO Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Jun 2012 19:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11711 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.133970151614944 (code B ref -1); Thu, 14 Jun 2012 19:19:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Jun 2012 19:18:36 +0000 Original-Received: from localhost ([127.0.0.1]:42635 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SfFYx-0003sz-GX for submit@debbugs.gnu.org; Thu, 14 Jun 2012 15:18:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50014) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SfFYu-0003sr-8t for submit@debbugs.gnu.org; Thu, 14 Jun 2012 15:18:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfFW3-0006PE-Ut for submit@debbugs.gnu.org; Thu, 14 Jun 2012 15:15:37 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:55245) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFW3-0006P7-Rb for submit@debbugs.gnu.org; Thu, 14 Jun 2012 15:15:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFW2-00086A-3K for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:15:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfFW0-0006OS-4X for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:15:33 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:17718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfFVz-0006Mx-Rx for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2012 15:15:32 -0400 Original-Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5EJFTMm005030 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Jun 2012 15:15:29 -0400 Original-Received: from localhost (vpn-233-203.phx2.redhat.com [10.3.233.203]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5EJFS4Z021853 for ; Thu, 14 Jun 2012 15:15:29 -0400 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60981 Archived-At: This is not a bug report. This is a request to merge a patch to the offcial source tree. 2012-06-13 Masatake YAMATO * textmodes/rst.el (rst-mode, rst-imenu-index): Added imenu and which-func support. === modified file 'lisp/textmodes/rst.el' --- lisp/textmodes/rst.el 2012-06-07 09:20:41 +0000 +++ lisp/textmodes/rst.el 2012-06-13 17:16:13 +0000 @@ -794,6 +794,13 @@ (set (make-local-variable 'uncomment-region-function) 'rst-uncomment-region) + ;; Imenu + (set (make-local-variable 'imenu-create-index-function) 'rst-imenu-index) + + ;; Which func + (when (and (boundp 'which-func-modes) (listp which-func-modes)) + (add-to-list 'which-func-modes 'rst-mode)) + ;; Font lock. (set (make-local-variable 'font-lock-defaults) '(rst-font-lock-keywords @@ -4088,6 +4095,63 @@ ;; output. )) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Imenu support +(defun rst-imenu-find-adornments-for-position (adornments p) + "Find adornments cell for position P in ADORNMENTS" + (let ((a nil)) + (while adornments + (if (and (car adornments) + (eq (car (car adornments)) p)) + (setq a adornments + adornments nil) + (setq adornments (cdr adornments)))) + a)) + +(defun rst-imenu-convert-cell (elt adornments) + "Convert adornment cell to imenu index" + (let* ((kar (car elt)) + (kdr (cdr elt)) + (title (car kar))) + (if kar + (let* ((p (marker-position (cadr kar))) + (adornments (rst-imenu-find-adornment-for-position adornments p)) + (a (car adornments)) + (adornments (cdr adornments)) + (title (format "%s%s%s" + (make-string (1+ (nth 3 a)) (nth 1 a)) + title + (if (eq (nth 2 a) 'simple) + "" + (char-to-string (nth 1 a)))))) + (cons title + (if (null kdr) + p + (cons + ;; A bit ugly but this make which-func happy. + (cons title p) + (mapcar (lambda (elt0) + (rst-imenu-index0 elt0 adornments)) + kdr))))) + nil))) + +(defun rst-imenu-index () + "Create index for imenu." + (rst-reset-section-caches) + (let ((tree (rst-section-tree)) + ;; Translate line notation to point notion + (adornments (save-excursion + (mapcar (lambda (a) + (cons (progn + (goto-char (point-min)) + (forward-line (1- (car a))) + (point)) + (cdr a))) + (rst-find-all-adornments))))) + (delete nil (mapcar (lambda (elt) + (rst-imenu-convert-cell elt adornments)) + tree)))) +