Setting default Java mode?

Asked by Angus77

I haven't figured out how to do this aside from tinkering with the source itself.

When working with JSPs, is it possible to set the default java-mode to jde-mode?

If it's not, could the feature be requested?

I changed it in the source for myself a while ago, but through my tinkering I somehow broke the electric-parens so that every time I type a parenthesis, I'd be stopped by an error report (meaning two such error reports every time I typed in a function!)

Question information

Language:
English Edit question
Status:
Solved
For:
nXhtml Edit question
Assignee:
No assignee Edit question
Solved by:
lborgman
Solved:
Last query:
Last reply:
Revision history for this message
lborgman (lennart-borgman) said :
#1

Try

   M-x customize-group RET mumamo RET

and then look at the option

  mumamo-major-modes (Mumamo Major Modes)

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#2

I've tried for the last hour or so, but I'm still at a loss. What should I be adding here?

Revision history for this message
Best lborgman (lennart-borgman) said :
#3

I might have misunderstood you. I thought that you wanted jde-mode in java-mode chunks in multi major modes like jsp-nxhtml-mumamo.

Do you understand what I mean? Is this what you want?

If that is what you want then you can do like this:

  M-x customize-option RET mumamo-major-modes RET

You should add a new entry there where the first Symbol is java-mode and the second Symbol is jde-mode.

Could you perhaps try tell me how I could have made this more understandable and easier to do for you?

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#4

"jde-mode in java-mode chunks in multi major modes like jsp-nxhtml-mumamo" sounds exactly like what I want.

I'd already tried:

INS DEL Symbol: java-mode
            Repeat:
            INS DEL Choice: Value Menu Function: jde-mode
            INS

INS DEL Symbol: java-mode
            Repeat:
            INS DEL Choice: Value Menu Function: java-mode
            INS DEL Choice: Value Menu Function: jde-mode
            INS

and numerous permutations of the same. In the second one, it still works as normal (but no JDE), but in the first one, nxhtml-mode stops recognizing anything between the <% %> tags (meaning it doesn't switch modes).

If it's supposed to say "Symbol" instead of "Function", well, when I switch it to "Symbol", save and exit, when I come back to the Customize-Group page, it reverts to "Function". Is this important?

Revision history for this message
lborgman (lennart-borgman) said :
#5

The "Symbol" versus "Function" is not very important. If the function is not loaded it says Symbol.

I think the first one is the one you want of your choiced above is the one you want. Probably something goes wrong, that is why it does not work. Can you look in the message buffer and see if there is something that can help?

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#6

Thanks for the quick reply!

Here's what I get in *Messages*. The first error happens every time I open a .jsp file--I always have to open it twice (regardless of whether I've tried to set up nxhtml with JDE. Someone else reported the same problem at EmacsWiki).

The rest is more ELisp than I know how to deal with...

