From: Masatake YAMATO <yamato@redhat.com>
To: smerten@oekonux.de
Cc: 11711@debbugs.gnu.org
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) [thread overview]
Message-ID: <20120619.123325.666872936278948401.yamato@redhat.com> (raw)
In-Reply-To: <6712.1340013440@theowa.merten-home.homelinux.org>
> 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 <yamato <at> 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))))
+
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generic text functions that are more convenient than the defaults.
prev parent reply other threads:[~2012-06-19 3:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-14 19:15 bug#11711: 24.0.95; [PATCH] added imenu and which-func support to rst.el Masatake YAMATO
2012-06-15 1:46 ` Stefan Monnier
2012-06-16 22:33 ` Masatake YAMATO
2012-06-18 1:59 ` Stefan Monnier
2012-06-18 9:28 ` Stefan Merten
2012-06-18 9:44 ` Stefan Merten
2012-06-18 19:25 ` Stefan Monnier
2012-06-18 9:57 ` Stefan Merten
2012-06-19 3:33 ` Masatake YAMATO [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120619.123325.666872936278948401.yamato@redhat.com \
--to=yamato@redhat.com \
--cc=11711@debbugs.gnu.org \
--cc=smerten@oekonux.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.