[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc
From: |
Alan Mackenzie |
Subject: |
bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode |
Date: |
23 Dec 2018 14:48:37 -0000 |
User-agent: |
tin/2.4.2-20171224 ("Lochhead") (UNIX) (FreeBSD/11.2-RELEASE-p4 (amd64)) |
Hello again, Beatrix.
In article <mailman.5894.1545155289.1284.bug-gnu-emacs@gnu.org> you wrote:
> When using cc-mode, turning on electric-pair-mode causes the
> auto-newline minor mode to stop inserting newlines where expected. This
> is relevant to the formatting of C# code with the Allman/BSD brace style
> in particular, though it would be nice if these modes specifically did
> work together.
> In GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS
> appkit-1348.17 Version 10.10.5 (Build 14F2511))
> of 2018-05-30 built on builder10-10.porkrind.org
> Windowing system distributor 'Apple', version 10.3.1671
> Recent messages:
> Saving file /Users/bea/.emacs.d/lisp/dotnet.el...
> Wrote /Users/bea/.emacs.d/lisp/dotnet.el
> ; expected
> Undo!
> ; expected
> Undo! [2 times]
> ; expected
> Auto-saving...
> ; expected [2 times]
> Making completion list...
I think the following workaround will give you a lot of what you want.
I've tried it out only on C Mode, however. The pertinent file is in
.../emacs/lisp/progmodes/.
Sadly it is only a workaround, since there doesn't seem to be any
interface to electric-pair-mode usable by programs. However, it should
help, whilst we at Emacs negotiate amongst ourselves.
Happy Christmas, if you celebrate it! (And a good time, otherwise!).
diff -r 7ec0a318802a cc-cmds.el
--- a/cc-cmds.el Thu Dec 20 12:07:55 2018 +0000
+++ b/cc-cmds.el Sun Dec 23 14:34:51 2018 +0000
@@ -721,7 +721,9 @@
;; Insert the brace. Note that expand-abbrev might reindent
;; the line here if there's a preceding "else" or something.
- (self-insert-command (prefix-numeric-value arg))
+ (let (post-self-insert-hook) ; the only way to get dependable
+ ; functionality from self-insert-command.
+ (self-insert-command (prefix-numeric-value arg)))
(when (and c-electric-flag (not literal) (not arg))
(if (not (looking-at "[ \t]*\\\\?$"))
@@ -844,6 +846,15 @@
(c-newline-and-indent))
))))
+ ;; Emulate `electric-pair-mode'.
+ (when (and (boundp 'electric-pair-mode)
+ electric-pair-mode
+ (eq last-command-event ?{))
+ (save-excursion
+ (newline)
+ (let ((last-command-event ?}))
+ (c-electric-brace nil))))
+
;; blink the paren
(and (eq (c-last-command-char) ?\})
(not executing-kbd-macro)
--
Alan Mackenzie (Nuremberg, Germany).
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, (continued)
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Stefan Monnier, 2018/12/22
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Beatrix Klebe, 2018/12/22
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, João Távora, 2018/12/22
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Alan Mackenzie, 2018/12/22
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, João Távora, 2018/12/22
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Alan Mackenzie, 2018/12/23
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, João Távora, 2018/12/23
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Alan Mackenzie, 2018/12/23
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Alan Mackenzie, 2018/12/28
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode, Stefan Monnier, 2018/12/23
Message not available
- bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode,
Alan Mackenzie <=