Error: (error Variable binding depth exceeds max-specpdl-size) [2 times]
Setting customized JDE variables to startup values...
Symbol's function definition is void: turn-on-font-lock-if-enabled
mumamo-fontify-region-with: Wrong type argument: listp, jde-run-applet-document
** In buffer addedGame.jsp
  backtrace()
  (let ((standard-output standard-output)) (backtrace))
  (let ((standard-output ...)) (let (...) (backtrace)) (with-current-buffer standard-output (prog1 ... ...)))
  (with-output-to-string (backtrace))
  (let ((format-string2 ...) (bt ...)) (mumamo-message-with-face (concat ... "
" ... bt) (quote highlight)) (apply (quote message) format-string2 lwarn-type args) (run-with-idle-timer 1 nil (quote mumamo-show-report-message)) (when mumamo-display-error-stop (setq font-lock-mode nil) (when ... ...) (when ... ...) (apply ... format-string2 lwarn-type args)))
  mumamo-display-error(mumamo-fontify-region-with "%s" "Wrong type argument: listp, jde-run-applet-document")
  (condition-case err (progn (mumamo-with-major-mode-fontification major ...)) (error (mumamo-display-error ... "%s" ...)))
  (if (not mumamo-use-condition-case) (let* (... ...) (progn ...)) (condition-case err (progn ...) (error ...)))
  (mumamo-condition-case err (progn (mumamo-with-major-mode-fontification major ...)) (error (mumamo-display-error ... "%s" ...)))
  mumamo-fontify-region-with(3 48 nil jde-mode 3 48)
  (let ((syntax-min ...) (syntax-max ...) (chunk-min ...) (chunk-max ...)) (when (<= here syntax-min) (mumamo-flush-chunk-syntax chunk chunk-min chunk-max)) (when (and ... ...) (put-text-property chunk-min syntax-min ... ...)) (when (and ... ...) (put-text-property syntax-max chunk-max ... ...)) (mumamo-fontify-region-with here max verbose chunk-major syntax-min syntax-max))
  (let* ((chunk ...) (old-chunk chunk) (chunk-min ...) (chunk-max ...) (chunk-min-1 ...) (chunk-max-1 ...) (chunk-min-face ...) (chunk-max-face ...) (chunk-major ...) (chunk-values ...) (cv-min ...) (cv-max ...) (cv-major-sub ...) (max) prev-major prev-chunk (need-new-chunk nil)) (mumamo-msgfntfy "old-chunk=%s cv-min/cv-max %s/%s" old-chunk cv-min cv-max) (unless cv-max (setq cv-max end)) (unless old-chunk (mumamo-adjust-old-chunks chunk-values nil end) (setq chunk ...)) (when old-chunk (unless ... ...)) (when need-new-chunk (mumamo-adjust-old-chunks chunk-values start end) (setq chunk ...)) (setq chunk-min (when chunk ...)) (setq chunk-max (when chunk ...)) (setq chunk-min-1 (when chunk ...)) (setq chunk-max-1 (when chunk ...)) (setq chunk-min-face (when chunk ...)) (setq chunk-max-face (when chunk ...)) (setq chunk-major (when chunk ...)) (if first-new-ovl (setq last-new-ovl chunk) (setq last-new-ovl chunk) (setq first-new-ovl chunk)) (mumamo-msgfntfy "0 first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (mumamo-msgfntfy "mumamo-fontify-region-1 FACE FACE FACE chunk-min: %s %s, chunk-max: %s %s" chunk-min chunk-min-face chunk-max chunk-max-face) (setq max (min chunk-max end)) (mumamo-msgfntfy "*** mumamo-fontify-region-1.here=%s, chunk=%s" here chunk) (assert chunk) (assert (overlay-buffer chunk)) (assert chunk-min) (assert chunk-max) (assert chunk-major) (mumamo-msgfntfy "*** mumamo-fontify-region-1: here 2 here=%s, start=%s, chunk-min=%s,max=%s end=%s chunk-major=%s" here start chunk-min chunk-max end chunk-major) (assert (not ...)) (when prev-chunk (assert ...)) (mumamo-msgfntfy "a first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (let (... ... ... ...) (when ... ...) (when ... ...) (when ... ...) (mumamo-fontify-region-with here max verbose chunk-major syntax-min syntax-max)) (setq prev-major chunk-major) (setq prev-chunk chunk) (setq here max) (setq fontified-t (or mumamo-dbg-pretend-fontified ...)))
  (while (and fontified-t (< here end)) (mumamo-msgfntfy "mumamo-fontify-region-1 heree 1, here=%s, end=%s" here end) (let* (... ... ... ... ... ... ... ... ... ... ... ... ... ... prev-major prev-chunk ...) (mumamo-msgfntfy "old-chunk=%s cv-min/cv-max %s/%s" old-chunk cv-min cv-max) (unless cv-max ...) (unless old-chunk ... ...) (when old-chunk ...) (when need-new-chunk ... ...) (setq chunk-min ...) (setq chunk-max ...) (setq chunk-min-1 ...) (setq chunk-max-1 ...) (setq chunk-min-face ...) (setq chunk-max-face ...) (setq chunk-major ...) (if first-new-ovl ... ... ...) (mumamo-msgfntfy "0 first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (mumamo-msgfntfy "mumamo-fontify-region-1 FACE FACE FACE chunk-min: %s %s, chunk-max: %s %s" chunk-min chunk-min-face chunk-max chunk-max-face) (setq max ...) (mumamo-msgfntfy "*** mumamo-fontify-region-1.here=%s, chunk=%s" here chunk) (assert chunk) (assert ...) (assert chunk-min) (assert chunk-max) (assert chunk-major) (mumamo-msgfntfy "*** mumamo-fontify-region-1: here 2 here=%s, start=%s, chunk-min=%s,max=%s end=%s chunk-major=%s" here start chunk-min chunk-max end chunk-major) (assert ...) (when prev-chunk ...) (mumamo-msgfntfy "a first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (let ... ... ... ... ...) (setq prev-major chunk-major) (setq prev-chunk chunk) (setq here max) (setq fontified-t ...)))
  (let* ((old-point ...) (here start) (main-major ...) (fontified-t t) after-change-functions (first-new-ovl nil) (last-new-ovl nil) (chunk-at-start-1 ...)) (when chunk-at-start-1 (unless ... ...)) (while (and fontified-t ...) (mumamo-msgfntfy "mumamo-fontify-region-1 heree 1, here=%s, end=%s" here end) (let* ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...)) (goto-char old-point) (mumamo-msgfntfy "b first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (unless fontified-t (mumamo-msgfntfy "not sure, here=%s, end=%s" here end) (unless ... ...)) (mumamo-msgfntfy "c first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (let (... ... ... ...) (mumamo-msgfntfy "*** mumamo-fontify-region-1: here 3 ovl-start=%s,end=%s, start=%s, chunks-to-remove=%s" ovl-start ovl-end start mumamo-chunks-to-remove) (when ... ...) (mumamo-msgfntfy "*** mumamo-fontify-region-1: here 4") (when ... ...)))
  (progn (let* (... ... ... ... after-change-functions ... ... ...) (when chunk-at-start-1 ...) (while ... ... ...) (goto-char old-point) (mumamo-msgfntfy "b first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (unless fontified-t ... ...) (mumamo-msgfntfy "c first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (let ... ... ... ... ...)))
  (unwind-protect (progn (let* ... ... ... ... ... ... ... ...)) (set-match-data save-match-data-internal (quote evaporate)))
  (let ((save-match-data-internal ...)) (unwind-protect (progn ...) (set-match-data save-match-data-internal ...)))
  (save-match-data (let* (... ... ... ... after-change-functions ... ... ...) (when chunk-at-start-1 ...) (while ... ... ...) (goto-char old-point) (mumamo-msgfntfy "b first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (unless fontified-t ... ...) (mumamo-msgfntfy "c first-new-ovl=%s last-new-ovl=%s" first-new-ovl last-new-ovl) (let ... ... ... ... ...)))
  mumamo-fontify-region-1(1 333 nil)
  (let ((debugger ...) (debug-on-error t)) (mumamo-fontify-region-1 start end verbose))
  (condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (not mumamo-use-condition-case) (let* (... ...) (let ... ...)) (condition-case err (let ... ...) (error ...)))
  (mumamo-condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (and mumamo-just-changed-major nil (= 0 ...)) (mumamo-display-error (quote mumamo-fontify-region) "Just changed major, should not happen") (mumamo-condition-case err (let ... ...) (error ...)))
  mumamo-fontify-region(1 333 nil)
  font-lock-fontify-region(1 333)
  run-hook-with-args(font-lock-fontify-region 1 333)
  byte-code("\302\303 #\207" [start next run-hook-with-args jit-lock-functions] 4)
  jit-lock-fontify-now(1 501)
  jit-lock-function(1)
  mumamo-jit-lock-function(1)

mumamo-fontify-region-with: Wrong type argument: listp, jde-run-applet-document
mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
** In buffer addedGame.jsp
  backtrace()
  (let ((standard-output standard-output)) (backtrace))
  (let ((standard-output ...)) (let (...) (backtrace)) (with-current-buffer standard-output (prog1 ... ...)))
  (with-output-to-string (backtrace))
  (let ((format-string2 ...) (bt ...)) (mumamo-message-with-face (concat ... "
" ... bt) (quote highlight)) (apply (quote message) format-string2 lwarn-type args) (run-with-idle-timer 1 nil (quote mumamo-show-report-message)) (when mumamo-display-error-stop (setq font-lock-mode nil) (when ... ...) (when ... ...) (apply ... format-string2 lwarn-type args)))
  mumamo-display-error(mumamo-fontify-region "%s" "Wrong type argument: number-or-marker-p, nil")
  (condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (not mumamo-use-condition-case) (let* (... ...) (let ... ...)) (condition-case err (let ... ...) (error ...)))
  (mumamo-condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (and mumamo-just-changed-major nil (= 0 ...)) (mumamo-display-error (quote mumamo-fontify-region) "Just changed major, should not happen") (mumamo-condition-case err (let ... ...) (error ...)))
  mumamo-fontify-region(1 333 nil)
  font-lock-fontify-region(1 333)
  run-hook-with-args(font-lock-fontify-region 1 333)
  byte-code("\302\303 #\207" [start next run-hook-with-args jit-lock-functions] 4)
  jit-lock-fontify-now(1 501)
  jit-lock-function(1)
  mumamo-jit-lock-function(1)

mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
Setting customized JDE variables to startup values...
Symbol's function definition is void: turn-on-font-lock-if-enabled
Wrong type argument: listp, jde-run-applet-document
mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
** In buffer addedGame.jsp
  backtrace()
  (let ((standard-output standard-output)) (backtrace))
  (let ((standard-output ...)) (let (...) (backtrace)) (with-current-buffer standard-output (prog1 ... ...)))
  (with-output-to-string (backtrace))
  (let ((format-string2 ...) (bt ...)) (mumamo-message-with-face (concat ... "
" ... bt) (quote highlight)) (apply (quote message) format-string2 lwarn-type args) (run-with-idle-timer 1 nil (quote mumamo-show-report-message)) (when mumamo-display-error-stop (setq font-lock-mode nil) (when ... ...) (when ... ...) (apply ... format-string2 lwarn-type args)))
  mumamo-display-error(mumamo-fontify-region "%s" "Wrong type argument: number-or-marker-p, nil")
  (condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (not mumamo-use-condition-case) (let* (... ...) (let ... ...)) (condition-case err (let ... ...) (error ...)))
  (mumamo-condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (and mumamo-just-changed-major nil (= 0 ...)) (mumamo-display-error (quote mumamo-fontify-region) "Just changed major, should not happen") (mumamo-condition-case err (let ... ...) (error ...)))
  mumamo-fontify-region(1 333 nil)
  font-lock-fontify-region(1 333)
  run-hook-with-args(font-lock-fontify-region 1 333)
  byte-code("\302\303 #\207" [start next run-hook-with-args jit-lock-functions] 4)
  jit-lock-fontify-now(3 503)
  jit-lock-function(3)
  mumamo-jit-lock-function(3)

mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
MuMaMo error, please look in the *Message* buffer
MuMaMo error, please look in the *Message* buffer
MuMaMo error, please look in the *Message* buffer
Using vacuous schema

Revision history for this message
lborgman (lennart-borgman) said :
#7

Which version of CEDET and JDEE are you using?

I am not using either of them yet, but I know there has been quite a number of changes to CEDET and also to JDEE. The function turn-on-font-lock-if-enabled is not defined in my Emacs. Maybe that is an old function?

Could you perhaps checkout the development versions of CEDET and JDEE and try again?

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#8

I'll try that and report back.

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#9

Well, I downloaded the jdee & cedet tarballs and set them up, and now when I open a .jsp file jdee does indeed seem to get started up, but the behaviour is the same as regular java-mode.

When point is between some <% %> tags and I press enter to open a new line, I get:

Internal nXML mode error in nxml-after-change (Wrong type argument: number-or-marker-p, nil), degrading
dolist: Variable binding depth exceeds max-specpdl-size

Here's what I get in *Messages*:

Using vacuous schema
Error: (error Variable binding depth exceeds max-specpdl-size) [2 times]
Loading jde...
mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
** In buffer addGame.jsp
  backtrace()
  (let ((standard-output standard-output)) (backtrace))
  (let ((standard-output ...)) (let (...) (backtrace)) (with-current-buffer standard-output (prog1 ... ...)))
  (with-output-to-string (backtrace))
  (let ((format-string2 ...) (bt ...)) (mumamo-message-with-face (concat ... "
" ... bt) (quote highlight)) (apply (quote message) format-string2 lwarn-type args) (run-with-idle-timer 1 nil (quote mumamo-show-report-message)) (when mumamo-display-error-stop (setq font-lock-mode nil) (when ... ...) (when ... ...) (apply ... format-string2 lwarn-type args)))
  mumamo-display-error(mumamo-fontify-region "%s" "Wrong type argument: number-or-marker-p, nil")
  (condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (not mumamo-use-condition-case) (let* (... ...) (let ... ...)) (condition-case err (let ... ...) (error ...)))
  (mumamo-condition-case err (let (... ...) (mumamo-fontify-region-1 start end verbose)) (error (mumamo-display-error ... "%s" ...)))
  (if (and mumamo-just-changed-major nil (= 0 ...)) (mumamo-display-error (quote mumamo-fontify-region) "Just changed major, should not happen") (mumamo-condition-case err (let ... ...) (error ...)))
  mumamo-fontify-region(1 572 nil)
  font-lock-fontify-region(1 572)
  run-hook-with-args(font-lock-fontify-region 1 572)
  byte-code("\302\303 #\207" [start next run-hook-with-args jit-lock-functions] 4)
  jit-lock-fontify-now(1 501)
  jit-lock-function(1)
  mumamo-jit-lock-function(1)

mumamo-fontify-region: Wrong type argument: number-or-marker-p, nil
Loading jde... [16 times]
MuMaMo error, please look in the *Message* buffer
Using vacuous schema
Loading jde... [16 times]
Using vacuous schema [2 times]
Internal nXML mode error in nxml-after-change (Wrong type argument: number-or-marker-p, nil), degrading
Entering debugger...
file-truename: Variable binding depth exceeds max-specpdl-size

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#10

Oh, and the JDEE I was using was the Ubuntu .deb package, which is the same version as the tarball I downloaded.

Revision history for this message
lborgman (lennart-borgman) said :
#11

I have checked out the latest sources from the repositories for JDEE and CEDET. Could you please tell me what you enter in your .emacs to setup CEDET and JDEE so I can test here?

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#12

(add-to-list 'load-path (expand-file-name "~/elisp/jde-2.3.5.1/lisp"))
(add-to-list 'load-path (expand-file-name "~/elisp/cedet-1.0pre4/semantic"))
(add-to-list 'load-path (expand-file-name "~/elisp/cedet-1.0pre4/speedbar"))
(add-to-list 'load-path (expand-file-name "~/elisp/elib"))
(add-to-list 'load-path (expand-file-name "~/elisp/cedet-1.0pre4/eieio"))
(add-to-list 'load-path (expand-file-name "~/elisp/cedet-1.0pre4/common"))

;; Initialize CEDET.
(load-file (expand-file-name "~/elisp/cedet-1.0pre4/common/cedet.el"))

(setq defer-loading-jde t)

(if defer-loading-jde
    (progn
      (autoload 'jde-mode "jde" "JDE mode." t)
      (setq auto-mode-alist
     (append
      '(("\\.java\\'" . jde-mode))
      auto-mode-alist)))
  (require 'jde))

Revision history for this message
lborgman (lennart-borgman) said :
#13

I have just uploaded version 1.48 of nXhtml with a small bug fix that is needed to get it to work with jde-mode. I also made a change so that jde-mode now is the default for the <% ... %> chunks if it is available.

I tried the devel version of CEDET and JDEE and it is possible to get the chunks to have major mode jde-mode.

However I have not tried how it works, since I have not used CEDET or JDEE myself yet. Could you please tell me how it works for you? I would be surprised if there were no buffer local variables to survive when moving between chunks, but I have not looked at what is needed.

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#14

It works now (at least in the couple of minutes I played around with it, it did everything I expected)! Although, it didn't work with the CEDET and JDEE packages I downloaded myself. It only worked when I reinstalled the Ubuntu packages (which is perfectly fine by me!)

A couple of things, though.

Doing M-x customize-group RET mumamo RET and selecting Major Modes gives me this error:

Debugger entered--Lisp error: (void-function nil)
  nil((command :tag "Major mode") javascript-mode)
  widget-apply((command :tag "Major mode") :match javascript-mode)

It slipped my mind, but maybe i should mention that I'm using the ubuntu emacs-snapshot 1:20080228-1ubuntu1 package and that I'm set up for a Japansese UTF-8 environment (for Japanese input. I still do everything in English, but I need to input Japanese characters here and there).

I mention this, because with the JDEE and CEDET that weren't from Ubuntu, I was getting this error:

 Invalid read syntax: "invalid multibyte form"

This is how I've set up my Japanese environment in my .emacs:

;; Make Japanese the default language
(set-language-environment "Japanese")
(set-buffer-file-coding-system 'utf-8 'utf-8-unix)
(set-default buffer-file-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)
(set-default default-buffer-file-coding-system 'utf-8-unix)
;; Add anthy.el to the load path
(push "/usr/local/share/emacs/site-lisp/anthy/" load-path)
;; Load anthy.el
(load-library "anthy")
;; Set japanese-anthy as the default input-method
(setq default-input-method "japanese-anthy")
;; Use Japanese keyboard key to toggle Japanese input on and off.
(global-set-key [zenkaku-hankaku] 'toggle-input-method)
(global-set-key "\C-\\" nil)

Revision history for this message
Angus77 (andrewmcintosh-yahoo) said :
#15

Actually, I've found now that I get the "Invalid read syntax: invalid multibyte form" error even when I remove all the Japanese environment stuff.

Revision history for this message
Dominique Quatravaux (dominique-quatravaux) said :
#16

Hi Angus77, I found the root cause for the customization backtrace issue; see https://bugs.launchpad.net/nxhtml/+bug/599726 . As a workaround, add the following to your .emacs after the lines where you load nxhtml:

(require 'ourcomments-widgets)