Re: AW: auto newline, indent and close brace on open brace, return

2004-03-14 Thread Martin Schwamberger
Hi Paul,

Berndl, Klaus wrote:
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.
jde-parse-comment-or-quoted-p doen't work reliable.
I propose to reimplement this function using parse-partial-sexp.
Since I've already made changes on jde-parse.el, I could do
this, if you agree.
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.

Since I do already work on the templates,
I could move the kr stuff to a function (or macro).
This would finally allow to change the way it is implemented
at one single place.
Regards,

Martin


Re: AW: auto newline, indent and close brace on open brace, return

2004-03-14 Thread Paul Kinnucan
Martin Schwamberger writes:
  Hi Paul,
  
  Berndl, Klaus wrote:
   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.
   
  
  jde-parse-comment-or-quoted-p doen't work reliable.
  I propose to reimplement this function using parse-partial-sexp.
  Since I've already made changes on jde-parse.el, I could do
  this, if you agree.
  

I do. Thanks.

   
   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.

Yes. I agree this approach would be much more elegant and I'd appreciate your
doing it.

Regards,

Paul

   
  
  Since I do already work on the templates,
  I could move the kr stuff to a function (or macro).
  This would finally allow to change the way it is implemented
  at one single place.
  
  Regards,
  
  Martin



Re: jde-import-all

2004-03-14 Thread Paul Kinnucan
Phillip Lord writes:
  
  Here is the latest version of jde-import-all, which works with
  jde-2.3.3.
  

Hi Philip,

How about leveraging semantic to find a candidate list of classes
to import? The following function uses the semantic lexer to get
a list of all Java tokens in the current buffer. It then 
extracts all identifiers in the list that start with an upper
case character and have at least one lower case character,
and that do not appear in an import statement
or inner or outer class declaration.

A more rigorous approach might use David Ponce's wisent parser
generator to generate a parser that builds a list of class
names as a side effect of parsing the buffer.

Paul 

(defun jde-import-find-classes-to-import ()
  Returns a list of unqualified class names to import into this
buffer. This function returns all the identifiers in the current
buffer that start with an uppercase character, have at least one lower
case character, and that are not included in an import statement and
are not the names of inner or outer classes declared in this buffer.
  (let (declared-classes
imported-classes
classes-to-import)

;; Get the names of classes that are already imported into this buffer.
(let ((import-tags (semantic-brute-find-tag-by-class 'include (current-buffer
  (setq
imported-classes
(mapcar
 (lambda (import-tag)
   (jde-parse-get-unqualified-name (semantic-tag-name import-tag)))
 import-tags)))

;; Get the names of classes declared in this buffer.
(let ((buffer-class-tags (semantic-brute-find-tag-by-class 'type 
(current-buffer 
  (flet ((find-declared-classes 
  (class-tag)
  (let ((members (semantic-tag-get-attribute class-tag :members)))
(dolist (member members)
  (if (eq (semantic-tag-class member) 'type)
  (progn
(setq declared-classes 
  (append declared-classes (list (semantic-tag-name 
member
(find-declared-classes member)))
  (dolist (class-tag buffer-class-tags)
 (setq declared-classes (append declared-classes  (list (semantic-tag-name 
class-tag
 (find-declared-classes class-tag
  
;; Sort through the Java tokens in this buffer, looking
;; for identifiers that start with an uppercase character and
;; do not appear in an import statement or a toplevel
;; class declaration.
(let ((tokens (semantic-lex-buffer 1000)))
 (dolist (token tokens classes-to-import)
  (let ((type (car token))
(start (cadr token))
(end (cddr token)))
(if (eq type 'IDENTIFIER)
(let (case-fold-search
  (name (buffer-substring-no-properties start end)))
  (unless (or
   (string-match ^[a-z] name)
   (not (string-match [a-z] name))
   (member name declared-classes)
   (member name imported-classes))
(add-to-list 'classes-to-import  name t)


(defun test ()
  (interactive)
  (message 
   Classes: %s
   (mapconcat 
'identity
(jde-import-find-classes-to-import)
 )))


  
  
  Cheers
  
  Phil
  
  
  ;;; jde-import-all.el --- Import everything at once.
  
  ;; Copyright (C) 2004 Phillip Lord
  
  ;; Author: Phillip Lord [EMAIL PROTECTED]
  
  ;; COPYRIGHT NOTICE
  ;;
  ;; This program is free software; you can redistribute it and/or modify
  ;; it under the terms of the GNU General Public License as published by
  ;; the Free Software Foundation; either version 2, or (at your option)
  ;; any later version.
  
  ;; This program is distributed in the hope that it will be useful,
  ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ;; GNU General Public License for more details.
  
  ;; You should have received a copy of the GNU General Public License
  ;; along with this program; see the file COPYING.  If not, write to the
  ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  ;; Boston, MA 02111-1307, USA.
  
  ;;; Commentary:
  ;;
  ;; Build imports for all types in the buffer.  This package has two
  ;; entry points.  `jde-import-all' finds all declared types in the
  ;; buffer, then presents the user with a nice dialog which they can
  ;; then choose as many as they wish.  `jde-import-all-unambiguous'
  ;; finds all the declared types in the buffer, and then imports
  ;; without asking the user any imports which identify a class
  ;; unambigiously.
  ;;
  ;; There are not user options other than those in `jde-import' which
  ;; this respects.
  ;;
  ;; This package is really meant for rolling into jde-import.  There's
  ;; also a dialog near the end which uses the efc namespace, because it
  ;; probably belongs there.
  ;; 
  ;; This