Next: , Previous: Extending versor, Up: Extending versor



10.1 Notes on the internals of Versor

The following notes are derived from the reply to a question about adding an emacspeak interface to Versor.

Most versor commands have a macro wrapped around most of the command, either versor-as-versor-command or versor-as-motion-command, both defined in versor-commands.el.

versor-as-versor-command is a recent hack to let me turn versor off quickly, thus making eligible to be a minor mode; if versor-mode is nil, it just looks for whatever was previously on the key that triggered this command, and runs that instead.

More interesting is versor-as-motion-command (probably a bit of a misnomer by now) which is what updates the versor selection highlight at the end of each command. To do this, it calls versor-clear-current-item-indication before running the main logic of the command, to get rid of the old highlight, then after running the command-specific code that it is wrapped around, it calls versor-indicate-current-item, which does the complicated bit. After that, it runs any functions on versor-post-command-hook.

versor-indicate-current-item is probably the thing to advise, but I'm happy to include emacspeak-specific code in it. It first checks whether the internal variables indicating the selection have been set (by the command-specific logic calling versor-set-current-item, or versor-set-current-items if it is a multi-part selection); if they haven't, it uses a heuristic to set them, again using versor-indicate-current-item, which is what generates the colourful overlays.

Then it (versor-indicate-current-item) calls versor-describe-selection on the selection, which gets a description of the selection, puts it in the echo area, and calls versor-speak, which is my rudimentary attempt to interface to emacspeak.

I'm already planning to upgrade versor-describe-selection (which is part of languide) to give more information. From the versor / languide point of view, it is probably the best place to get more spoken information.

As it stands now, it calls some mode-specific stuff (using modal-functions.el, which is part of the download) to discover stuff about the specified part of a buffer. Each mode's definition (see languide-lisp-like.el, languide-c-like.el for the current support) defines a function languide-region-type which returns things like if-then-body, if-then-else-tail, progn-whole, while-do-head, defun-body, to describe the specified text. languide-region-type can also set the variable languide-region-detail-string to give more information. region-type-description converts the result of languide-region-type into human-readable text.

There is another function which could be used to give more information that should probably be spoken, which is establish-current-statement, which works out the statement type at point. If languide-region-type says that the text is a single statement, establish-current-statement could be used to tell you what the statement is; if it is multiple statements, it could be used several times, to describe the region (or selection when used by versor) succintly.


SourceForge.net Logo