Function: LaTeX--modify-math-1

LaTeX--modify-math-1 is a byte-compiled function defined in latex.el.

Signature

(LaTeX--modify-math-1 OPEN CLOSE INLINE NEW-OPEN NEW-CLOSE NEW-INLINE POS)

Documentation

Helper function for LaTeX-modify-math.

OPEN and CLOSE are the current delimiters, NEW-OPEN and NEW-CLOSE are the new delimiters. INLINE and NEW-INLINE are booleans indicating whether the current and new delimiters are inline or display math. Assume point is at the start of the current OPEN delimiter. POS is a marker that keeps track of cursor position.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX--modify-math-1 (open close inline new-open new-close new-inline pos)
  "Helper function for `LaTeX-modify-math'.
OPEN and CLOSE are the current delimiters, NEW-OPEN and NEW-CLOSE are
the new delimiters.  INLINE and NEW-INLINE are booleans indicating
whether the current and new delimiters are inline or display math.
Assume point is at the start of the current OPEN delimiter.  POS is a
marker that keeps track of cursor position."
  (let ((converting-to-inline (and (not inline) new-inline)))
    (when converting-to-inline
      ;; Join with previous line if non-blank.
      (when (save-excursion
              (skip-chars-backward "[:blank:]")
              (and
               (bolp) (not (bobp))
               (progn
                 (forward-char -1)
                 (skip-chars-backward "[:blank:]")
                 (not (bolp)))))
        ;; The following dance gets around the slightly counterintuitive
        ;; behavior of (save-excursion (join-line)) with point at bol.
        (forward-char (length open))
        (save-excursion (join-line))
        (forward-char (- (length open)))))
    (unless new-inline
      ;; Ensure non-inline delimiters start on a blank line.
      (unless (save-excursion
                (skip-chars-backward "[:blank:]")
                (and
                 (bolp) (not (bobp))))
        (delete-horizontal-space)
        (insert "\n")))
    ;; Delete opening delimiter.
    (delete-char (length open))
    (let ((start (point)))
      (search-forward close)
      (when converting-to-inline
        ;; Join with next line if non-blank.
        (when (and (looking-at-p "[[:blank:]]*\n")
                   (save-excursion
                     (forward-line 1)
                     (not (looking-at-p "^[[:blank:]]*$"))))
          (join-line 'next)))
      (unless new-inline
        (unless (looking-at-p "[[:blank:]]*\n")
          (save-excursion
            (insert "\n"))))
      ;; Delete closing delimiter.
      (delete-char (- (length close)))
      (save-restriction
        (narrow-to-region start (point))
        ;; Clear labels.
        (goto-char (point-min))
        (LaTeX--strip-labels)
        ;; Delete leading and trailing whitespace.
        (dolist (re '("\\`[ \t\n\r]+" "[ \t\n\r]+\\'"))
          (goto-char (point-min))
          (when (re-search-forward re nil t)
            (replace-match "")))
        (unless new-inline
          (goto-char (point-min))
          (insert "\n")
          (goto-char (point-max))
          (insert "\n"))
        ;; Insert new opening delimiter.
        (goto-char (point-min))
        (insert new-open)
        ;; Insert new closing delimiter
        (goto-char (point-max))
        (when (= (point) pos)
          (set-marker-insertion-type pos (not 'advance)))
        (when converting-to-inline
          (skip-chars-backward ".,;:!?"))
        (insert new-close)
        ;; Indent, including one line past the modified region.
        (widen)
        (and sentence-end-double-space
             (looking-at-p "[.?!]")
             (save-excursion
               (forward-char)
               (when (looking-at-p " [^ ]")
                 (insert " "))))
        (end-of-line 2)
        (indent-region start (point))))))