Hi,
The templates included in JDE didn't offer choice for the brace placement,
so I made them configurable. Users can now chooce between "modern" and
"K&R" brace style.
jari
2000-01-24 Mon Jari Aalto <[EMAIL PROTECTED]>
* jde-gen.el
(jde-k&r): 1.1.1.1 New user variable to select between
Kerningham & Ritchie and Modern brace placement styles:
class Some { // K&R
}
class Some // Modern
{
// Looks even around THIS code line
}
(jde-gen-class-buffer-template): 1.1.1.1 Support for
jde-k&r variable
(jde-gen-console-buffer-template): 1.1.1.1 Support for
jde-k&r variable
(jde-gen-jfc-app-buffer-template): 1.1.1.1 Support for
jde-k&r variable
Prereq: 1.1.1.1
Index: jde-gen.el
===================================================================
RCS file: g:/data/version-control/cvsroot/lisp/site-lisp/common/programming/java/jde/lisp/jde-gen.el,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -u -IId: -u -r1.1.1.1 -r1.1.1.1.2.1
--- jde-gen.el 2000/01/24 18:26:05 1.1.1.1
+++ jde-gen.el 2000/01/24 20:17:07 1.1.1.1.2.1
@@ -1,5 +1,5 @@
;;; jde-gen.el -- Integrated Development Environment for Java.
-;; $Revision$
+;; $Revision$
;; Author: Paul Kinnucan <[EMAIL PROTECTED]>
;; Maintainer: Paul Kinnucan
@@ -30,7 +30,28 @@
:group 'jde
:prefix "jde-gen-")
+(defcustom jde-k&r nil
+ "*If non-nil, use braces in Original Kerningham & Ritchie Style.
+The Creators of C started using brace placement style:
+ class Some {
+
+ }
+
+But there is also alternative line-up style
+
+ class Some
+ {
+
+ }
+
+Setting this variable to t, uses k&R style in skeletons and tempaltes.
+
+Changing this variable after JDE is loaded does nothing,
+because it is evaluated at load time to set up defualt templates."
+ :group 'jde-project
+ :type 'string)
+
(defun jde-gen-lookup-named (name)
"Lookup some saved data under the name NAME.
Returns the data if NAME was found, and nil otherwise."
@@ -83,7 +104,7 @@
(defun jde-gen-get-super-class ()
(let ((super-class (read-from-minibuffer "extends: "))
(interface (read-from-minibuffer "implements: ")))
- (cond
+ (cond
((and
(not (string= super-class ""))
(not (string= interface "")))
@@ -95,10 +116,10 @@
(concat "implements " interface)))))
(defcustom jde-gen-class-buffer-template
- '(
+ (list
"(funcall jde-gen-boilerplate-function) 'n"
"\"/**\" 'n"
- "\" * \""
+ "\" * \""
"(file-name-nondirectory buffer-file-name) 'n"
"\" *\" 'n"
"\" *\" 'n"
@@ -110,14 +131,34 @@
"'n>"
"\"public class \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\" \" (jde-gen-get-super-class) \" {\" 'n> 'n>"
+ "\" \" (jde-gen-get-super-class)" ;; \" {\" 'n> 'n>"
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
"\"public \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\"() {\" 'n>"
+ "\" ()\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
"'p 'n>"
- "\"}\" 'n>"
+ "\"}\">"
"'n>"
- "\"} // \""
+ "'n>"
+ "\"}\">"
+ "\"// \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
"'n>")
"*Template for new Java class.
@@ -150,10 +191,10 @@
(defcustom jde-gen-console-buffer-template
- '(
+ (list
"(funcall jde-gen-boilerplate-function) 'n"
"\"/**\" 'n"
- "\" * \""
+ "\" * \""
"(file-name-nondirectory buffer-file-name) 'n"
"\" *\" 'n"
"\" *\" 'n"
@@ -165,14 +206,44 @@
"'n>"
"\"public class \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\" {\" 'n> 'n>"
+
+;; "\" {\" 'n> 'n>"
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
"\"public \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\"() {\" 'n>"
+ "\" ()\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"'n>"
"\"}\" 'n>"
"'n>"
- "\"public static void main(String[] args) {\" 'n>"
+ "\"public static void main(String[] args)\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"'p 'n>"
"\"}\" 'n> 'n>"
"\"} // \""
@@ -207,7 +278,7 @@
(defcustom jde-gen-jfc-app-buffer-template
- '(
+ (list
"(funcall jde-gen-boilerplate-function) 'n"
"\"import java.awt.Dimension;\" 'n"
"\"import java.awt.Graphics;\" 'n"
@@ -224,7 +295,7 @@
"\"import java.awt.event.ActionEvent;\" 'n"
"\"import javax.swing.AbstractAction;\" 'n 'n"
"\"/**\" 'n"
- "\" * \""
+ "\" * \""
"(file-name-nondirectory buffer-file-name) 'n"
"\" *\" 'n"
"\" *\" 'n"
@@ -236,20 +307,66 @@
"'n>"
"\"public class \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\" extends JFrame {\" 'n> 'n>"
+ "\" extends JFrame\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
- "\"class Canvas extends JPanel {\" 'n> 'n>"
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
- "\"public Canvas () {\" 'n>"
+ "\"class Canvas extends JPanel\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+ "\"public Canvas () \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"\"setSize(getPreferredSize());\" 'n>"
"\"Canvas.this.setBackground(Color.white);\" 'n>"
"\"}\" 'n> 'n>"
+
+ "\"public Dimension getPreferredSize() \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
- "\"public Dimension getPreferredSize() {\" 'n>"
+
"\"return new Dimension(600, 600);\" 'n>"
"\"}\" 'n> 'n>"
+
+ "\"public void paintComponent(Graphics g) \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
- "\"public void paintComponent(Graphics g) {\" 'n>"
+
"\"super.paintComponent(g);\" 'n>"
"\"Graphics2D g2d = (Graphics2D) g;\" 'n>"
"\"Ellipse2D circle = new Ellipse2D.Double(0d, 0d, 100d, 100d);\" 'n>"
@@ -265,19 +382,53 @@
;; Constructor
"\"public \""
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
- "\"() {\" 'n>"
+ "\"()\""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"\"super(\\\"\" (P \"Enter app title: \") \"\\\");\" 'n>"
"\"setSize(300, 300);\" 'n>"
- "\"addWindowListener(new WindowAdapter() {\" 'n>"
+ "\"addWindowListener(new WindowAdapter() \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"\"public void windowClosing(WindowEvent e) {System.exit(0);}\" 'n>"
- "\"public void windowOpened(WindowEvent e) {}});\" 'n>"
+ "\"public void windowOpened(WindowEvent e) {}\" 'n>"
+ "\"});\" 'n>"
+
+
"\"setJMenuBar(createMenu());\" 'n>"
"\"getContentPane().add(new JScrollPane(new Canvas()));\" 'n>"
"\"}\" 'n>"
"'n>"
;; Main method
- "\"public static void main(String[] args) {\" 'n>"
+ "\"public static void main(String[] args) \""
+
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"'n>"
"(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
"\" f = new \""
@@ -287,11 +438,42 @@
"'p 'n>"
"\"}\" 'n> 'n>"
;; createMenu method
- "\"protected JMenuBar createMenu() {\" 'n>"
+ "\"protected JMenuBar createMenu() \""
+
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"\"JMenuBar mb = new JMenuBar();\" 'n>"
"\"JMenu menu = new JMenu(\\\"File\\\");\" 'n>"
- "\"menu.add(new AbstractAction(\\\"Exit\\\") {\" 'n>"
- "\"public void actionPerformed(ActionEvent e) {\" 'n>"
+ "\"menu.add(new AbstractAction(\\\"Exit\\\") \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
+ "\"public void actionPerformed(ActionEvent e) \""
+
+ (if jde-k&r
+ "\" {\" 'n>"
+ "'n")
+
+ (if jde-k&r
+ ""
+ "\"{\"> 'n>")
+
+
"\"System.exit(0);\" 'n>"
"\"}\" 'n>"
"\"});\" 'n>"
@@ -329,13 +511,13 @@
(tempo-forward-mark))
-(defcustom jde-gen-buffer-templates
+(defcustom jde-gen-buffer-templates
(list (cons "Class" 'jde-gen-class)
(cons "Console" 'jde-gen-console)
(cons "Swing App" 'jde-gen-jfc-app))
"*Specifies available autocode templates for creating buffers.
The value of this variable is an association list. The car of
-each element specifies the template's title. The cdr specifies
+each element specifies the template's title. The cdr specifies
a command that inserts the template into a buffer. See the function
`tempo-define-template' for any easy way to create a template
insertion command."
@@ -361,7 +543,7 @@
"Create a new Java buffer containing a code template.
This command inserts the specified template at the beginning
of the buffer."
- (interactive
+ (interactive
(list (completing-read "Template: " jde-gen-buffer-template-names)
(read-file-name "File: ")))
(find-file file)
@@ -390,7 +572,7 @@
"\"* @param v Value to assign to \" (s name) \".\" 'n>"
"\"*/\" 'n>"
"\"public void set\" (jde-gen-init-cap (jde-gen-lookup-named 'name))"
- "\"(\" (s type) \" v) {this.\" (s name) \" = v;}\" 'n>"
+ "\"(\" (s type) \" v) {this.\" (s name) \" = v;}\" 'n>"
)
"*Template for creating a get/set method pair.
Setting this variable defines a template instantiation
@@ -430,7 +612,7 @@
(defcustom jde-gen-action-listener-template
'(
"'& (P \"Component name: \")"
- "\".addActionListener(new ActionListener() {\" 'n>"
+ "\".addActionListener(new ActionListener() {\" 'n>"
"\"public void actionPerformed(ActionEvent e) {\" 'n>"
"\"}});\" 'n>"
)
@@ -526,7 +708,7 @@
(defcustom jde-gen-to-string-method-template
'(
"'&"
- "\"public String toString() {\" 'n>"
+ "\"public String toString() {\" 'n>"
"\"return super.toString();\" 'n>"
"\"}\" 'n>"
)
@@ -544,10 +726,10 @@
"Insert skeleton toString method."))
(set-default sym val)))
-(defcustom jde-gen-println
+(defcustom jde-gen-println
'(
"'&"
- "\"System.out.println(\" (P \"Print out: \") \");\" 'n>"
+ "\"System.out.println(\" (P \"Print out: \") \");\" 'n>"
)
"*Template for generating a System.out.println statement."
:group 'jde-gen
@@ -561,7 +743,7 @@
"Insert println statement."))
(set-default sym val)))
-(defcustom jde-gen-property-change-support
+(defcustom jde-gen-property-change-support
'(
"'&"
@@ -710,7 +892,7 @@
(set-default sym val)))
-(defcustom jde-gen-code-templates
+(defcustom jde-gen-code-templates
(list (cons "Get Set Pair" 'jde-gen-get-set)
(cons "toString method" 'jde-gen-to-string-method)
(cons "Action Listener" 'jde-gen-action-listener)
@@ -725,7 +907,7 @@
)
"*Specifies available autocode templates.
The value of this variable is an association list. The car of
-each element specifies a template name. The cdr specifies
+each element specifies a template name. The cdr specifies
a command that inserts the template into a buffer. See the function
`tempo-define-template' for any easy way to create a template
insertion command."
@@ -755,9 +937,9 @@
(completing-read "Template name: " jde-gen-template-names)))
(funcall (cdr (assoc name jde-gen-code-templates))))
-; (defun jde-gen-doc-method()
+; (defun jde-gen-doc-method()
; "Document method at point."
-; (interactive)
+; (interactive)
; (catch 'error
; (save-excursion
; (let* (start-of-function
@@ -801,6 +983,9 @@
(provide 'jde-gen)
;; $Log$
+;; Revision 1.1.1.1.2.1 2000/01/24 20:17:07 Jari Aalto
+;; jde-k&r
+;;
;; Revision 1.1.1.1 2000/01/24 18:26:05 Jari Aalto
;; init
;;
@@ -900,4 +1085,4 @@
;; Initial revision
;;
-;; End of jde-gen.el
\ No newline at end of file
+;; End of jde-gen.el