diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/cc-align.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index f30477dc787..c49bdc5c518 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el | |||
| @@ -790,6 +790,38 @@ arglist-cont-nonempty." | |||
| 790 | (or (c-lineup-assignments langelem) | 790 | (or (c-lineup-assignments langelem) |
| 791 | c-basic-offset)) | 791 | c-basic-offset)) |
| 792 | 792 | ||
| 793 | (defun c-lineup-ternary-bodies (langelem) | ||
| 794 | "Line up true and false branches of a ternary operator (i.e. ‘?:’). | ||
| 795 | More precisely, if the line starts with a colon which is a part of | ||
| 796 | a said operator it with corresponding question mark; otherwise return | ||
| 797 | nil. For example: | ||
| 798 | |||
| 799 | return arg % 2 == 0 ? arg / 2 | ||
| 800 | : (3 * arg + 1); <- c-lineup-ternary-bodies | ||
| 801 | |||
| 802 | Works with: arglist-cont, arglist-cont-nonempty and statement-cont. | ||
| 803 | " | ||
| 804 | (save-excursion | ||
| 805 | (back-to-indentation) | ||
| 806 | (when (and (eq ?: (char-after)) | ||
| 807 | (not (eq ?: (char-after (1+ (point)))))) | ||
| 808 | (let ((limit (c-langelem-pos langelem)) (depth 1)) | ||
| 809 | (catch 'done | ||
| 810 | (while (c-syntactic-skip-backward "^?:" limit t) | ||
| 811 | (goto-char (1- (point))) | ||
| 812 | (cond ((eq (char-after) ??) | ||
| 813 | ;; If we’ve found a question mark, decrease depth. If we’re | ||
| 814 | ;; reached zero, we’ve found the one we were looking for. | ||
| 815 | (when (zerop (setq depth (1- depth))) | ||
| 816 | (throw 'done (vector (current-column))))) | ||
| 817 | ((or (eq ?: (char-before)) (eq ?? (char-before))) | ||
| 818 | ;; Step over ‘::’ and ‘?:’ operators. We don’t have to | ||
| 819 | ;; handle ‘?:’ here but doing so saves an iteration. | ||
| 820 | (if (eq (point) limit) | ||
| 821 | (throw 'done nil) | ||
| 822 | (goto-char (1- (point))))) | ||
| 823 | ((setq depth (1+ depth)))))))))) ; Otherwise increase depth. | ||
| 824 | |||
| 793 | (defun c-lineup-cascaded-calls (langelem) | 825 | (defun c-lineup-cascaded-calls (langelem) |
| 794 | "Line up \"cascaded calls\" under each other. | 826 | "Line up \"cascaded calls\" under each other. |
| 795 | If the line begins with \"->\" or \".\" and the preceding line ends | 827 | If the line begins with \"->\" or \".\" and the preceding line ends |