7.24 Context Menu

In addition to the keybindings that Sweep provides for invoking its commands, it integrates with Emacs’s standard Context Menu minor mode to provide contextual menus that you interact with using the mouse.

Command: context-menu-mode

Toggle Context Menu mode. When enabled, clicking the mouse button down-mouse-3 (meaning “right-click”) activates a menu whose contents depend on its surrounding context.

Variable: sweeprolog-context-menu-functions

List of functions that create Context Menu entries for Prolog tokens. Each function should receive as its arguments the menu that is being created, the Prolog token’s description, its start position, its end position, and the position of the mouse click. It should alter the menu according to that context.

To enable Context Menu mode, type M-x context-menu-mode RET. To have Context Menu mode enabled automatically when Emacs starts, place a call to (context-menu-mode) in your Emacs initialization file. You can access the context menu by right-clicking anywhere in Emacs. If you do it in a Sweep Prolog mode buffer, you can invoke several Prolog-specific commands based on where you click in the buffer.

If you right-click on a Prolog file specification or module name, Sweep suggests visiting it either in the current window or in another. If you right-click on a predicate, it lets you view its documentation in a dedicated buffer (see Prolog Help). For variables, it enables the ‘Rename Variable’ menu entry that you can use to rename the variable you click on across its containing clause (see Renaming Variables).

You can further extend and customize the context menu that Sweep Prolog mode provides by adding functions to the variable sweeprolog-context-menu-functions. Each function on this list receives the menu that is being created and a description of the clicked Prolog token, and it can extend the menu with entries before Emacs displays the menu.