On Wed, 28 Apr 2004 14:30:20 -0400, Paul Kinnucan [EMAIL PROTECTED] wrote:
Martin Dickau writes:
Hi Paul,
Just installed jdee 2.3.4beta1. Looks very nice. One complaint:
I absolutely *HATE* having my return key overridden and having to do
something to actively prevent it. Now I have yet another customization to
maintain that I don't even really want to have IMO, even more annoying
than when abbrev mode was turned on by default. FWIW.
I'm planning to make this feature off by default.
I did notice that it the jde-gen-embrace it's bound to does not honor my
indentation style. For example, I have my indentation set up to get the
now-not-in-favor alignment of close brace under beginning of keyword:
There was a thread on getting jde-gen-embrace to honor a user's indentation styles
that I did not follow very closely. I plan to review the thread and incorporate any
ideas that are workable into an enhanced version of this feature.
Paul
try {
}
via:
(setq c-basic-offset 4)
(setq c-indent-level 4)
(setq c-tab-always-indent nil)
(setq tab-width 4)
(setq-default tab-width 4)
(setq default-tab-width 4)
but when I used 2.3.4 with RET, I got:
try {
}
(tab on the close-brace line shifts it back to the left, but that sort of
defeats the purpose of having the code generated in the first place).
Regards,
Martin
The gen-embrace code in the 2.3.4beta1 is from the start of the thread
and is a bit buggy.
The consensus at the end of the thread was that it would be nice we
could get this functionalty in a way that was more in the spirit of
realted cc-mode features. I think c-context-line-break is a good
candidate to host this functionality (along with the special handling
of returns inside strings). I am working on this and shall post the
code to the cc-mode list when I'm done.
So, since the code is half-baked now and will hopefully the feature
will get into cc-mode someday, I suggest that it not be included in
JDE.
If however you want to use this feature in right now, you can use the
code at the end of the old thread. For convenience I've pasted it here
after ripping out the multi-line string stuff. To
bind [return] to jde-electric-return. The code is much smarter about
not inserting a close brace if it is not needed, jde-newline-function
lets you customize which identation function you want for newlines and
jde-gen-embrace lets you toggle the brace insertion.
Suraj
(defun jde-electric-return ()
(interactive)
(cond
;; ((and jde-gen-complete-multi-line-string (jde-inside-string-literal))
;; (jde-multi-line-string-enter))
((and jde-gen-embrace (jde-line-end-at-open-brace))
(jde-gen-embrace))
(t (jde-newline))
)
)
(defcustom jde-newline-function '(newline)
Indent command that the enter key calls.
:group 'jde
:type '(list
(radio-button-choice
:format %t \n%v
:tag Function:
:entry-format %b %v
(const newline)
(const newline-and-indent)
(const align-newline-and-indent)
(function my-custom-newline-function)))
)
(defcustom jde-gen-embrace t
Typing enter after a close brace at the end of a line will
insert a matching closing brace (if required) and put point on a
empty line between the braces and indent the new lines.
So if before
you had:
pubic void function () {
^
You now have:
pubic void function () {
} ^
Point must be at the end of the line, or at a } character
followed by the end of the line.
If it thinks a matching close brace already exists a new one is not inserted.
Before:
pubic void function () {
} ^
After:
pubic void function () {
} ^
:type 'boolean
)
(defun jde-line-end-at-open-brace ()
(and (looking-back {\\s-* (line-beginning-position)) (looking-at
}?\\s-*$)))
(defun jde-gen-embrace ()
Adds a new line and inserts a matching close brace if
required. See variable 'jde-gen-embrace.
Assumes that 'jde-line-end-at-open-brace has been called and it
returned true.
(interactive)
(let ((open-indent (current-indentation)))
(when (looking-at })
;; if there is a } after point, put it on a new line and come back
(jde-newline)
(end-of-line 0) ;; move to end of previous line
)
;; make a blank line
(jde-newline)
(when (save-excursion
(
;; parenthesis depth at point
(car (parse-partial-sexp (point-min) (point)))
;; number of unmatched open parenthesis staring from point
(- (car (parse-partial-sexp (point) (point-max)
)
;; add the } on a new indented line
(insert })
(indent-according-to-mode)
(end-of-line 0) ;; move to