help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Listing headings in dedicated buffer with imenu.


From: Stephen Berman
Subject: Re: Listing headings in dedicated buffer with imenu.
Date: Mon, 29 Jul 2024 12:32:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

On Mon, 29 Jul 2024 10:26:22 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Monday, July 29th, 2024 at 9:33 PM, Stephen Berman 
> <stephen.berman@gmx.net> wrote:
>
>> On Mon, 29 Jul 2024 08:48:38 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > I wish to list headings in a dedicated buffer with imenu.
>> > The listing should be in the order in which headings occur
>> > in the buffer.
>> >
>> > Have done the following, but the buffer ends up empty.
>> >
>> > (defun vodil-imenu-bfh ()
>> > "Insert imenu headings in order in a dedicated buffer."
>> > (interactive)
>> >
>> > (let ((imenu-items (imenu--make-index-alist t))
>> > (buffer-name "Imenu Headings"))
>> > (with-current-buffer (get-buffer-create buffer-name)
>> > (erase-buffer)
>> > (dolist (item imenu-items)
>> > (let ((name (car item))
>> > (position (cdr item)))
>> > (when (and (stringp name) (number-or-marker-p position))
>> > (insert (format "%s\n" name)))))
>> > (goto-char (point-min)))
>> > (pop-to-buffer buffer-name)))
>>
>>
>> It works for me, as long as imenu.el is loaded.
>>
>> Steve Berman
>
> What would I need to load it ?

One way is this:

(defun vodil-imenu-bfh ()
  "Insert imenu headings in order in a dedicated buffer."
  (interactive)
  (eval-when-compile
    (require 'imenu))
  (let ((imenu-items (imenu--make-index-alist t))
        (buffer-name "*Imenu Headings*"))
    (with-current-buffer (get-buffer-create buffer-name)
      (erase-buffer)
      (dolist (item imenu-items)
        (let ((name (car item))
              (position (cdr item)))
          (when (and (stringp name) (number-or-marker-p position))
            (insert (format "%s\n" name)))))
      (goto-char (point-min)))
    (pop-to-buffer buffer-name)))

Steve Berman



reply via email to

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