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: Tue, 19 Jun 2012 12:33:25 +0900 (JST) Organization: Red Hat Japan, Inc. Message-ID: <20120619.123325.666872936278948401.yamato@redhat.com> References: <20120615.041527.616439723447762585.yamato@redhat.com> <6712.1340013440@theowa.merten-home.homelinux.org> 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 1340076833 27766 80.91.229.3 (19 Jun 2012 03:33:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2012 03:33:53 +0000 (UTC) Cc: 11711@debbugs.gnu.org To: smerten@oekonux.de Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 19 05:33:52 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 1SgpCQ-0000fB-1U for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jun 2012 05:33:50 +0200 Original-Received: from localhost ([::1]:45515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgpCQ-0001Xh-1O for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Jun 2012 23:33:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgpCM-0001XQ-QA for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2012 23:33:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgpCK-0002Re-Kq for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2012 23:33:46 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgpCK-0002RW-I7 for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2012 23:33:44 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SgpFW-0007Nu-Cf; Mon, 18 Jun 2012 23:37: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, Stefan Merten Resent-Date: Tue, 19 Jun 2012 03:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11711 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed X-Debbugs-Original-Cc: 11711@debbugs.gnu.org, bug-gnu-emacs@gnu.org Original-Received: via spool by 11711-submit@debbugs.gnu.org id=B11711.134007701428370 (code B ref 11711); Tue, 19 Jun 2012 03:37:02 +0000 Original-Received: (at 11711) by debbugs.gnu.org; 19 Jun 2012 03:36:54 +0000 Original-Received: from localhost ([127.0.0.1]:47568 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SgpFN-0007NX-LJ for submit@debbugs.gnu.org; Mon, 18 Jun 2012 23:36:54 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:10771) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SgpFK-0007NN-Rt for 11711@debbugs.gnu.org; Mon, 18 Jun 2012 23:36:52 -0400 Original-Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5J3XTar016485 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Jun 2012 23:33:30 -0400 Original-Received: from localhost (dhcp-193-19.nrt.redhat.com [10.64.193.19]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q5J3XQJI014570; Mon, 18 Jun 2012 23:33:28 -0400 In-Reply-To: <6712.1340013440@theowa.merten-home.homelinux.org> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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:61097 Archived-At: > Hi Masatake! > > 4 days ago Masatake YAMATO wrote: >> This is not a bug report. This is a request to merge a patch >> to the offcial source tree. > > There seem to be some functions missing. From the byte-compiler: > > rst.el:4263:1:Warning: the following functions are not known to be defined: > rst-imenu-find-adornment-for-position, rst-imenu-index0 I'm very sorry. I' am ashamed. Revised patch is here. 2012-06-16 Masatake YAMATO redhat.com> * textmodes/rst.el (rst-mode): Added imenu and which-func supports. (rst-imenu-find-adornments-for-position): New function. (rst-imenu-convert-cell): Ditto. (rst-imenu-index): Ditto. === modified file 'lisp/textmodes/rst.el' --- lisp/textmodes/rst.el 2012-06-07 09:20:41 +0000 +++ lisp/textmodes/rst.el 2012-06-19 02:48:16 +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,64 @@ ;; output. )) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Imenu support +(defun rst-imenu-find-adornments-for-position (adornments p) + "Find adornments cell in ADORNMENTS for position P." + (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 a cell ELT in a tree returned from `rst-section-tree' to imenu index. +ADORNMENTS is used as hint information for conversion." + (let* ((kar (car elt)) + (kdr (cdr elt)) + (title (car kar))) + (if kar + (let* ((p (marker-position (cadr kar))) + (adornments (rst-imenu-find-adornments-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-convert-cell 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)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generic text functions that are more convenient than the defaults.