[comp.emacs] Mode-specific suntools menu in Gnu emacs - answers

dwiggins@atsun.a-t.com (Don Dwiggins) (02/03/90)

I posted a request for information on this subject; and got several replies.
Various approaches were suggested, but the reply that really got me started
was this:

    From: Stan Jefferson <sjeff@iuvax.cs.indiana.edu>
    
	This is in reply to your question about mode-dependent mouse bindings.
	I was the principle author of the sun-mouse.el and sun-fns.el.  It is
	NOT necessary to make any changes to have mode-dependent mouse
	bindings; the following functions are analogues of the functions for
	local key bindings and will give you mode-dependent mouse bindings:
	
	  make-mousemap, local-set-mouse, use-local-mousemap
	  
	I can send you an example if you have further problems.
	
	- Stan Jefferson

Based on this, I put the following into a file that gets loaded at startup:

;; Set up local mouse map to show the local menu
(require 'sun-fns)
(local-set-mouse '(text right)  'local-mode-menu-eval)
(setq-default current-local-mousemap current-local-mousemap)

;; Local menu; to be set by mode hooks
(make-variable-buffer-local 'current-local-menu)
(setq-default current-local-menu nil)

;; Cribbed from "emacs-menu-eval" in sun-fns.el
(defun local-mode-menu-eval (window x y)
  "Pop up mode-specific menu of editor commands (if defined for mode)"
  (sun-menu-evaluate window (1+ x) (1- y)
                     (cond ((null current-local-menu) 'emacs-menu)
                           (t current-local-menu))))

;; Menus for popular modes, and the hooks to set them up
(defmenu GNUS-Newsgroup-menu
  ("GNUS Newsgroup Mode")
  ("Select unread articles" gnus-Group-select-group nil)
  ("Select all articles" gnus-Group-select-group 1)
  ("Compose article" gnus-Group-post-news)
  ("Unsubscribe/resubscribe" gnus-Group-unsubscribe-current-group)
  ("Check bogus groups" gnus-Group-check-bogus-groups)
  ("Update group list" (lambda ()
                         (gnus-Group-get-new-news) (gnus-Group-force-update)))
  ("Restart GNUS" gnus-Group-restart)
  ("Global Menu" . emacs-menu))
(setq gnus-Group-mode-hook
            '(lambda () (setq current-local-menu 'GNUS-Newsgroup-menu)))

... and so on for other modes.  Generally, I put into a menu those commands
that I only use occasionally, and tend to forget; once a key sequence is
memorized, it's much faster.

Finally, thanks to Stan and all the other folks who replied.
--
Don Dwiggins				"Solvitur Ambulando"
Ashton-Tate, Inc.
dwiggins@ashtate.a-t.com