emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ement 18b7ae73d3 4/4: Merge: Improvements to image view


From: ELPA Syncer
Subject: [elpa] externals/ement 18b7ae73d3 4/4: Merge: Improvements to image viewing commands
Date: Sat, 17 Jun 2023 01:05:43 -0400 (EDT)

branch: externals/ement
commit 18b7ae73d395d625579a817da8928b5ee8d99247
Merge: 50e426eb02 5d54f2a949
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Merge: Improvements to image viewing commands
    
    Thanks to Steven Allen (@Stebalien).
---
 README.org    |   7 +++-
 ement-room.el | 101 ++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 62 insertions(+), 46 deletions(-)

diff --git a/README.org b/README.org
index 7fc8d2d3e3..6554f1268c 100644
--- a/README.org
+++ b/README.org
@@ -299,7 +299,12 @@ Note that, while ~matrix-client~ remains usable, and 
probably will for some time
 
 ** 0.11-pre
 
-Nothing new yet.
+*Additions*
++ Commands ~ement-room-image-show~ and ~ement-room-image-scale~ (bound to 
~RET~ and ~M-RET~ when point is at an image) view and scale images.  (Thanks to 
[[https://github.com/Stebalien][Steven Allen]] for these and other 
image-related improvements.)
++ Command ~ement-room-image-show-mouse~ is used to show an image with the 
mouse.
+
+*Changes*
++ Command ~ement-room-image-show~ is not used for mouse events.
 
 ** 0.10
 
diff --git a/ement-room.el b/ement-room.el
index eaaf3ae17b..776e50e413 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -3962,10 +3962,10 @@ STRUCT should be an `ement-room-membership-events' 
struct."
 (defvar ement-room-image-keymap
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map image-map)
-    ;; TODO: Make RET work for showing images too.
-    ;; (define-key map (kbd "RET") #'ement-room-image-show)
+    (define-key map (kbd "M-RET") #'ement-room-image-scale)
+    (define-key map (kbd "RET") #'ement-room-image-show)
     (define-key map [mouse-1] #'ement-room-image-scale-mouse)
-    (define-key map [double-mouse-1] #'ement-room-image-show)
+    (define-key map [double-mouse-1] #'ement-room-image-show-mouse)
     map)
   "Keymap for images in room buffers.")
 
@@ -3998,51 +3998,62 @@ 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)))
+  (let* ((pos (event-start event))
+         (window (posn-window pos)))
     (with-selected-window window
-      (pcase-let* ((image (get-text-property pos 'display))
-                   (window-width (window-body-width nil t))
-                   (window-height (window-body-height nil t))
-                   ;; Image scaling commands set :max-height and friends to 
nil so use the
-                   ;; impossible dummy value -1.  See 
<https://github.com/alphapapa/ement.el/issues/39>.
-                   (new-height (if (= window-height (or (image-property image 
:max-height) -1))
-                                   (/ 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))
-        ;; Set :scale to nil since image scaling commands might have changed 
it.
-        (setf (image-property image :scale) nil
-              (image-property image :max-width) window-width
-              (image-property image :max-height) new-height)))))
-
-(defun ement-room-image-show (event)
+      (ement-room-image-scale (posn-point pos)))))
+
+(defun ement-room-image-scale (pos)
+  "Toggle scale of image at POS.
+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 "d")
+  (pcase-let* ((image (get-text-property pos 'display))
+               (window-width (window-body-width nil t))
+               (window-height (window-body-height nil t))
+               ;; Image scaling commands set :max-height and friends to nil so 
use the
+               ;; impossible dummy value -1.  See 
<https://github.com/alphapapa/ement.el/issues/39>.
+               (new-height (if (= window-height (or (image-property image 
:max-height) -1))
+                               (/ 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))
+    ;; Set :scale to nil since image scaling commands might have changed it.
+    (setf (image-property image :scale) nil
+          (image-property image :max-width) window-width
+          (image-property image :max-height) new-height)))
+
+(defun ement-room-image-show-mouse (event)
   "Show image at mouse EVENT in a new buffer."
   (interactive "e")
-  (pcase-let* ((`(,_type ,position ,_count) event)
-               (window (posn-window position)))
-    (with-current-buffer (window-buffer window)
-      (pcase-let* ((pos (event-start position))
-                   (image (copy-sequence (get-text-property pos 'display)))
-                   (ement-event (ewoc-data (ewoc-locate ement-ewoc pos)))
-                   ((cl-struct ement-event id) ement-event)
-                   (buffer-name (format "*Ement image: %s*" id))
-                   (new-buffer (get-buffer-create buffer-name)))
-        (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 :scale) 1.0
-              (image-property image :max-width) nil
-              (image-property image :max-height) nil)
-        (with-current-buffer new-buffer
-          (erase-buffer)
-          (insert-image image))
-        (pop-to-buffer new-buffer '((display-buffer-pop-up-frame)))
-        (set-frame-parameter nil 'fullscreen 'maximized)))))
+  (let* ((pos (event-start event))
+         (window (posn-window pos)))
+    (with-selected-window window
+      (ement-room-image-show (posn-point pos)))))
+
+(defun ement-room-image-show (pos)
+  "Show image at POS in a new buffer."
+  (interactive "d")
+  (pcase-let* ((image (copy-sequence (get-text-property pos 'display)))
+               (ement-event (ewoc-data (ewoc-locate ement-ewoc pos)))
+               ((cl-struct ement-event id) ement-event)
+               (buffer-name (format "*Ement image: %s*" id))
+               (new-buffer (get-buffer-create buffer-name)))
+    (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 :scale) 1.0
+          (image-property image :max-width) nil
+          (image-property image :max-height) nil)
+    (with-current-buffer new-buffer
+      (erase-buffer)
+      (insert-image image))
+    (pop-to-buffer new-buffer '((display-buffer-pop-up-frame)))
+    (set-frame-parameter nil 'fullscreen 'maximized)))
 
 (defun ement-room--format-m.image (event)
   "Return \"m.image\" EVENT formatted as a string.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]