[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Java indentation
From: |
Antti P Miettinen |
Subject: |
Java indentation |
Date: |
Fri, 04 Apr 2003 16:10:38 +0300 (EEST) |
Does the below patch make sense? In order to make the following work:
---(from my .emacs)---(from my .emacs)---(from my .emacs)---
;; ...
(c-add-style
"apm"
;; ...
(c-offsets-alist
(objc-method-args-cont . c-lineup-arglist)
;; ...
(defun my-java-mode-hook ()
;; ...
(c-set-offset 'arglist-cont-nonempty '+))
;; ...
---(from my .emacs)---(from my .emacs)---(from my .emacs)---
i.e. to make method definitions and method calls indent differently
for Java:
public class Test
{
public void stoopidFunction(int x,
int y)
{
if (x > 0)
stoopidFunction(x - 1,
y);
}
}
I had to make the following changes to emacs-21.2 lisp files:
--- lisp/progmodes/cc-mode.el~ 2001-05-04 12:02:56.000000000 +0300
+++ lisp/progmodes/cc-mode.el 2003-04-04 15:17:25.000000000 +0300
@@ -643,7 +643,7 @@
c-conditional-key c-Java-conditional-key
c-comment-start-regexp c-Java-comment-start-regexp
c-class-key c-Java-class-key
- c-method-key nil
+ c-method-key c-Java-method-key
c-baseclass-key nil
c-recognize-knr-p nil
c-inexpr-class-key c-Java-inexpr-class-key
--- lisp/progmodes/cc-align.el~ 2001-07-16 09:46:48.000000000 +0300
+++ lisp/progmodes/cc-align.el 2003-04-04 15:01:11.000000000 +0300
@@ -61,7 +61,10 @@
;; is good when offset is +, but bad
;; when it is c-lineup-arglist, so we
;; have to special case a kludge here.
- (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
+ (if (memq (car langelem)
+ '(objc-method-args-cont
+ arglist-intro
+ arglist-cont-nonempty))
(progn
(beginning-of-line)
(backward-up-list 1)
--- lisp/progmodes/cc-engine.el~ 2001-11-20 00:54:41.000000000 +0200
+++ lisp/progmodes/cc-engine.el 2003-04-04 15:08:23.000000000 +0300
@@ -1533,7 +1533,8 @@
(save-excursion
(save-restriction
(beginning-of-line)
- (let* ((indent-point (point))
+ (let* ((syntax-point nil)
+ (indent-point (point))
(case-fold-search nil)
(fullstate (c-parse-state))
(state fullstate)
@@ -2050,7 +2051,17 @@
(c-forward-syntactic-ws)
(c-add-syntax 'topmost-intro-cont (c-point 'boi)))
)) ; end CASE 5
- ;; (CASE 6 has been removed.)
+ ;; (CASE 6 has been reborn.)
+ ((and c-method-key
+ (c-major-mode-is 'java-mode)
+ (save-excursion
+ (c-beginning-of-statement-1 lim)
+ (beginning-of-line)
+ (setq syntax-point (point))
+ (looking-at c-method-key)))
+ (progn
+ (goto-char syntax-point)
+ (c-add-syntax 'objc-method-args-cont (point))))
;; CASE 7: line is an expression, not a statement. Most
;; likely we are either in a function prototype or a function
;; call argument list
--- lisp/progmodes/cc-langs.el~ 2001-07-16 09:46:48.000000000 +0300
+++ lisp/progmodes/cc-langs.el 2003-04-04 15:16:08.000000000 +0300
@@ -335,6 +335,22 @@
;; since it is considered the end of //-comments.
"[ \t\n]*" c-symbol-key))
+(defconst c-Java-argdef-key
+ (concat c-symbol-key "\\s +" c-symbol-key))
+
+;; This does not match empty arglist cause indentation is not
+;; an issue then
+(defconst c-Java-arglistdef-key
+ (concat "(\\(\\s *" c-Java-argdef-key "\\s *,\\s *\\)*"
+ "\\s *" c-Java-argdef-key "\\s *)?"))
+
+(defconst c-Java-method-key
+ (concat
+ "\\s *\\(" c-protection-key "\\s +\\)?"
+ "\\(" c-symbol-key "\\s +\\)?" ;return type
+ c-symbol-key "\\s *" ;name of method
+ c-Java-arglistdef-key)) ;arglist
+
;; comment starter definitions for various languages. language specific
(defconst c-C++-comment-start-regexp "/[/*]")
(defconst c-C-comment-start-regexp c-C++-comment-start-regexp)
- Java indentation,
Antti P Miettinen <=