From xemacs-m  Thu Jan  9 23:14:28 1997
Received: from atreides.mindspring.com (atreides.mindspring.com [204.180.142.236])
          by xemacs.cs.uiuc.edu (8.8.4/8.8.4) with SMTP
	  id XAA22264 for <xemacs-beta@xemacs.org>; Thu, 9 Jan 1997 23:14:28 -0600 (CST)
Received: (qmail 15338 invoked by uid 52477); 10 Jan 1997 05:14:23 -0000
Sender: sj@atreides.mindspring.com
To: XEmacs beta <xemacs-beta@xemacs.org>
Subject: Re: cperl and imenu
References: <xcdybe22l46.fsf@gargoyle164.cs.uchicago.edu>
Mime-Version: 1.0 (generated by tm-edit 7.100)
Content-Type: text/plain; charset=US-ASCII
From: Sudish Joseph <sudish@mindspring.com>
Date: 10 Jan 1997 00:14:23 -0500
In-Reply-To: Soren Dayton's message of 09 Jan 1997 22:46:17 -0600
Message-ID: <yviavi962jtc.fsf@atreides.mindspring.com>
Lines: 172
X-Mailer: Red Gnus v0.79/XEmacs 20.0

Soren Dayton writes:
> I noticed that porting cperl was on the list of things `todo' on the
> `beta' web page.  I also noticed it in the 20-b34 distribution.  Has
> this been done?  If so, can we revisit it (because imenu does not work.
> something involving the gnu variable `last-nonmenu-event' most of it
> looks straightforward, but at one point cperl sets this).  if not, I
> would like to do this.

I started on an imenu port last weekend, but ran out of weekend.  The
mouse-specific code is done.  What remains is to modify the code that
dynamically creates the Imenu menu entry to use XEmacs's :filter stuff.
Imenu uses the GNU Emacs keymap/menu equivalence, so this part entails
some work.

Also, under GNU Emacs each mode contains the stuff needed to get imenu
to work in that mode.  Under XEmacs, that stuff is commented out in
modes that have been synched.  I was using lisp-mode to test stuff,
the patch is trivial and included below.

I don't think I'll be able to continue this weekend; if you do plan to
do this, the patch below might be useful.

-Sudish

--- /home/sj/src/xemacs/lisp/modes/imenu.el	Fri Jan 10 00:06:58 1997
+++ /home/sj/xemacs/site-lisp/imenu/imenu.el	Fri Jan 10 00:06:58 1997
@@ -758,21 +758,21 @@
 
 The returned value is on the form (INDEX-NAME . INDEX-POSITION)."
   (let (index-alist
-	(mouse-triggered (listp last-nonmenu-event))
+	(mouse-triggered (mouse-event-p current-mouse-event))
 	(result t) )
     ;; If selected by mouse, see to that the window where the mouse is
     ;; really is selected.
     (and mouse-triggered
-	 (not (equal last-nonmenu-event '(menu-bar)))
-	 (let ((window (posn-window (event-start last-nonmenu-event))))
+	 (let ((window (event-window current-mouse-event)))
 	   (or (framep window) (null window) (select-window window))))
     ;; Create a list for this buffer only when needed.
     (while (eq result t)
       (setq index-alist (if alist alist (imenu--make-index-alist)))
       (setq result
-	    (if (and mouse-triggered
-		     (not imenu-always-use-completion-buffer-p))
-		(imenu--mouse-menu index-alist last-nonmenu-event)
+	    (if (and (not imenu-always-use-completion-buffer-p)
+		     (or mouse-triggered
+			 (misc-user-event-p current-mouse-event)))
+		(imenu--mouse-menu index-alist current-mouse-event)
 	      (imenu--completion-buffer index-alist prompt)))
       (and (eq result t)
 	   (imenu--cleanup)
@@ -785,46 +785,37 @@
 NAME is a string used to name the menu bar item.
 See the command `imenu' for more information."
   (interactive "sImenu menu item name: ")
-  (let ((newmap (make-sparse-keymap))
-	(menu-bar (lookup-key (current-local-map) [menu-bar])))
-    (define-key newmap [menu-bar]
-      (append (make-sparse-keymap) menu-bar))
-    (define-key newmap [menu-bar index]
-      (cons name (nconc (make-sparse-keymap "Imenu")
-			(make-sparse-keymap))))
-    (use-local-map (append newmap (current-local-map))))
-  (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+  (set-buffer-menubar current-menubar)
+  (add-submenu nil `(,name :filter imenu-update-menubar)))
 
 (defvar imenu-buffer-menubar nil)
 
 (defun imenu-update-menubar ()
-  (and (current-local-map)
-       (keymapp (lookup-key (current-local-map) [menu-bar index]))
-       (let ((index-alist (imenu--make-index-alist t)))
-	 ;; Don't bother updating if the index-alist has not changed
-	 ;; since the last time we did it.
-	 (or (equal index-alist imenu--last-menubar-index-alist)
-	     (let (menu menu1 old)
-	       (setq imenu--last-menubar-index-alist index-alist)
-	       (setq index-alist (imenu--split-submenus index-alist))
-	       (setq menu (imenu--split-menu
-			   (if imenu-sort-function
-			       (sort
-				(let ((res nil)
-				      (oldlist index-alist))
-				  ;; Copy list method from the cl package `copy-list'
-				  (while (consp oldlist) (push (pop oldlist) res))
-				  (prog1 (nreverse res) (setcdr res oldlist)))
-				imenu-sort-function)
-			     index-alist)
-			   (buffer-name)))
-	       (setq menu1 (imenu--create-keymap-1 (car menu) 
-						   (if (< 1 (length (cdr menu)))
-						       (cdr menu)
-						     (cdr (car (cdr menu))))
-						   t))
-	       (setq old (lookup-key (current-local-map) [menu-bar index]))
-	       (setcdr old (cdr menu1)))))))
+  (let ((index-alist (imenu--make-index-alist t)))
+    ;; Don't bother updating if the index-alist has not changed
+    ;; since the last time we did it.
+    (or (equal index-alist imenu--last-menubar-index-alist)
+	(let (menu menu1 old)
+	  (setq imenu--last-menubar-index-alist index-alist)
+	  (setq index-alist (imenu--split-submenus index-alist))
+	  (setq menu (imenu--split-menu
+		      (if imenu-sort-function
+			  (sort
+			   (let ((res nil)
+				 (oldlist index-alist))
+			     ;; Copy list method from the cl package `copy-list'
+			     (while (consp oldlist) (push (pop oldlist) res))
+			     (prog1 (nreverse res) (setcdr res oldlist)))
+			   imenu-sort-function)
+			index-alist)
+		      (buffer-name)))
+	  (setq menu1 (imenu--create-keymap-1 (car menu) 
+					      (if (< 1 (length (cdr menu)))
+						  (cdr menu)
+						(cdr (car (cdr menu))))
+					      t))
+	  (setq old (lookup-key (current-local-map) [menu-bar index]))
+	  (setcdr old (cdr menu1))))))
 
 (defun imenu--menubar-select (item)
   "Use Imenu to select the function or variable named in this menu item."

--- /home/sj/src/xemacs/lisp/modes/lisp-mode.el	Fri Jan 10 00:13:59 1997
+++ /home/sj/xemacs/site-lisp/imenu/lisp-mode.el	Fri Jan 10 00:13:59 1997
@@ -136,17 +136,17 @@
 
 (define-abbrev-table 'lisp-mode-abbrev-table ())
 
-;(defvar lisp-imenu-generic-expression
-;      '(
-;	 (nil 
-;	  "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
-;	 ("Variables" 
-;	  "^\\s-*(def\\(var\\|const\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
-;	 ("Types" 
-;	  "^\\s-*(def\\(type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+]+\\)" 
-;	  2))
-;
-;  "Imenu generic expression for Lisp mode.  See `imenu-generic-expression'.")
+(defvar lisp-imenu-generic-expression
+  '(
+    (nil 
+     "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
+    ("Variables" 
+     "^\\s-*(def\\(var\\|const\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
+    ("Types" 
+     "^\\s-*(def\\(type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+]+\\)" 
+     2))
+
+  "Imenu generic expression for Lisp mode.  See `imenu-generic-expression'.")
 
 (defun lisp-mode-variables (lisp-syntax)
   (cond (lisp-syntax
@@ -185,9 +185,8 @@
   (setq comment-column 40)
   (make-local-variable 'comment-indent-function)
   (setq comment-indent-function 'lisp-comment-indent)
-  ;; XEmacs changes
-;  (make-local-variable 'imenu-generic-expression)
-;  (setq imenu-generic-expression lisp-imenu-generic-expression)
+  (make-local-variable 'imenu-generic-expression)
+  (setq imenu-generic-expression lisp-imenu-generic-expression)
   (set (make-local-variable 'dabbrev-case-fold-search) nil)
   (set (make-local-variable 'dabbrev-case-replace) nil)
   )

