Simon Wright <[email protected]> writes:
> 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)))
At this point, you can do:
(looking-at (buffer-substring (point) (+ (point) (wisi-cache-last cache))))
But I see this hits references to names, as well as declarations of names.
So you want to use the "containing" links in the wisi caches to check
for declarations:
(let* ((cache (wisi-backward-find-class 'name))
(containing (wisi-goto-containing cache)))
(when containing
(ecase (wisi-containing-token)
((PROCEDURE FUNCTION)
...
You can use `ada-wisi-debug-keys' to define some keys that are useful
for navigating around caches; M-H goes from a cache to its container.
Hmm. That's still very low level. I think you can just use
"ada-goto-declaration-start" to move from one declaration to the
previous, and skip the intervening names.
Except that skips types; we could enhance it to include those.
Or you can do the low level search; look at goto-declaration-start for
ideas on how to handle various syntax.
To handle the outer package, you'll have to move up one line at a time
from the end until you find something new.
> 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?
Maybe you need a "save-excursion" around the goto's after the search, so
the search starts again from the right place.
> 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!
That's a bug. That cache is missing a containing entry, as you can see
with M-J (with point on the name). Here's a patch:
--- ada-grammar.wy c58d885764d7918d16bf5992ec88d36055de39a7
+++ ada-grammar.wy 64f01cdd70c83dea1cdd7a87b4135bfdfde4ec7d
@@ -1625,6 +1625,7 @@ package_body
(wisi-containing-action 3 4)
(wisi-containing-action 5 6)
(wisi-containing-action 7 8)
+ (wisi-containing-action 9 10)
(wisi-motion-action [1 5 7 [8 block-middle EXCEPTION block-middle WHEN]
9])
(wisi-face-action [3 font-lock-function-name-face 10
font-lock-function-name-face]))
| PACKAGE BODY name aspect_specification_opt IS declarative_part_opt END
name_opt SEMICOLON
@@ -1633,6 +1634,7 @@ package_body
(wisi-containing-action 1 3)
(wisi-containing-action 3 4)
(wisi-containing-action 5 6)
+ (wisi-containing-action 7 8)
(wisi-motion-action [1 5 7])
(wisi-face-action [3 font-lock-function-name-face 8
font-lock-function-name-face]))
;
> How do I get the buffer to be parsed before starting the search?
(wisi-validate-cache (point-max))
> 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?
Why?
This needs a comment, but I believe it runs syntax-ppss after
ada-mode-hook in case the hook changes the syntax table; for example, to
change "_" from symbol to word.
--
-- Stephe
_______________________________________________
Emacs-ada-mode mailing list
[email protected]
http://host114.hostmonster.com/mailman/listinfo/emacs-ada-mode_stephe-leake.org