(goto-char here)
(delete-char 1))))
+\f
+
+;; Text conversion support.
+
+(defun c-post-text-conversion ()
+ "Notice that the character `last-command-event' has been inserted.
+If said character is an electric character such as `*' or `{', delete
+it, then call the appropriate CC Mode function to electrically insert
+it again."
+ (cond ((eq last-command-event ?#)
+ (delete-char -1)
+ (c-electric-pound nil) t)
+ ((memq last-command-event '(?{ ?}))
+ (delete-char -1)
+ (c-electric-brace nil) t)
+ ((memq last-command-event '(?\( ?\)))
+ (delete-char -1)
+ (c-electric-paren nil) t)
+ ((eq last-command-event ?*)
+ (delete-char -1)
+ (c-electric-star nil) t)
+ ((eq last-command-event ?/)
+ (delete-char -1)
+ (c-electric-slash nil) t)
+ ((memq last-command-event '(?\; ?,))
+ (delete-char -1)
+ (c-electric-semi&comma nil) t)
+ ((eq last-command-event ?:)
+ (delete-char -1)
+ (c-electric-colon nil) t)
+ ((memq last-command-event '(?> ?<))
+ (delete-char -1)
+ (c-electric-lt-gt nil) t)))
+
+
\f
(cc-provide 'cc-cmds)
(when (fboundp 'electric-indent-local-mode)
(add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook)
(add-hook 'electric-indent-local-mode-hook
- 'c-electric-indent-local-mode-hook)))
+ 'c-electric-indent-local-mode-hook))
+ ;; Set up text conversion, for Emacs >= 30.0
+ (when (boundp 'post-text-conversion-hook)
+ (add-hook 'post-text-conversion-hook #'c-post-text-conversion)))
;; Will try initialization hooks again if they failed.
(put 'c-initialize-cc-mode initprop c-initialization-ok))))
;; Text conversion support. See textconv.c for more details about
;; what this is.
-
;; Actually in textconv.c.
(defvar text-conversion-edits)
(defvar electric-pair-preserve-balance)
(declare-function electric-pair-analyze-conversion "elec-pair.el")
+(defvar-local post-text-conversion-hook nil
+ "Hook run after text is inserted by an input method.
+Each function in this list is run until one returns non-nil.
+When run, `last-command-event' is bound to the last character
+that was inserted by the input method.")
+
(defun analyze-text-conversion ()
"Analyze the results of the previous text conversion event.
- Run `post-self-insert-functions' for the last character of
any inserted text so that modes such as `electric-pair-mode'
- can work."
+ can work.
+
+ - Run `post-text-conversion-hook' with `last-command-event' set
+ to the last character of any inserted text to finish up."
(interactive)
;; The list must be processed in reverse.
(dolist (edit (reverse text-conversion-edits))
(funcall auto-fill-function)))))
(goto-char (nth 2 edit))
(let ((last-command-event end))
- (run-hooks 'post-self-insert-hook)))
+ (unless (run-hook-with-args-until-success
+ 'post-text-conversion-hook)
+ (run-hooks 'post-self-insert-hook))))
;; Process this deletion before point. (nth 2 edit) is the
;; text which was deleted. Input methods typically prefer
;; to edit words instead of deleting characters off their