emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] scratch/rfc-mode bec092989b 30/52: Add imenu support for rfc-mo


From: Stefan Monnier
Subject: [nongnu] scratch/rfc-mode bec092989b 30/52: Add imenu support for rfc-mode
Date: Wed, 12 Oct 2022 16:29:20 -0400 (EDT)

branch: scratch/rfc-mode
commit bec092989b1d1696555e5c0f2e00d87058e08137
Author: Daniel Martín <mardani29@yahoo.es>
Commit: Nicolas Martyanoff <khaelin@gmail.com>

    Add imenu support for rfc-mode
    
    * rfc-mode.el (rfc-mode-imenu-title): Customizable variable to set the
    menu bar title for imenu.
    (rfc-mode-title-regexp): Extracted regular expression to identify RFC
    section titles.
    (rfc-mode-init): Configure imenu and add it to the menu bar.
    (rfc-mode-highlight): Use the extracted regular expression to identify
    RFC section titles.
---
 rfc-mode.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/rfc-mode.el b/rfc-mode.el
index 86a0cb2117..cb64693b3f 100644
--- a/rfc-mode.el
+++ b/rfc-mode.el
@@ -81,11 +81,19 @@ Assume RFC documents are named as e.g. rfc21.txt, 
rfc-index.txt."
   "The width of the column containing RFC titles in the browser."
   :type 'integer)
 
+(defcustom rfc-mode-imenu-title "RFC Contents"
+  "The title to use if `rfc-mode' adds a RFC Contents menu to the menubar."
+  :type 'string
+  :group 'rfc-mode-group)
+
 ;;; Misc variables:
 
 (defvar rfc-mode-index-entries nil
   "The list of entries in the RFC index.")
 
+(defconst rfc-mode-title-regexp "^\\(?:[0-9]+\\.\\)+\\(?:[0-9]+\\)? .*$"
+  "Regular expression to model section titles in RFC documents.")
+
 ;;; Keys:
 
 (defvar rfc-mode-map
@@ -102,7 +110,9 @@ Assume RFC documents are named as e.g. rfc21.txt, 
rfc-index.txt."
 (defun rfc-mode-init ()
   "Initialize the current buffer for `rfc-mode'."
   (setq-local page-delimiter "^.*?\n")
-  (rfc-mode-highlight))
+  (rfc-mode-highlight)
+  (setq imenu-generic-expression (list (list nil rfc-mode-title-regexp 0)))
+  (imenu-add-to-menubar rfc-mode-imenu-title))
 
 (defun rfc-mode-quit ()
   "Quit the current window and bury its buffer."
@@ -173,7 +183,7 @@ Assume RFC documents are named as e.g. rfc21.txt, 
rfc-index.txt."
       ;; Section titles
       (save-excursion
         (goto-char (point-min))
-        (while (search-forward-regexp "^\\(?:[0-9]+\\.\\)+\\(?:[0-9]+\\)? .*$" 
nil t)
+        (while (search-forward-regexp rfc-mode-title-regexp nil t)
           (let ((start (match-beginning 0))
                 (end (match-end 0)))
             (put-text-property start end



reply via email to

[Prev in Thread] Current Thread [Next in Thread]