mirror of
https://github.com/vale981/ement.el
synced 2025-03-04 17:01:39 -05:00
Change: (ement-room-image-scale-mouse) Toggle scale
This commit is contained in:
parent
baed04d5d5
commit
ec0c324823
2 changed files with 12 additions and 6 deletions
|
@ -121,7 +121,7 @@ If you want to install it manually, it's simple enough, but you should know what
|
|||
|
||||
*Viewing images*
|
||||
|
||||
+ Resize image to window: ~mouse-1~
|
||||
+ Toggle scale of image at point (between fit-to-window and thumbnail): ~mouse-1~
|
||||
+ Show image in new buffer at full size: ~double-mouse-1~
|
||||
|
||||
*** Room list buffer
|
||||
|
|
|
@ -1719,21 +1719,27 @@ For use as a `help-echo' function on `ement-user' headings."
|
|||
(display-warning 'ement "This Emacs was not built with ImageMagick support, nor does it support Cairo/XRender scaling, so images can't be displayed in Ement")))))
|
||||
|
||||
(defun ement-room-image-scale-mouse (event)
|
||||
"Scale image at mouse EVENT to fit in window."
|
||||
"Toggle scale of image at mouse EVENT.
|
||||
Scale image to fit within the window's body. If image is already
|
||||
fit to the window, reduce its max-height to 10% of the window's
|
||||
height."
|
||||
(interactive "e")
|
||||
(pcase-let* ((`(,_type ,position ,_count) event)
|
||||
(window (posn-window position))
|
||||
(pos (event-start position)))
|
||||
(with-selected-window window
|
||||
(pcase-let* ((image (get-text-property pos 'display))
|
||||
(width (window-body-width nil t))
|
||||
(height (window-body-height nil t)))
|
||||
(window-width (window-body-width nil t))
|
||||
(window-height (window-body-height nil t))
|
||||
(new-height (if (= window-height (image-property image :max-height))
|
||||
(/ window-height 10)
|
||||
window-height)))
|
||||
(when (fboundp 'imagemagick-types)
|
||||
;; Only do this when ImageMagick is supported.
|
||||
;; FIXME: When requiring Emacs 27+, remove this (I guess?).
|
||||
(setf (image-property image :type) 'imagemagick))
|
||||
(setf (image-property image :max-width) width
|
||||
(image-property image :max-height) height)))))
|
||||
(setf (image-property image :max-width) window-width
|
||||
(image-property image :max-height) new-height)))))
|
||||
|
||||
(defun ement-room-image-show (event)
|
||||
"Show image at mouse EVENT in a new buffer."
|
||||
|
|
Loading…
Add table
Reference in a new issue