(defmacro c--call-post-self-insert-hook-more-safely ()
;; Call post-self-insert-hook, if such exists. See comment for
- ;; `c--call-post-self-insert-hook-more-safely-1'.
+ ;; `c--call-post-self-insert-hook-more-safely-1'. This macro should be
+ ;; invoked OUTSIDE of `c-with-string-fences'.
(if (boundp 'post-self-insert-hook)
'(c--call-post-self-insert-hook-more-safely-1)
'(progn)))
(delete-horizontal-space)
(insert (c-last-command-char))
(and (not bolp)
- (goto-char (- (point-max) pos)))
- ))
- (c--call-post-self-insert-hook-more-safely)))
+ (goto-char (- (point-max) pos))))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-point-syntax ()
;; Return the syntactic context of the construct at point. (This is NOT
settings of `c-cleanup-list' are done."
(interactive "*P")
- (c-with-string-fences
- (let (safepos literal
- ;; We want to inhibit blinking the paren since this would be
- ;; most disruptive. We'll blink it ourselves later on.
- (old-blink-paren blink-paren-function)
- blink-paren-function case-fold-search
- (at-eol (looking-at "[ \t]*\\\\?$"))
- (active-region (and (fboundp 'use-region-p) (use-region-p)))
- got-pair-} electric-pair-deletion)
+ (let (safepos literal
+ ;; We want to inhibit blinking the paren since this would be
+ ;; most disruptive. We'll blink it ourselves later on.
+ (old-blink-paren blink-paren-function)
+ blink-paren-function case-fold-search
+ (at-eol (looking-at "[ \t]*\\\\?$"))
+ (active-region (and (fboundp 'use-region-p) (use-region-p)))
+ got-pair-} electric-pair-deletion)
+ (c-with-string-fences
(c-save-buffer-state ()
(setq safepos (c-safe-position (point) (c-parse-state))
literal (c-in-literal safepos)))
;; the line here if there's a preceding "else" or something.
(let (post-self-insert-hook) ; the only way to get defined functionality
; from `self-insert-command'.
- (self-insert-command (prefix-numeric-value arg)))
-
- ;; Emulate `electric-pair-mode'.
- (when (and (boundp 'electric-pair-mode)
- electric-pair-mode)
- (let ((size (buffer-size))
- 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))))
-
+ (self-insert-command (prefix-numeric-value arg))))
+
+ ;; Emulate `electric-pair-mode', outside of `c-with-string-fences'.
+ (when (and (boundp 'electric-pair-mode)
+ electric-pair-mode)
+ (let ((size (buffer-size))
+ 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))))
+
+ (c-with-string-fences
;; Perform any required CC Mode electric actions.
(cond
((or literal arg (not c-electric-flag) active-region))
(save-excursion
(c-save-buffer-state nil
(c-backward-syntactic-ws safepos))
- (funcall old-blink-paren)))
- (c--call-post-self-insert-hook-more-safely))))
+ (funcall old-blink-paren)))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-slash (arg)
"Insert a slash character.
(let (post-self-insert-hook) ; Disable random functionality.
(self-insert-command (prefix-numeric-value arg)))
(if indentp
- (indent-according-to-mode))
- (c--call-post-self-insert-hook-more-safely))))
+ (indent-according-to-mode))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-star (arg)
"Insert a star character.
(skip-chars-backward " \t")
(bolp))))
(let (c-echo-syntactic-information-p) ; shut this up
- (indent-according-to-mode)))
- (c--call-post-self-insert-hook-more-safely)))
+ (indent-according-to-mode))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-semi&comma (arg)
"Insert a comma or semicolon.
(setq add-newline-p (not (eq answer 'stop)))
))
(if add-newline-p
- (c-newline-and-indent)))))
- (c--call-post-self-insert-hook-more-safely))))
+ (c-newline-and-indent)))))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-colon (arg)
"Insert a colon.
;; does a newline go after the colon?
(if (and (memq 'after (cdr-safe newlines))
(not is-scope-op))
- (c-newline-and-indent))))
- (c--call-post-self-insert-hook-more-safely))))
+ (c-newline-and-indent))))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-lt-gt (arg)
"Insert a \"<\" or \">\" character.
numeric argument is supplied, or the point is inside a literal."
(interactive "*P")
- (c-with-string-fences
- (let ((literal (c-save-buffer-state () (c-in-literal)))
- template-delim include-delim
- (c-echo-syntactic-information-p nil)
- final-pos found-delim case-fold-search)
+ (let (template-delim include-delim
+ (c-echo-syntactic-information-p nil)
+ final-pos found-delim case-fold-search)
+ (c-with-string-fences
(let (post-self-insert-hook) ; Disable random functionality.
(self-insert-command (prefix-numeric-value arg)))
(setq final-pos (point))
;;;; property on the new < or > and its mate (if any) when they are template
;;;; parens. This is now done in an after-change function.
- (when (and (not arg) (not literal))
+ (when (and (not arg)
+ (not (c-save-buffer-state () (c-in-literal))))
;; Have we got a delimiter on a #include directive?
(beginning-of-line)
(setq include-delim
(goto-char final-pos)
(when found-delim
- (indent-according-to-mode)))
-
- ;; On the off chance that < and > are configured as pairs in
- ;; electric-pair-mode.
- (when (and (boundp 'electric-pair-mode) electric-pair-mode
- (or template-delim include-delim))
- (let (post-self-insert-hook)
- (electric-pair-post-self-insert-function))))
-
- (when found-delim
- (when (and (eq (char-before) ?>)
- (not executing-kbd-macro)
- blink-paren-function)
- ;; From now (2016-01-01), the syntax-table text properties on < and >
- ;; are applied in an after-change function, not during redisplay. Hence
- ;; we no longer need to call (sit-for 0) for blink paren to work.
- (funcall blink-paren-function))))
- (c--call-post-self-insert-hook-more-safely)))
+ (indent-according-to-mode)))))
+
+ ;; On the off chance that < and > are configured as pairs in
+ ;; electric-pair-mode.
+ (when (and (boundp 'electric-pair-mode) electric-pair-mode
+ (or template-delim include-delim))
+ (let (post-self-insert-hook)
+ (electric-pair-post-self-insert-function)))
+
+ (when found-delim
+ (when (and (eq (char-before) ?>)
+ (not executing-kbd-macro)
+ blink-paren-function)
+ ;; From now (2016-01-01), the syntax-table text properties on < and >
+ ;; are applied in an after-change function, not during redisplay. Hence
+ ;; we no longer need to call (sit-for 0) for blink paren to work.
+ (funcall blink-paren-function))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-paren (arg)
"Insert a parenthesis.
Also, if `c-electric-flag' and `c-auto-newline' are both non-nil, some
newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
(interactive "*P")
- (c-with-string-fences
- (let ((literal (c-save-buffer-state () (c-in-literal)))
- ;; shut this up
- (c-echo-syntactic-information-p nil)
- case-fold-search)
- (let (post-self-insert-hook) ; The only way to get defined functionality
+ (let ((literal (c-save-buffer-state ()
+ (c-with-string-fences (c-in-literal))))
+ ;; shut this up
+ (c-echo-syntactic-information-p nil)
+ case-fold-search)
+ (let (post-self-insert-hook) ; The only way to get defined functionality
; from `self-insert-command'.
- (self-insert-command (prefix-numeric-value arg)))
-
- (if (and (not arg) (not literal))
- (let* (;; We want to inhibit blinking the paren since this will
- ;; be most disruptive. We'll blink it ourselves
- ;; afterwards.
- (old-blink-paren blink-paren-function)
- blink-paren-function)
+ (self-insert-command (prefix-numeric-value arg)))
+
+ (if (and (not arg) (not literal))
+ (let* (;; We want to inhibit blinking the paren since this will
+ ;; be most disruptive. We'll blink it ourselves
+ ;; afterwards.
+ (old-blink-paren blink-paren-function)
+ blink-paren-function)
+ (c-with-string-fences
(if (and c-syntactic-indentation c-electric-flag)
(indent-according-to-mode))
nil t)
(not (c-save-buffer-state () (c-in-literal))))
(delete-region (match-beginning 0) (match-end 0))
- (insert-and-inherit "} catch (")))
+ (insert-and-inherit "} catch ("))))
- ;; Apply `electric-pair-mode' stuff.
- (when (and (boundp 'electric-pair-mode)
- electric-pair-mode)
- (let (post-self-insert-hook)
- (electric-pair-post-self-insert-function)))
+ ;; Apply `electric-pair-mode' stuff.
+ (when (and (boundp 'electric-pair-mode)
+ electric-pair-mode)
+ (let (post-self-insert-hook)
+ (electric-pair-post-self-insert-function)))
+ (c-with-string-fences
;; Check for clean-ups at function calls. These two DON'T need
;; `c-electric-flag' or `c-syntactic-indentation' set.
;; Point is currently just after the inserted paren.
(skip-chars-backward " \t")
(setq beg (point))
(c-on-identifier)))))
- (delete-region beg end))))
- (and (eq last-input-event ?\))
- (not executing-kbd-macro)
- old-blink-paren
- (funcall old-blink-paren)))
-
- ;; Apply `electric-pair-mode' stuff inside a string or comment.
- (when (and (boundp 'electric-pair-mode) electric-pair-mode)
- (let (post-self-insert-hook)
- (electric-pair-post-self-insert-function))))
- (c--call-post-self-insert-hook-more-safely))))
+ (delete-region beg end)))))
+ (and (eq last-input-event ?\))
+ (not executing-kbd-macro)
+ old-blink-paren
+ (funcall old-blink-paren)))
+
+ ;; Apply `electric-pair-mode' stuff inside a string or comment.
+ (when (and (boundp 'electric-pair-mode) electric-pair-mode)
+ (let (post-self-insert-hook)
+ (electric-pair-post-self-insert-function)))))
+ (c--call-post-self-insert-hook-more-safely))
(defun c-electric-continued-statement ()
"Reindent the current line if appropriate.