diff options
| author | Alan Mackenzie | 2009-04-30 10:36:24 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2009-04-30 10:36:24 +0000 |
| commit | f0e4b2f240536ea8bc5aa66e559d62083c33e209 (patch) | |
| tree | a373ad76fe0be8c9d0259914a3ed5712179e0b72 | |
| parent | 9e95e9f4b50f69252a8af6754d6710bd84fb812d (diff) | |
| download | emacs-f0e4b2f240536ea8bc5aa66e559d62083c33e209.tar.gz emacs-f0e4b2f240536ea8bc5aa66e559d62083c33e209.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-align.el | 44 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/cc-vars.el | 42 |
3 files changed, 84 insertions, 4 deletions
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index ff22eba0c33..c9dd92f46b2 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el | |||
| @@ -907,8 +907,48 @@ Works with: objc-method-call-cont." | |||
| 907 | ) | 907 | ) |
| 908 | (- target-col open-bracket-col extra)))) | 908 | (- target-col open-bracket-col extra)))) |
| 909 | 909 | ||
| 910 | (defun c-lineup-ObjC-method-call-colons (langelem) | ||
| 911 | "Line up selector args as Project Builder / XCode: colons of first | ||
| 912 | selector portions on successive lines are aligned. If no decision can | ||
| 913 | be made return NIL, so that other lineup methods can be tried. This is | ||
| 914 | typically chained with `c-lineup-ObjC-method-call'. | ||
| 915 | |||
| 916 | Works with: objc-method-call-cont." | ||
| 917 | (save-excursion | ||
| 918 | (catch 'no-idea | ||
| 919 | (let* ((method-arg-len (progn | ||
| 920 | (back-to-indentation) | ||
| 921 | (if (search-forward ":" (c-point 'eol) 'move) | ||
| 922 | (- (point) (c-point 'boi)) | ||
| 923 | ; no complete argument to indent yet | ||
| 924 | (throw 'no-idea nil)))) | ||
| 925 | |||
| 926 | (extra (save-excursion | ||
| 927 | ; indent parameter to argument if needed | ||
| 928 | (back-to-indentation) | ||
| 929 | (c-backward-syntactic-ws (c-langelem-pos langelem)) | ||
| 930 | (if (eq ?: (char-before)) | ||
| 931 | c-objc-method-parameter-offset 0))) | ||
| 932 | |||
| 933 | (open-bracket-col (c-langelem-col langelem)) | ||
| 934 | |||
| 935 | (arg-ralign-colon-ofs (progn | ||
| 936 | (forward-char) ; skip over '[' | ||
| 937 | ; skip over object/class name | ||
| 938 | ; and first argument | ||
| 939 | (c-forward-sexp 2) | ||
| 940 | (if (search-forward ":" (c-point 'eol) 'move) | ||
| 941 | (- (current-column) open-bracket-col | ||
| 942 | method-arg-len extra) | ||
| 943 | ; previous arg has no param | ||
| 944 | c-objc-method-arg-unfinished-offset)))) | ||
| 945 | |||
| 946 | (if (>= arg-ralign-colon-ofs c-objc-method-arg-min-delta-to-bracket) | ||
| 947 | (+ arg-ralign-colon-ofs extra) | ||
| 948 | (throw 'no-idea nil)))))) | ||
| 949 | |||
| 910 | (defun c-lineup-ObjC-method-args (langelem) | 950 | (defun c-lineup-ObjC-method-args (langelem) |
| 911 | "Line up the colons that separate args. | 951 | "Line up the colons that separate args in a method declaration. |
| 912 | The colon on the current line is aligned with the one on the first | 952 | The colon on the current line is aligned with the one on the first |
| 913 | line. | 953 | line. |
| 914 | 954 | ||
| @@ -932,7 +972,7 @@ Works with: objc-method-args-cont." | |||
| 932 | c-basic-offset))))) | 972 | c-basic-offset))))) |
| 933 | 973 | ||
| 934 | (defun c-lineup-ObjC-method-args-2 (langelem) | 974 | (defun c-lineup-ObjC-method-args-2 (langelem) |
| 935 | "Line up the colons that separate args. | 975 | "Line up the colons that separate args in a method declaration. |
| 936 | The colon on the current line is aligned with the one on the previous | 976 | The colon on the current line is aligned with the one on the previous |
| 937 | line. | 977 | line. |
| 938 | 978 | ||
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 1a4fba2c8a1..cc35daa02ff 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -2149,7 +2149,7 @@ This construct is \"<keyword> <expression> :\"." | |||
| 2149 | t nil | 2149 | t nil |
| 2150 | (c c++) '("NULL" ;; Not a keyword, but practically works as one. | 2150 | (c c++) '("NULL" ;; Not a keyword, but practically works as one. |
| 2151 | "false" "true") ; Defined in C99. | 2151 | "false" "true") ; Defined in C99. |
| 2152 | objc '("nil" "Nil") | 2152 | objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER") |
| 2153 | idl '("TRUE" "FALSE") | 2153 | idl '("TRUE" "FALSE") |
| 2154 | java '("true" "false" "null") ; technically "literals", not keywords | 2154 | java '("true" "false" "null") ; technically "literals", not keywords |
| 2155 | pike '("UNDEFINED")) ;; Not a keyword, but practically works as one. | 2155 | pike '("UNDEFINED")) ;; Not a keyword, but practically works as one. |
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index fa5aa538d72..a1f7d3ad3f2 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el | |||
| @@ -936,6 +936,45 @@ this variable to nil." | |||
| 936 | :type 'integer | 936 | :type 'integer |
| 937 | :group 'c) | 937 | :group 'c) |
| 938 | 938 | ||
| 939 | (defcustom c-objc-method-arg-min-delta-to-bracket 2 | ||
| 940 | "*Minimum number of chars to the opening bracket. | ||
| 941 | |||
| 942 | Consider this ObjC snippet: | ||
| 943 | |||
| 944 | [foo blahBlah: fred | ||
| 945 | |<-x->|barBaz: barney | ||
| 946 | |||
| 947 | If `x' is less than this number then `c-lineup-ObjC-method-call-colons' | ||
| 948 | will defer the indentation decision to the next function. By default | ||
| 949 | this is `c-lineup-ObjC-method-call', which would align it like: | ||
| 950 | |||
| 951 | [foo blahBlahBlah: fred | ||
| 952 | thisIsTooDamnLong: barney | ||
| 953 | |||
| 954 | This behaviour can be overridden by customizing the indentation of | ||
| 955 | `objc-method-call-cont' in the \"objc\" style." | ||
| 956 | :type 'integer | ||
| 957 | :group 'c) | ||
| 958 | |||
| 959 | (defcustom c-objc-method-arg-unfinished-offset 4 | ||
| 960 | "*Offset relative to bracket if first selector is on a new line. | ||
| 961 | |||
| 962 | [aaaaaaaaa | ||
| 963 | |<-x->|bbbbbbb: cccccc | ||
| 964 | ddddd: eeee];" | ||
| 965 | :type 'integer | ||
| 966 | :group 'c) | ||
| 967 | |||
| 968 | (defcustom c-objc-method-parameter-offset 4 | ||
| 969 | "*Offset for selector parameter on a new line (relative to first selector. | ||
| 970 | |||
| 971 | [aaaaaaa bbbbbbbbbb: | ||
| 972 | |<-x->|cccccccc | ||
| 973 | ddd: eeee | ||
| 974 | ffff: ggg];" | ||
| 975 | :type 'integer | ||
| 976 | :group 'c) | ||
| 977 | |||
| 939 | (defcustom c-default-style '((java-mode . "java") (awk-mode . "awk") | 978 | (defcustom c-default-style '((java-mode . "java") (awk-mode . "awk") |
| 940 | (other . "gnu")) | 979 | (other . "gnu")) |
| 941 | "*Style which gets installed by default when a file is visited. | 980 | "*Style which gets installed by default when a file is visited. |
| @@ -1121,7 +1160,8 @@ can always override the use of `c-default-style' by making calls to | |||
| 1121 | ;; Anchor pos: Boi. | 1160 | ;; Anchor pos: Boi. |
| 1122 | (objc-method-args-cont . c-lineup-ObjC-method-args) | 1161 | (objc-method-args-cont . c-lineup-ObjC-method-args) |
| 1123 | ;; Anchor pos: At the method start (always at boi). | 1162 | ;; Anchor pos: At the method start (always at boi). |
| 1124 | (objc-method-call-cont . c-lineup-ObjC-method-call) | 1163 | (objc-method-call-cont . (c-lineup-ObjC-method-call-colons |
| 1164 | c-lineup-ObjC-method-call +)) | ||
| 1125 | ;; Anchor pos: At the open bracket. | 1165 | ;; Anchor pos: At the open bracket. |
| 1126 | (extern-lang-open . 0) | 1166 | (extern-lang-open . 0) |
| 1127 | (namespace-open . 0) | 1167 | (namespace-open . 0) |