Hi,

[email protected] (Ludovic Courtès) writes:

> Is there any reason for not using `define-derived-mode' when defining
> `jde-mode'?  (I see code that uses it is commented out.)
>
> It turns out that not using it can have undesirable side-effects and
> lead to "non-deterministic" behavior.
>
> What happened to me recently is that the first Java file I opened during
> my Emacs session was with `C-x C-f' from a Gnus *Group* buffer.
> Consequently, `jde-mode-map' inherited Gnus bindings, which, needless to
> say, is quite inconvenient.  ;-)

The attached patch (with stripped paths!) fixes that.

Can someone review it?

Thanks,
Ludo'.

>From 9e49921cb9a220324c22b55300a85a46f7f917bf Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ludovic=20Court=C3=A8s?= <[email protected]>
Date: Fri, 14 Aug 2009 13:04:32 +0200
Subject: [PATCH] Use kosher mode definition to make `jde-mode' deterministic.

This makes `jde-mode' actually deterministic.  Previous method had it
depend on the mode current when it was called.  See
http://thread.gmane.org/gmane.emacs.jdee.user/196 for a discussion.

* jde/lisp/jde.el (jde-mode): Now defined using `define-derived-mode'.
  (jde-mode-internal): New, from former `jde-mode'.  Remove low-level
  mode bit fiddling.  Add `easy-menu-define' call for GNU Emacs.
---
 jde/lisp/jde.el |   41 +++++++++++++++--------------------------
 1 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/jde/lisp/jde.el b/jde/lisp/jde.el
index 28b31e5..0a79adb 100644
--- jde/lisp/jde.el
+++ jde/lisp/jde.el
@@ -7,6 +7,7 @@
 
 ;; Copyright (C) 1997-2008 Paul Kinnucan.
 ;; Copyright (C) 2009 by Paul Landes
+;; Copyright (C) 2009 Ludovic Courtès
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -828,35 +829,20 @@ This command invokes the function defined by `jde-build-function'."
   (interactive)
   (call-interactively (car jde-build-function)))
 
-; (define-derived-mode
-;   jde-mode java-mode "JDE"
-;   "Major mode for developing Java applications and applets.
-;   \\{jde-mode-map}"
-;   (jde-mode-internal)
-; )
-
-;; The following is the expansion of the above macro.
-;; We include the expansion to permit automatic
-;; loading of the JDE.
-(derived-mode-init-mode-variables 'jde-mode)
-(put 'jde-mode 'derived-mode-parent 'java-mode)
-
 ;;;###autoload
-(defun jde-mode ()
+(define-derived-mode
+  jde-mode java-mode "JDE"
   "Major mode for developing Java applications and applets.
+
 \\{jde-mode-map}"
-  (interactive)
+  (jde-mode-internal))
+
+
+(defun jde-mode-internal ()
+  "Initialization of `jde-mode'."
   (condition-case err
       (progn
 	(jde-check-versions)
-	(java-mode)
-	(if (get 'java-mode 'special)
-	    (put 'jde-mode 'special t))
-	(setq major-mode 'jde-mode)
-	(setq mode-name "JDE")
-	(derived-mode-set-keymap 'jde-mode)
-	(derived-mode-set-syntax-table 'jde-mode)
-	(derived-mode-set-abbrev-table 'jde-mode)
 
 	;; Define buffer-local variables.
 	(make-local-variable 'jde-project-name)
@@ -892,9 +878,12 @@ This command invokes the function defined by `jde-build-function'."
 	(unless (member 'jde-clean-up-after-jde kill-buffer-hook)
 	  (add-hook 'kill-buffer-hook 'jde-clean-up-after-jde))
 
-	(when jde-xemacsp
-	  (require 'jde-xemacs)
-	  (jde-insert-menu-in-xemacs-menubar))
+	(if jde-xemacsp
+	    (progn
+	      (require 'jde-xemacs)
+	      (jde-insert-menu-in-xemacs-menubar))
+	  (easy-menu-define jde-menu jde-mode-map "JDE"
+	    jde-menu-definition))
 
 	;; Define underscore as a word constituent. This is needed
 	;; to support coding styles the begin fields with an underscore.
-- 
1.6.1.3

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
jdee-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jdee-users

Reply via email to