(c-hungry-delete-forward)
(c-hungry-delete-backwards)))
-(defvar c--disable-fix-of-bug-33794 nil
- "If non-nil disable alans controversional fix of 33794.
-This fix breaks most features of `electric-pair-mode' by
-incompletely reimplementing in in this mode.")
-
-(defmacro c--with-post-self-insert-hook-maybe (&rest body)
- `(let ((post-self-insert-hook
- (if c--disable-fix-of-bug-33794
- post-self-insert-hook
- ;; Acording to AM: Disable random functionality to get
- ;; defined functionality from `self-insert-command'
- nil)))
- ,@body))
+(defun c-self-insert-command (arg)
+ ;; If `c-auto-newline' is on we use our own implementation of
+ ;; `electric-pair-mode' and `electric-layout-mode' doesn't make
+ ;; sense.
+ (let ((electric-layout-mode (not c-auto-newline))
+ (electric-pair-mode (not c-auto-newline)))
+ (self-insert-command arg)))
(defun c-electric-pound (arg)
"Insert a \"#\".
(eq (char-before) ?\\))))
(c-in-literal)))
;; do nothing special
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
;; place the pound character at the left edge
(let ((pos (- (point-max) (point)))
(bolp (bolp)))
;; Insert the brace. Note that expand-abbrev might reindent
;; the line here if there's a preceding "else" or something.
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
;; Emulate `electric-pair-mode'.
- (unless c--disable-fix-of-bug-33794
- (when (and (boundp 'electric-pair-mode)
- electric-pair-mode)
- (let ((size (buffer-size))
- (c-in-electric-pair-functionality t)
- post-self-insert-hook)
- (electric-pair-post-self-insert-function)
- (setq got-pair-} (and at-eol
- (eq (c-last-command-char) ?{)
- (eq (char-after) ?}))
- electric-pair-deletion (< (buffer-size) size))))
-
- ;; Perform any required CC Mode electric actions.
- (cond
- ((or literal arg (not c-electric-flag) active-region))
- ((not at-eol)
- (c-indent-line))
- (electric-pair-deletion
- (c-indent-line)
- (c-do-brace-electrics 'ignore nil))
- (t (c-do-brace-electrics nil nil)
- (when got-pair-}
- (save-excursion
- (forward-char)
- (c-do-brace-electrics 'assume 'ignore))
- (c-indent-line)))))
-
+ (when (and (boundp 'electric-pair-mode)
+ electric-pair-mode
+ c-auto-newline)
+ (let ((size (buffer-size))
+ (c-in-electric-pair-functionality t)
+ post-self-insert-hook)
+ (electric-pair-post-self-insert-function)
+ (setq got-pair-} (and at-eol
+ (eq (c-last-command-char) ?{)
+ (eq (char-after) ?}))
+ electric-pair-deletion (< (buffer-size) size))))
+
+ ;; Perform any required CC Mode electric actions.
+ (cond
+ ((or literal arg (not c-electric-flag) active-region))
+ ((not at-eol)
+ (c-indent-line))
+ (electric-pair-deletion
+ (c-indent-line)
+ (c-do-brace-electrics 'ignore nil))
+ (t (c-do-brace-electrics nil nil)
+ (when got-pair-}
+ (save-excursion
+ (forward-char)
+ (c-do-brace-electrics 'assume 'ignore))
+ (c-indent-line))))
;; blink the paren
c-electric-flag
(eq (c-last-command-char) ?/)
(eq (char-before) (if literal ?* ?/))))
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
(if indentp
(indent-according-to-mode))))
this indentation is inhibited."
(interactive "*P")
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
;; if we are in a literal, or if arg is given do not reindent the
;; current line, unless this star introduces a comment-only line.
(if (c-save-buffer-state ()
(setq lim (c-most-enclosing-brace (c-parse-state))
literal (c-in-literal lim)))
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
(if (and c-electric-flag (not literal) (not arg))
;; do all cleanups and newline insertions if c-auto-newline is on.
newlines is-scope-op
;; shut this up
(c-echo-syntactic-information-p nil))
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
;; Any electric action?
(if (and c-electric-flag (not literal) (not arg))
;; Unless we're at EOL, only re-indentation happens.
(let ((c-echo-syntactic-information-p nil)
final-pos found-delim case-fold-search)
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
(setq final-pos (point))
;;;; 2010-01-31: There used to be code here to put a syntax-table text
;; shut this up
(c-echo-syntactic-information-p nil)
case-fold-search)
- (c--with-post-self-insert-hook-maybe
- (self-insert-command (prefix-numeric-value arg)))
+ (c-self-insert-command (prefix-numeric-value arg))
(if (and (not arg) (not literal))
(let* ( ;; We want to inhibit blinking the paren since this will
(insert-and-inherit "} catch (")))
;; Apply `electric-pair-mode' stuff.
- (unless c--disable-fix-of-bug-33794
- (when (and (boundp 'electric-pair-mode)
- electric-pair-mode)
- (let (post-self-insert-hook)
- (electric-pair-post-self-insert-function))))
+ (when (and c-auto-newline
+ (boundp 'electric-pair-mode)
+ electric-pair-mode)
+ (let (post-self-insert-hook)
+ (electric-pair-post-self-insert-function)))
;; Check for clean-ups at function calls. These two DON'T need
;; `c-electric-flag' or `c-syntactic-indentation' set.