Function: preview-toggle

preview-toggle is a byte-compiled function defined in preview.el.

Signature

(preview-toggle OV &optional ARG EVENT)

Documentation

Toggle visibility of preview overlay OV.

ARG can be one of the following: t displays the overlay, nil displays the underlying text, and toggle toggles. ARG can also be maybe-open to display the underlying text only when the cursor of the overlay's buffer is inside the overlay (in this case, OV is added to preview-temporary-opened). If EVENT is given, it indicates the window where the event occurred, either by being a mouse event or by directly being the window in question. This may be used for cursor restoration purposes.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.2.0/preview.el
(defun preview-toggle (ov &optional arg event)
  "Toggle visibility of preview overlay OV.
ARG can be one of the following: t displays the overlay, nil displays
the underlying text, and `toggle' toggles.  ARG can also be `maybe-open'
to display the underlying text only when the cursor of the overlay's
buffer is inside the overlay (in this case, OV is added to
`preview-temporary-opened').  If EVENT is given, it indicates the window
where the event occurred, either by being a mouse event or by directly
being the window in question.  This may be used for cursor restoration
purposes."
  (let ((old-urgent (preview-remove-urgentization ov)))
    (unwind-protect
        (let ((preview-state
               (if (cond
                    ((eq arg 'toggle)
                     (null (eq (overlay-get ov 'preview-state) 'active)))
                    ((eq arg 'maybe-open)
                     (with-current-buffer (overlay-buffer ov)
                       ;; If (point) is on the overlay.
                       (or (not (memq ov (overlays-at (point))))
                           (progn (push ov preview-temporary-opened)
                                  nil))))
                    (t arg))
                   'active
                 'inactive))
              (prop (if (consp preview-at-point-placement)
                        (car preview-at-point-placement)
                      preview-at-point-placement))
              (strings (overlay-get ov 'strings)))
          (unless (eq (overlay-get ov 'preview-state) 'disabled)
            (overlay-put ov 'preview-state preview-state)
            (overlay-put ov 'category 'preview-overlay)
            (if (eq preview-state 'active)
                (progn
                  (if (eq (overlay-start ov) (overlay-end ov))
                      (overlay-put ov prop (car strings))
                    (unless (eq preview-visibility-style 'at-point)
                      (dolist (prop '(display keymap mouse-face help-echo))
                        (overlay-put ov prop
                                     (get-text-property 0 prop
                                                        (car strings)))))
                    (overlay-put ov prop nil))
                  (overlay-put ov 'face nil))
              (dolist (prop '(display keymap mouse-face help-echo))
                (overlay-put ov prop nil))
              (unless (eq preview-visibility-style 'at-point)
                (overlay-put ov 'face 'preview-face))
              (unless (cdr strings)
                (setcdr strings
                        (preview--string
                         ov
                         (and (eq preview-visibility-style 'off-point)
                              preview-icon)
                         "%s redisplays preview\n%s more options")))
              (overlay-put ov prop (cdr strings)))
            (preview-overlay-updated ov)))
      (when old-urgent
        (apply #'preview-add-urgentization old-urgent))))
  (if event
      (preview-restore-position
       ov
       (if (windowp event)
           event
         (posn-window (event-start event))))))