mm-display-external

This commit is contained in:
dickmao 2020-01-13 15:40:58 -05:00
parent a786b76fc0
commit 43e53f0eae
2 changed files with 90 additions and 72 deletions

View file

@ -45,7 +45,8 @@
(declare-function mm-encode-buffer "mm-encode")
(declare-function mm-possibly-verify-or-decrypt "mm-decode")
(declare-function mm-dissect-singlepart "mm-decode")
(declare-function mm-interactively-view-part "mm-decode")
(declare-function mm-display-external "mm-decode")
(declare-function mm-handle-media-type "mm-decode")
(defun ein:cell--ewoc-delete (ewoc &rest nodes)
"Delete NODES from EWOC."
@ -844,7 +845,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
" "))
'font-lock-face 'ein:cell-output-prompt)
(ein:insert-read-only "\n")
(ein:cell-append-mime-type json)
(ein:cell-append-mime-type json (not (ein:oref-safe cell 'kernel)))
(ein:insert-read-only "\n"))
(cl-defmethod ein:cell-append-pyerr ((cell ein:codecell) json)
@ -891,7 +892,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
(cl-defmethod ein:cell-append-display-data ((cell ein:codecell) json)
"Insert display-data type output in the buffer.
Called from ewoc pretty printer via `ein:cell-insert-output'."
(ein:cell-append-mime-type json)
(ein:cell-append-mime-type json (not (ein:oref-safe cell 'kernel)))
(ein:insert-read-only "\n"))
(make-obsolete-variable 'ein:output-type-preference nil "0.17.0")
@ -903,7 +904,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
(minor (car (nreverse (split-string minor-kw ":")))))
(cl-subseq minor 0 (cl-search "+" minor))))
(defun ein:cell-append-mime-type (json)
(defun ein:cell-append-mime-type (json starting-p)
(ein:output-area-case-type
json
(cl-case type
@ -917,7 +918,17 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
t)))
(if ein:output-area-inlined-images
(ein:insert-image image)
(mm-interactively-view-part (ein:make-mm-handle image)))))
(unless starting-p ;; don't display on ein:worksheet-render
(let* ((handle (ein:make-mm-handle image))
(type (mm-handle-media-type handle))
(method (seq-some (lambda (i) (cdr (assoc 'viewer i)))
(mailcap-mime-info type 'all))))
(when (and (stringp method) (string-match "^[^% \t]+$" method))
(setq method (concat method " %s")))
(if (and (stringp method) (> (length method) 0))
(mm-display-external handle method)
(ein:log 'warn "ein:cell-append-mime-type: %s"
"no viewer method found in mailcap")))))))
(otherwise
(ein:insert-read-only value)))))

View file

@ -166,6 +166,7 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
result))
(defun ein:worksheet--jigger-undo-list (&optional change-cell-id)
(cl-assert (listp buffer-undo-list))
(if (/= (length buffer-undo-list) (length ein:%which-cell%))
(ein:log 'debug "jig %s to %s: %S %S" (length ein:%which-cell%) (length buffer-undo-list) buffer-undo-list ein:%which-cell%))
(ein:and-let* ((old-cell-id (car change-cell-id))
@ -202,6 +203,7 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
(setq old-cell cell))
(when buffer-local-enable-undo
(ein:with-live-buffer (ein:cell-buffer cell)
(if (listp buffer-undo-list)
(let* ((opl (ein:worksheet--prompt-length old-cell t))
(ool (ein:worksheet--output-length old-cell t))
(otl (ein:worksheet--total-length old-cell t))
@ -238,7 +240,9 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
"ein:worksheet--unshift-undo-list %d != %d"
(length buffer-undo-list) (length lst))
(setq buffer-undo-list lst)
(ein:worksheet--update-cell-lengths cell exogenous-input)))))
(ein:worksheet--update-cell-lengths cell exogenous-input))
(ein:log 'debug "ein:worksheet--unshift-undo-list: buffer-undo-list %s in %s"
buffer-undo-list (ein:cell-buffer cell))))))
(defun ein:worksheet--calc-offset (u)
"Return length of inserted (or uninserted) text corresponding to undo entry U."
@ -252,6 +256,7 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
"Adjust `buffer-undo-list' for deleting CELL. Shift in list parlance means removing the front."
(when buffer-local-enable-undo
(ein:with-live-buffer (ein:cell-buffer cell)
(if (listp buffer-undo-list)
(let* ((pdist (ein:worksheet--prompt-length cell))
(odist (ein:worksheet--output-length cell))
(sdist (ein:worksheet--saved-input-length cell))
@ -280,7 +285,9 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
(setq buffer-undo-list (nreverse lst))
(setq ein:%which-cell% (nreverse wc))
(ein:worksheet--jigger-undo-list)
(cl-remprop 'ein:%cell-lengths% (slot-value cell 'cell-id))))))
(cl-remprop 'ein:%cell-lengths% (slot-value cell 'cell-id)))
(ein:log 'debug "ein:worksheet--shift-undo-list: buffer-undo-list %s in %s"
buffer-undo-list (ein:cell-buffer cell))))))
;;; Class and variable
@ -309,7 +316,7 @@ Normalize `buffer-undo-list' by removing extraneous details, and update the ein:
"Binds event handlers which are not needed to be bound per instance."
(ein:events-on events
'maybe_reset_undo.Worksheet
(lambda (-ignore- cell)
(lambda (_ignore cell)
(ein:worksheet--unshift-undo-list cell)))
(ein:events-on events 'set_next_input.Worksheet
#'ein:worksheet--set-next-input)