At 01:09 PM 6/17/99 -0500, you wrote:
>I have a question regarding my emacs programming. When I write code for
>java in emacs I have to manually space and tab to make the code look
>organized. How do I set up .emacs so that it automatically spaces and
>tabs my source code? Thank you.
>
Hi Grace,
The Emacs Lisp package, cc-mode, handles the indenting of code coded in any
of the C family of languages, including Java. cc-mode uses spaces to indent
code, although this is not obvious as cc-mode binds the TAB key to an
indent command. Thus, when you type the TAB key, you are invoking this
command, which inserts spaces into the current line, with the number of
spaces being determined by the syntactic element at the current cursor
position and by the current indentation style. You can customize just about
every aspect of cc-mode, including what indentation style is used, whether
spaces or tabs are inserted, etc.
The JDE sets up cc-mode to do standard Java indentation, using cc-mode's
defaults for indentation character (SPACE) and Java indentation style. You
don't have to do anything in your .emacs file to get default Java
indentation. If you want to customize any aspect of indentation, you should
read the cc-mode info file and follow the instructions there. Any
customization code should be put in a jde-mode hook function defined in
your .emacs file. See the JDE FAQ at the JDE website for more information.
If you have specific questions, please feel free to post them to me or the
JDE mailing list.
I am copying my reply to the JDE mailing list in case someone more
knowledgable than I about indentation may have something to add to or
correct in what I have said.
Good luck,
Paul
>Grace Coy
>
>Software descriptions
>1. Windows/NT
>2. JDE 21
>3. Emacs 20.3.1
>
>;; Grace Coy
>;; 6-8-99
>
>(setq default-frame-alist
> '((cursor-color . "blue")
> (foreground-color . "black")
> (background-color . "light yellow")
> (top . 5) (left . 100)
> (width . 80) (height . 40)))
>
>(setq user-full-name "Grace Coy")
>
>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>;; JDE Stuff ;;
>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>;; Update the Emacs load-path to include the path to
>;; the JDE. This code assumes that you have installed
>;; the JDE in the specified subdirectory of your home
>;; directory.
>(setq load-path
> (nconc
> '(
> "/Emacs20.3.1/jde-2_1_4"
> ;; Add paths to other add-on packages here.
> )
> load-path))
>;; Tell Emacs to load the entire JDE package at startup (only once).
>(require 'jde)
>;; Sets the basic indentation for Java source files
>;; to two spaces.
>(defun my-jde-mode-hook ()
> (setq c-basic-offset 2))
>
>(add-hook 'jde-mode-hook 'my-jde-mode-hook)
>
>;; Include the following only if you want to run
>;; bash as your shell.
>
>;; Setup Emacs to run bash as its primary shell.
>;;(setq binary-process-input t)
>;;(setq shell-file-name "bash")
>;;(setq explicit-shell-file-name shell-file-name)
>;;(setenv "SHELL" shell-file-name)
>;;(setq explicit-sh-args '("-login" "-i"))
>;;(setq w32-quote-process-args ?\") ;; Use Cygnus quoting rules.
>
>;; Configure Emacs to use the default browser on your system
>;; to display the JDE documentation.
>;;(defvar shell-execute-helper "shelex.exe")
>;;(defun shell-execute-url (url &optional new-window)
>;; "Invoke the shell-execute-helper program to call ShellExecute and
launch
>;; or re-direct a web browser on the specified url."
>;; (interactive "sURL: ")
>;; (call-process shell-execute-helper nil nil nil url))
>;;(setq browse-url-browser-function 'shell-execute-url)
>(custom-set-variables
> '(jde-compile-option-command-line-args "-g")
> '(jde-db-option-classpath nil)
> '(jde-db-source-directories (quote ("d:/jdk1.2/src/")))
> '(jde-gen-class-buffer-template (quote ("(funcall
>jde-gen-boilerplate-function) 'n" "\"/**\" 'n" "\" * Applied
>Research Laboratories \" 'n" "\" * The University of Texas at Austin
>\" 'n" "\" * \" 'n" "\" * \"" "\" File: \" (file-name-nondirectory
>buffer-file-name) 'n" "\" *\" 'n" "\" *\" 'n" "\" * Created: \"
>(current-time-string) 'n" "\" *\" 'n" "\" * Author \" (user-full-name) 'n"
>"\" * Revision History:\" 'n" "\" */\" 'n>" "'n>" "\"public class \""
>"(file-name-sans-extension (file-name-nondirectory buffer-file-name))" "\"
>\" (jde-gen-get-super-class) \" {\" 'n> 'n>" "\"public \""
>"(file-name-sans-extension (file-name-nondirectory buffer-file-name))" "\"()
>{\" 'n>" "'p 'n>" "\"}\" 'n>" "'n>" "\"} // \"" "(file-name-sans-extension
>(file-name-nondirectory buffer-file-name))" "'n>")))
> '(jde-run-option-classpath nil))
>(custom-set-faces)
>(defun my-jde-mode-hook ()
> (setq c-basic-offset 2))
> (add-hook 'jde-mode-hook 'my-jde-mode-hook)