Function: TeX-insert-quote

TeX-insert-quote is an interactive and byte-compiled function defined in tex.el.

Signature

(TeX-insert-quote FORCE)

Documentation

Insert the appropriate quotation marks for TeX.

Inserts the value of TeX-open-quote (normally ``) or TeX-close-quote
(normally '') depending on the context. If TeX-quote-after-quote
is non-nil, this insertion works only after ". With prefix argument FORCE, always inserts " characters.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
;; TODO: rework according to the slogan from
;; `TeX--put-electric-delete-selection'. That entails splitting off the
;; «electric» part that tries to do smart things and the plain part that
;; just inserts a quote.
(defun TeX-insert-quote (force)
  "Insert the appropriate quotation marks for TeX.
Inserts the value of `TeX-open-quote' (normally \\=`\\=`) or `TeX-close-quote'
\(normally \\='\\=') depending on the context.  If `TeX-quote-after-quote'
is non-nil, this insertion works only after \".
With prefix argument FORCE, always inserts \" characters."
  (interactive "*P")
  (if (or force
          ;; Do not insert TeX quotes in verbatim, math or comment constructs.
          (and (fboundp 'font-latex-faces-present-p)
               (font-latex-faces-present-p '(font-latex-verbatim-face
                                             font-latex-math-face
                                             font-lock-comment-face))
               (font-latex-faces-present-p '(font-latex-verbatim-face
                                             font-latex-math-face
                                             font-lock-comment-face)
                                           (1- (point))))
          (texmathp)
          (and (TeX-in-comment) (not (eq major-mode 'docTeX-mode))))
      (self-insert-command (prefix-numeric-value force))
    (when abbrev-mode
      (expand-abbrev))
    (TeX-update-style)
    (pcase-let ((`(,open-quote ,close-quote ,q-after-q)
                 (TeX-get-quote-characters)))
      (if q-after-q
          (insert (cond ((bobp)
                         ?\")
                        ((save-excursion
                           (TeX-looking-at-backward
                            (concat (regexp-quote open-quote) "\\|"
                                    (regexp-quote close-quote))
                            (max (length open-quote) (length close-quote))))
                         (delete-char (- (length (match-string 0))))
                         "\"\"")
                        ((< (save-excursion (skip-chars-backward "\"")) -1)
                         ?\")
                        ((not (= (preceding-char) ?\"))
                         ?\")
                        ((save-excursion
                           (forward-char -1)
                           (bobp))
                         (delete-char -1)
                         open-quote)
                        ((save-excursion
                           (forward-char -2) ;;; at -1 there is double quote
                           (looking-at "[ \t\n]\\|\\s("))
                         (delete-char -1)
                         open-quote)
                        (t
                         (delete-char -1)
                         close-quote)))
        (insert (cond ((bobp)
                       open-quote)
                      ((= (preceding-char) (string-to-char TeX-esc))
                       ?\")
                      ((= (preceding-char) ?\")
                       ?\")
                      ((and (<= (length open-quote) (- (point) (point-min)))
                            (save-excursion
                              (forward-char (- (length open-quote)))
                              (looking-at (regexp-quote open-quote))))
                       (delete-char (- (length open-quote)))
                       ?\")
                      ((and (<= (length open-quote) (- (point) (point-min)))
                            (save-excursion
                              (forward-char (- (length close-quote)))
                              (looking-at (regexp-quote close-quote))))
                       (delete-char (- (length close-quote)))
                       ?\")
                      ((save-excursion
                         (forward-char -1)
                         (looking-at "[ \t\n]\\|\\s("))
                       open-quote)
                      (t
                       close-quote))))
      ;; Fold quotes if TeX-fold-quotes-on-insert is t
      (when (and (bound-and-true-p TeX-fold-mode)
                 (bound-and-true-p TeX-fold-quotes-on-insert)
                 (fboundp 'TeX-fold-quotes)
                 (not (eq (char-before) ?\")))  ; Don't fold single quotes
        (save-excursion
          (let* ((end (point))
                 (start (- end
                           (length
                            (if (string= (buffer-substring-no-properties
                                          (max (point-min)
                                               (- end (length open-quote)))
                                          end)
                                         open-quote)
                                open-quote
                              close-quote)))))
            (when start
              (TeX-fold-quotes start end))))))))