Here is a better way to determine the syntactiy context of current point, means if
point stays within a line-comment, block-comment or within a string. IMHO this is more
robust than jde-line-has-incomplete-string...and uses well proved Emacs-concepts for
this instead of fiddling with some regexps and increasing numbers ;-)
(defun syntactic-context ()
"Check in which syntactic context point is. Return nil if no special context
meaning, otherwise 'string if within a string, 'comment if within a
line-comment and 'block-comment if within a block-comment."
(let* ((beg (save-excursion
(beginning-of-defun)
(point)))
(state (save-excursion
(parse-partial-sexp beg (point)))))
(cond
((nth 3 state) 'string)
((nth 4 state) (if (member major-mode
'(c-mode c++-mode java-mode jde-mode))
(if (nth 7 state) 'comment 'block-comment)
'comment))
(t nil))))
This function returns 'string if point is within a string - so also when point is at
the end of an unterminated string.
In that situation a newline-command should insert a (java)string terminator and so on
... As already done by the code of this thread. This has the side-effect that when
point stays within a terminated string a newline-command breaks this string by adding
a new terminator behind the break...so the smart newline-command does not only for
unterminated strings the right thing but also for terminated.
Thoughts?
BTW: I do not want to upset someone who contributes to this thread and code, but i
have the strong feeling, that the most things could be done more generally with
concepts and mechanism of the underlying cc-mode. I'm think into the direction of
`c-hanging-braces-alist' and all this stuff...IMHO JDEE and also this contributed new
code reinvents the wheel in some aspects...
Off topic: JDEE does this also with all the template-stuff - where IMHO somehow
cumbersomely is specified if a newline after a brace or not etc... all this could be
done more nifty with mechanism of cc-mode and tempo, so the user specifies with
cc-mode when he wants newlines before or after praces etc. and tempo uses this
informations instead of introducing new options by JDEE so the user has to customize
the same thing at differrent places.
Klaus
-----Urspr�ngliche Nachricht-----
Von: Paul Kinnucan [mailto:[EMAIL PROTECTED]
Gesendet: Freitag, 12. M�rz 2004 23:04
An: Suraj Acharya
Cc: [EMAIL PROTECTED]; Paul Kinnucan; Petter M�hl�n; [EMAIL PROTECTED]
Betreff: Re: auto newline, indent and close brace on open brace, return
Hi All,
I've been saving the email on this thread and will review it over the weekend. My plan
is to include the latest and greatest version that comes out of this discussion.
Thanks,
Paul