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: Sun, 17 Jun 2012 07:33:13 +0900 (JST) Organization: Red Hat Japan, Inc. Message-ID: <20120617.073313.1303392924099989359.yamato@redhat.com> References: <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 1339886048 6069 80.91.229.3 (16 Jun 2012 22:34:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 16 Jun 2012 22:34:08 +0000 (UTC) Cc: 11711@debbugs.gnu.org, smerten@oekonux.de To: monnier@iro.umontreal.ca Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 17 00:34:06 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 1Sg1ZC-0006n2-1G for geb-bug-gnu-emacs@m.gmane.org; Sun, 17 Jun 2012 00:34:02 +0200 Original-Received: from localhost ([::1]:60560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sg1ZB-00055e-Mm for geb-bug-gnu-emacs@m.gmane.org; Sat, 16 Jun 2012 18:34:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sg1Z8-00055K-BN for bug-gnu-emacs@gnu.org; Sat, 16 Jun 2012 18:33:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sg1Z6-0006xG-DC for bug-gnu-emacs@gnu.org; Sat, 16 Jun 2012 18:33:57 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sg1Z6-0006xA-81 for bug-gnu-emacs@gnu.org; Sat, 16 Jun 2012 18:33:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Sg1c6-0008GV-DT for bug-gnu-emacs@gnu.org; Sat, 16 Jun 2012 18: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 Resent-Date: Sat, 16 Jun 2012 22: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: patch Original-Received: via spool by 11711-submit@debbugs.gnu.org id=B11711.133988619031729 (code B ref 11711); Sat, 16 Jun 2012 22:37:02 +0000 Original-Received: (at 11711) by debbugs.gnu.org; 16 Jun 2012 22:36:30 +0000 Original-Received: from localhost ([127.0.0.1]:45222 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sg1bZ-0008Fh-Lw for submit@debbugs.gnu.org; Sat, 16 Jun 2012 18:36:30 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:25612) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sg1bV-0008FW-Dz for 11711@debbugs.gnu.org; Sat, 16 Jun 2012 18:36:27 -0400 Original-Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5GMXGh9023641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 16 Jun 2012 18:33:16 -0400 Original-Received: from localhost (vpn-233-239.phx2.redhat.com [10.3.233.239]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q5GMXEL5005555; Sat, 16 Jun 2012 18:33:15 -0400 In-Reply-To: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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:61043 Archived-At: Thank you for reviewing. >> 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. > > I'll let the other Stefan decide what to do with it. It looks > pretty good for me. Just a few nitpicks below: I found I should explain more about to the maintainer. I know `rst-toc'. People who writes a document in rst format may use `rst-toc' instead of imenu. However, there is a reason I write this patch. Sometime I read document writtn in rst file by my colleagues(on emacs running on a terminal). In such case `which-func' helps me to understand the document; and `which-func' uses imenu internally. >> + ;; 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. > > Try to punctuate your comments. > >> +(defun rst-imenu-find-adornments-for-position (adornments p) >> + "Find adornments cell for position P in ADORNMENTS" > > And do punctuate your docstring (C-u M-x checkdoc-current-buffer RET > might help you catch such things). > > > Stefan Thanks. Here is revised version. 2012-06-16 Masatake YAMATO * 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-16 22:31:55 +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-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)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generic text functions that are more convenient than the defaults.