unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Java indentation
@ 2003-04-04 13:10 Antti P Miettinen
  2003-04-10  5:37 ` Antti P Miettinen
  0 siblings, 1 reply; 2+ 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] 2+ 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; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2003-04-10  5:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).