Function: electric-quote-post-self-insert-function

electric-quote-post-self-insert-function is a byte-compiled function defined in electric.el.gz.

Signature

(electric-quote-post-self-insert-function)

Documentation

Function that electric-quote-mode(var)/electric-quote-mode(fun) adds to post-self-insert-hook.

This requotes when a quoting key is typed.

Source Code

;; Defined in /usr/src/emacs/lisp/electric.el.gz
(defun electric-quote-post-self-insert-function ()
  "Function that `electric-quote-mode' adds to `post-self-insert-hook'.
This requotes when a quoting key is typed."
  (when (and electric-quote-mode
             (or (eq last-command-event ?\')
                 (and (not electric-quote-context-sensitive)
                      (eq last-command-event ?\`))
                 (and electric-quote-replace-double
                      (eq last-command-event ?\")))
             (not (run-hook-with-args-until-success
                   'electric-quote-inhibit-functions))
             (if (derived-mode-p 'text-mode)
                 electric-quote-paragraph
               (and comment-start comment-use-syntax
                    (or electric-quote-comment electric-quote-string)
                    (let* ((syntax (syntax-ppss))
                           (beg (nth 8 syntax)))
                      (and beg
                           (or (and electric-quote-comment (nth 4 syntax))
                               (and electric-quote-string (nth 3 syntax)))
                           ;; Do not requote a quote that starts or ends
                           ;; a comment or string.
                           (eq beg (nth 8 (save-excursion
                                            (syntax-ppss (1- (point)))))))))))
    (pcase electric-quote-chars
      (`(,q< ,q> ,q<< ,q>>)
       (save-excursion
         (let ((backtick ?\`))
           (if (or (eq last-command-event ?\`)
                   (and (or electric-quote-context-sensitive
                            (and electric-quote-replace-double
                                 (eq last-command-event ?\")))
                        (save-excursion
                          (backward-char)
                          (skip-syntax-backward "\\")
                          (or (bobp) (bolp)
                              (memq (char-before) (list q< q<<))
                              (memq (char-syntax (char-before))
                                    '(?\s ?\())))
                        (setq backtick ?\')))
               (cond ((and electric-quote-replace-consecutive
                           (search-backward
                            (string q< backtick) (- (point) 2) t))
                      (replace-match (string q<<))
                      (when (and electric-pair-mode
                                 (eq (cdr-safe
                                      (assq q< electric-pair-text-pairs))
                                     (char-after)))
                        (delete-char 1))
                      (setq last-command-event q<<))
                     ((search-backward (string backtick) (1- (point)) t)
                      (replace-match (string q<))
                      (setq last-command-event q<))
                     ((search-backward "\"" (1- (point)) t)
                      (replace-match (string q<<))
                      (setq last-command-event q<<)))
             (cond ((and electric-quote-replace-consecutive
                         (search-backward (string q> ?') (- (point) 2) t))
                    (replace-match (string q>>))
                    (setq last-command-event q>>))
                   ((search-backward "'" (1- (point)) t)
                    (replace-match (string q>))
                    (setq last-command-event q>))
                   ((search-backward "\"" (1- (point)) t)
                    (replace-match (string q>>))
                    (setq last-command-event q>>))))))))))