On 18 Nov 2015, at 16:54, Stephen Leake <[email protected]> wrote:
>
> I would start by searching backward for class "name", then find out what
> kind of name it is (typically by wisi-goto-statement-start, check the
> token there), to see how to put it into imenu.
>
> (going out on a limb) There's no reason not to include all names in
> imenu.
>
> Well, perhaps only "file top-level" names, but I'm not sure that's easy
> to determine via the grammar.
>
> I'd start with "all names" and see if that's too many.
So far I have
(defun ada--imenu-find-menu-element ()
(let ((cache (wisi-backward-find-class 'name))
(start (point)))
(wisi-goto-statement-end)
(wisi-goto-statement-start)
(wisi-forward-find-class 'name start)
(looking-at "[A-Za-z0-9_]+")))
(defun wisi-backward-find-class (class)
"Search backward for a token that has a cache with CLASS.
Return cache, or nil if at start of buffer."
(let ((cache (wisi-backward-cache)))
(while (not (eq class (wisi-cache-class cache)))
(setq cache (wisi-backward-cache)))
cache))
Aside from the problem that I have yet to determine how to get
'wisi-backward-find-class' to return nil if at bob, and to fix so that
'ada--imenu-find-menu-element' takes account of this, there are some features:
I don't think imenu copes with nested entities; I suspect that when it starts
from point-max and finds a menu entry at p, it looks for the next (well,
previous) entry starting at p-1 (or possibly at the beginning of that line?).
This is an issue for the design above, because the only thing it will see is
the outermost entity (e.g. the package!). Could skip back (2?) tokens if point
is point-max?
The reason for going to statement-end before statement-start is that if point
is on the F of 'end Finalize;' then 'wisi-goto-statement-start' leaves point
unchanged!
How do I get the buffer to be parsed before starting the search? at present we
have (at end of 'ada-mode')
(run-mode-hooks 'ada-mode-hook)
;; If global-font-lock is not enabled, ada-syntax-propertize is
;; not run when the text is first loaded into the buffer. Recover
;; from that.
(syntax-ppss-flush-cache (point-min))
(syntax-propertize (point-max))
(add-hook 'hack-local-variables-hook 'ada-mode-post-local-vars nil t)
)
Would it make sense to move the two syntax-* calls before the run-mode-hooks?
_______________________________________________
Emacs-ada-mode mailing list
[email protected]
http://host114.hostmonster.com/mailman/listinfo/emacs-ada-mode_stephe-leake.org