From 395e55129c78e6507342d906030061bf97aa9223 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 8 Sep 2024 22:41:55 +0200 Subject: emacs: Configure auto newline insertion --- .config/emacs/init.el | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to '.config/emacs') diff --git a/.config/emacs/init.el b/.config/emacs/init.el index aad1603..8bebd23 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -667,9 +667,18 @@ font name, font weight, and font height in that order.") '(after) '(before after))) -(defun x-c (_syn _pos) - (message "OMG") - '(before)) +(defun x-c-semi&comma-after-return () + "‘c-mode’ criteria to avoid automatic newline insertion after entering +a semicolon following a return statement." + (catch 'return + (let ((end-position (point))) + (save-excursion + (goto-char (line-beginning-position)) + (save-match-data + (while (re-search-forward "\\" end-position 'noerror) + (when (eq (get-text-property (1- (point)) 'face) + 'font-lock-keyword-face) + (throw 'return 'stop)))))))) (c-add-style "mango" @@ -680,6 +689,10 @@ font name, font weight, and font height in that order.") (c-block-comment-prefix . "") (c-comment-only-line-offset . 0) (c-label-minimum-indentation . 0) + (c-hanging-semi&comma-criteria . (x-c-semi&comma-after-return + c-semi&comma-inside-parenlist + c-semi&comma-no-newlines-before-nonblanks + c-semi&comma-no-newlines-for-oneline-inliners)) (c-cleanup-list . (brace-else-brace brace-elseif-brace brace-catch-brace -- cgit v1.2.3