MicroEmacs / Macros-Imenu

Motivation

Providing an Emacs like imenu command for MicroEmacs.

imenu.emf is an macro simliar to the emacs imenu. You must save the file imenu.emf to your microemacs/user directory and add the lines:

define-macro-file imenu imenu
define-macro-file imenu imenu-refresh

to your user.emf-file in order to invoke imenu. If you want to redefine the indexing schema you must invoke imenu-refresh.

; imenu.emf
define-macro imenu 

    ; i use a high number trying not to disturb the original .osd.next variable
    ; hopefully that your session will not be to long
    set-variable #l0 10000 ; dangerous is somebody is building here an other osd
    set-variable #l1 1 ; osd incrementor for item-additions
    !if &or &not &exists :index-string &not @# ; then ask for a new one
        set-variable :index-string @ml "index what"
    !endif
    ; at first destroy possible old items
    set-variable #l5 40  ; let's say there is a max of 40 items
    !while &great #l5 1
        -1 osd #l0
        set-variable #l5 &dec #l5 1
    !done
    ; constant osd
    osd #l0 0   "b"
    set-alpha-mark "p"
    beginning-of-buffer
    !force search-forward :index-string
    !while $status
        beginning-of-line
        set-mark
        2 forward-word
        exchange-point-and-mark
        copy-region
        set-variable #l2 @y
        -1 yank
        end-of-line
        osd #l0 &pinc #l1 1 "" &cat &cat &cat &cat "|"   #l2  "   |" $window-line "|" f  imenu-osd-goto-line
        !force search-forward :index-string
    !done
    goto-alpha-mark "p"
    #l0 osd 0 "ba" &add $cursor-x 1 &sub $cursor-y 1
!emacro

0 define-macro imenu-osd-goto-line
    ; fetch the line number and goto
    goto-line &lget $result 2
!emacro