From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Antti P Miettinen Newsgroups: gmane.emacs.bugs Subject: Java indentation Date: Fri, 04 Apr 2003 16:10:38 +0300 (EEST) Sender: bug-gnu-emacs-bounces+gnu-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: <20030404.161038.125125346.apm@brigitte.dna.fi> Reply-To: apm@dna.fi NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1049462053 30160 80.91.224.249 (4 Apr 2003 13:14:13 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2003 13:14:13 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+gnu-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 04 15:14:12 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 191R1H-0007qJ-00 for ; Fri, 04 Apr 2003 15:14:11 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 191R1V-000455-06 for gnu-bug-gnu-emacs@m.gmane.org; Fri, 04 Apr 2003 08:14:25 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 191R18-0003Ve-00 for bug-gnu-emacs@gnu.org; Fri, 04 Apr 2003 08:14:02 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 191R12-0003Gu-00 for bug-gnu-emacs@gnu.org; Fri, 04 Apr 2003 08:13:58 -0500 Original-Received: from brigitte.dna.fi ([62.236.152.115]) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10.13) id 191QyD-00017t-00 for bug-gnu-emacs@gnu.org; Fri, 04 Apr 2003 08:11:02 -0500 Original-Received: from localhost (localhost [::1]) by brigitte.dna.fi (8.11.6/8.11.3) with ESMTP id h34DAcL10244 for ; Fri, 4 Apr 2003 16:10:38 +0300 (EEST) Original-To: bug-gnu-emacs@gnu.org X-Mailer: Mew version 2.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: bug-gnu-emacs-bounces+gnu-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:4724 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:4724 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)