emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp/progmodes cc-vars.el cc-langs.el cc-...


From: Alan Mackenzie
Subject: [Emacs-diffs] emacs/lisp/progmodes cc-vars.el cc-langs.el cc-...
Date: Thu, 30 Apr 2009 10:36:25 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Alan Mackenzie <acmacm> 09/04/30 10:36:25

Modified files:
        lisp/progmodes : cc-vars.el cc-langs.el cc-align.el 

Log message:
        Enhancements for Objective-C:
        
        cc-vars.el
        (c-objc-method-arg-min-delta-to-bracket,
        c-objc-method-arg-unfinished-offset, c-objc-method-parameter-offset): 
New
        variables.
        (c-offsets-alist): Use c-lineup-ObjC-method-call-colons in entry for
        objc-method-call-cont.
        
        cc-langs.el (c-constant-kwds): New ObjC keywords "YES", "NO",
        "NS_DURING", "NS_HANDLER", "NS_ENDHANDLER".
        
        cc-align.el (c-lineup-ObjC-method-call-colons): New function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/progmodes/cc-vars.el?cvsroot=emacs&r1=1.72&r2=1.73
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/progmodes/cc-langs.el?cvsroot=emacs&r1=1.65&r2=1.66
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/progmodes/cc-align.el?cvsroot=emacs&r1=1.43&r2=1.44

Patches:
Index: cc-vars.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-vars.el,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- cc-vars.el  26 Feb 2009 03:54:04 -0000      1.72
+++ cc-vars.el  30 Apr 2009 10:36:24 -0000      1.73
@@ -936,6 +936,45 @@
   :type 'integer
   :group 'c)
 
+(defcustom c-objc-method-arg-min-delta-to-bracket 2
+  "*Minimum number of chars to the opening bracket.
+
+Consider this ObjC snippet:
+
+       [foo blahBlah: fred
+       |<-x->|barBaz: barney
+
+If `x' is less than this number then `c-lineup-ObjC-method-call-colons'
+will defer the indentation decision to the next function.  By default
+this is `c-lineup-ObjC-method-call', which would align it like:
+
+       [foo blahBlahBlah: fred
+            thisIsTooDamnLong: barney
+
+This behaviour can be overridden by customizing the indentation of
+`objc-method-call-cont' in the \"objc\" style."
+  :type 'integer
+  :group 'c)
+
+(defcustom c-objc-method-arg-unfinished-offset 4
+  "*Offset relative to bracket if first selector is on a new line.
+
+    [aaaaaaaaa
+    |<-x->|bbbbbbb:  cccccc
+             ddddd: eeee];"
+  :type 'integer
+  :group 'c)
+
+(defcustom c-objc-method-parameter-offset 4
+  "*Offset for selector parameter on a new line (relative to first selector.
+
+    [aaaaaaa bbbbbbbbbb:
+            |<-x->|cccccccc
+                    ddd: eeee
+                   ffff: ggg];"
+  :type 'integer
+  :group 'c)
+
 (defcustom c-default-style '((java-mode . "java") (awk-mode . "awk")
                             (other . "gnu"))
   "*Style which gets installed by default when a file is visited.
@@ -1121,7 +1160,8 @@
        ;; Anchor pos: Boi.
        (objc-method-args-cont . c-lineup-ObjC-method-args)
        ;; Anchor pos: At the method start (always at boi).
-       (objc-method-call-cont . c-lineup-ObjC-method-call)
+       (objc-method-call-cont . (c-lineup-ObjC-method-call-colons
+                               c-lineup-ObjC-method-call +))
        ;; Anchor pos: At the open bracket.
        (extern-lang-open      . 0)
        (namespace-open        . 0)

Index: cc-langs.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-langs.el,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- cc-langs.el 21 Feb 2009 16:10:40 -0000      1.65
+++ cc-langs.el 30 Apr 2009 10:36:24 -0000      1.66
@@ -2149,7 +2149,7 @@
   t       nil
   (c c++) '("NULL" ;; Not a keyword, but practically works as one.
            "false" "true")             ; Defined in C99.
-  objc    '("nil" "Nil")
+  objc    '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
   idl     '("TRUE" "FALSE")
   java    '("true" "false" "null") ; technically "literals", not keywords
   pike    '("UNDEFINED")) ;; Not a keyword, but practically works as one.

Index: cc-align.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-align.el,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- cc-align.el 11 Jan 2009 00:37:05 -0000      1.43
+++ cc-align.el 30 Apr 2009 10:36:25 -0000      1.44
@@ -907,8 +907,48 @@
           )
       (- target-col open-bracket-col extra))))
 
+(defun c-lineup-ObjC-method-call-colons (langelem)
+  "Line up selector args as Project Builder / XCode: colons of first
+   selector portions on successive lines are aligned.  If no decision can
+   be made return NIL, so that other lineup methods can be tried.  This is
+   typically chained with `c-lineup-ObjC-method-call'.
+
+Works with: objc-method-call-cont."
+  (save-excursion
+    (catch 'no-idea
+      (let* ((method-arg-len (progn
+                              (back-to-indentation)
+                              (if (search-forward ":" (c-point 'eol) 'move)
+                                  (- (point) (c-point 'boi))
+                                ; no complete argument to indent yet
+                                (throw 'no-idea nil))))
+
+            (extra (save-excursion 
+                      ; indent parameter to argument if needed
+                     (back-to-indentation)
+                     (c-backward-syntactic-ws (c-langelem-pos langelem))
+                     (if (eq ?: (char-before))
+                         c-objc-method-parameter-offset 0)))
+
+            (open-bracket-col (c-langelem-col langelem))
+
+            (arg-ralign-colon-ofs (progn
+                       (forward-char) ; skip over '['
+                       ; skip over object/class name
+                       ; and first argument
+                       (c-forward-sexp 2)
+                       (if (search-forward ":" (c-point 'eol) 'move)
+                           (- (current-column) open-bracket-col
+                              method-arg-len extra)
+                         ; previous arg has no param
+                         c-objc-method-arg-unfinished-offset))))
+
+       (if (>= arg-ralign-colon-ofs c-objc-method-arg-min-delta-to-bracket)
+           (+ arg-ralign-colon-ofs extra)
+         (throw 'no-idea nil))))))
+
 (defun c-lineup-ObjC-method-args (langelem)
-  "Line up the colons that separate args.
+  "Line up the colons that separate args in a method declaration.
 The colon on the current line is aligned with the one on the first
 line.
 
@@ -932,7 +972,7 @@
          c-basic-offset)))))
 
 (defun c-lineup-ObjC-method-args-2 (langelem)
-  "Line up the colons that separate args.
+  "Line up the colons that separate args in a method declaration.
 The colon on the current line is aligned with the one on the previous
 line.
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]