From: Glenn Morris Date: Tue, 19 Jan 2016 23:13:07 +0000 (-0500) Subject: Avoid advising image-display-size for xwidgets. X-Git-Tag: emacs-25.0.90~111 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0b356a6aeb7c908e778ac20497bc90fee287af66;p=emacs.git Avoid advising image-display-size for xwidgets. * lisp/xwidget.el (xwidget-image-display-size): Remove. (image-display-size): Remove advice. * lisp/image-mode.el (xwidget-info, xwidget-at): Declare. (image-display-size): Incorporate xwidget code directly. --- diff --git a/lisp/image-mode.el b/lisp/image-mode.el index e677dd0d0e7..38a25d2b7a6 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -153,6 +153,8 @@ otherwise it defaults to t, used for times when the buffer is not displayed." (selected-window)))) (declare-function image-size "image.c" (spec &optional pixels frame)) +(declare-function xwidget-info "xwidget.c" (xwidget)) +(declare-function xwidget-at "xwidget.el" (pos)) (defun image-display-size (spec &optional pixels frame) "Wrapper around `image-size', handling slice display properties. @@ -160,24 +162,29 @@ Like `image-size', the return value is (WIDTH . HEIGHT). WIDTH and HEIGHT are in canonical character units if PIXELS is nil, and in pixel units if PIXELS is non-nil. -If SPEC is an image display property, this function is equivalent -to `image-size'. If SPEC is a list of properties containing -`image' and `slice' properties, return the display size taking -the slice property into account. If the list contains `image' -but not `slice', return the `image-size' of the specified image." - (if (eq (car spec) 'image) - (image-size spec pixels frame) - (let ((image (assoc 'image spec)) - (slice (assoc 'slice spec))) - (cond ((and image slice) - (if pixels - (cons (nth 3 slice) (nth 4 slice)) - (cons (/ (float (nth 3 slice)) (frame-char-width frame)) - (/ (float (nth 4 slice)) (frame-char-height frame))))) - (image - (image-size image pixels frame)) - (t - (error "Invalid image specification: %s" spec)))))) +If SPEC is an image display property, this function is equivalent to +`image-size'. If SPEC represents an xwidget object, defer to `xwidget-info'. +If SPEC is a list of properties containing `image' and `slice' properties, +return the display size taking the slice property into account. If the list +contains `image' but not `slice', return the `image-size' of the specified +image." + (cond ((eq (car spec) 'xwidget) + (let ((xwi (xwidget-info (xwidget-at 1)))) ; FIXME point-min? + (cons (aref xwi 2) (aref xwi 3)))) + ((eq (car spec) 'image) + (image-size spec pixels frame)) + (t (let ((image (assoc 'image spec)) + (slice (assoc 'slice spec))) + (cond ((and image slice) + (if pixels + (cons (nth 3 slice) (nth 4 slice)) + (cons (/ (float (nth 3 slice)) (frame-char-width frame)) + (/ (float (nth 4 slice)) + (frame-char-height frame))))) + (image + (image-size image pixels frame)) + (t + (error "Invalid image specification: %s" spec))))))) (defun image-forward-hscroll (&optional n) "Scroll image in current window to the left by N character widths. diff --git a/lisp/xwidget.el b/lisp/xwidget.el index ff3b977ade5..41e2c1cef6c 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -87,23 +87,6 @@ defaults to the string looking like a url around the cursor position." (xwidget-webkit-new-session url) (xwidget-webkit-goto-url url)))) - -;;shims for adapting image mode code to the webkit browser window -(defun xwidget-image-display-size (spec &optional pixels frame) - "Image code adaptor. SPEC PIXELS FRAME like the corresponding -`image-mode' fn." - (let ((xwi (xwidget-info (xwidget-at 1)))) - (cons (aref xwi 2) - (aref xwi 3)))) - -(defadvice image-display-size (around image-display-size-for-xwidget - (spec &optional pixels frame) - activate) - "Advice for re-using image mode for xwidget." - (if (eq (car spec) 'xwidget) - (setq ad-return-value (xwidget-image-display-size spec pixels frame)) - ad-do-it)) - ;;todo. ;; - check that the webkit support is compiled in (defvar xwidget-webkit-mode-map