* java indentation
@ 2002-11-13 20:46 chris.danx
2002-11-13 21:49 ` Benjamin Lewis
0 siblings, 1 reply; 5+ messages in thread
From: chris.danx @ 2002-11-13 20:46 UTC (permalink / raw)
Hi,
How can you change the indentation style for Java(/c++) to bsd style
(via .emacs)? For C, this worked...
(add-hook 'c-mode-common-hook
(function
(lambda () (c-set-style "bsd") (setq c-basic-offset 4))))
but I can't figure out how to get this to work for cc-mode (java uses cc
mode right?). Someone thought that should work for Java, but it won't.
Does anyone know how to do this?
Cheers,
Chris
--
for personal replies change spamoff to chris
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: java indentation
2002-11-13 20:46 java indentation chris.danx
@ 2002-11-13 21:49 ` Benjamin Lewis
2002-11-13 22:16 ` chris.danx
0 siblings, 1 reply; 5+ messages in thread
From: Benjamin Lewis @ 2002-11-13 21:49 UTC (permalink / raw)
On Wed, 13 Nov 2002, chris danx wrote:
> Hi,
>
> How can you change the indentation style for Java(/c++) to bsd style (via
> .emacs)? For C, this worked...
>
>
> (add-hook 'c-mode-common-hook
> (function
> (lambda () (c-set-style "bsd") (setq c-basic-offset 4))))
>
> but I can't figure out how to get this to work for cc-mode (java uses cc
> mode right?). Someone thought that should work for Java, but it
> won't. Does anyone know how to do this?
Try adding it to java-mode-hook instead; I do something like this and it
works for me.
--
Benjamin Lewis
Amoebit:
Amoeba/rabbit cross; it can multiply and divide at the same time.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Java indentation
@ 2003-04-04 13:10 Antti P Miettinen
2003-04-10 5:37 ` Antti P Miettinen
0 siblings, 1 reply; 5+ messages in thread
From: Antti P Miettinen @ 2003-04-04 13:10 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Java indentation
2003-04-04 13:10 Java indentation Antti P Miettinen
@ 2003-04-10 5:37 ` Antti P Miettinen
0 siblings, 0 replies; 5+ messages in thread
From: Antti P Miettinen @ 2003-04-10 5:37 UTC (permalink / raw)
Replying to myself..
> Does the below patch make sense? [..]
Unfortunately the c-Java-method-key I hastily constructed does not
match all possible method definitions and matches things that are not
method definitions (e.g. for (..) constructs). The below diff against
cc-langs.el should do better. Should I resend the complete diff?
Should I use savannah instead of mail? To bug-gnu-emacs or to
bug-cc-mode?
--- /usr/share/emacs/21.2/lisp/progmodes/cc-langs.el 2001-10-22 04:26:15.000000000 +0300
+++ /home/apm/elisp/cc-langs.el 2003-04-09 19:12:03.000000000 +0300
@@ -335,6 +335,24 @@
;; 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|onearg 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-Java-specifier-kwds "\\)\\>\\s +\\)*"
+ "\\(" c-symbol-key "\\s +\\)?" ;return type
+ c-symbol-key ;name of method
+ "\\s *"
+ 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)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-04-10 5:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-13 20:46 java indentation chris.danx
2002-11-13 21:49 ` Benjamin Lewis
2002-11-13 22:16 ` chris.danx
-- strict thread matches above, loose matches on Subject: below --
2003-04-04 13:10 Java indentation Antti P Miettinen
2003-04-10 5:37 ` Antti P Miettinen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.