From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#35421: Also bind left image rotation key Date: Wed, 17 Jul 2019 00:45:08 +0100 Message-ID: <87sgr5y263.fsf@tcd.ie> References: <874l6n7zsp.5.fsf@jidanni.org> <877e8ruwvy.fsf@mouse.gnus.org> <877e8rcl79.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="9649"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 35421@debbugs.gnu.org, =?UTF-8?Q?=E7=A9=8D=E4=B8=B9=E5=B0=BC?= Dan Jacobson To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 17 01:46:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hnX98-0002Nb-OO for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Jul 2019 01:46:10 +0200 Original-Received: from localhost ([::1]:52926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnX97-0003k1-1u for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Jul 2019 19:46:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36801) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnX93-0003iG-FY for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2019 19:46:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnX91-0005lI-7O for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2019 19:46:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42505) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnX90-0005l7-H3 for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2019 19:46:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hnX90-0003zP-Bh for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2019 19:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Jul 2019 23:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35421 X-GNU-PR-Package: emacs Original-Received: via spool by 35421-submit@debbugs.gnu.org id=B35421.156332072415277 (code B ref 35421); Tue, 16 Jul 2019 23:46:02 +0000 Original-Received: (at 35421) by debbugs.gnu.org; 16 Jul 2019 23:45:24 +0000 Original-Received: from localhost ([127.0.0.1]:51324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hnX8N-0003yJ-GO for submit@debbugs.gnu.org; Tue, 16 Jul 2019 19:45:23 -0400 Original-Received: from mail-wr1-f67.google.com ([209.85.221.67]:38138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hnX8L-0003y1-F7 for 35421@debbugs.gnu.org; Tue, 16 Jul 2019 19:45:22 -0400 Original-Received: by mail-wr1-f67.google.com with SMTP id g17so22732739wrr.5 for <35421@debbugs.gnu.org>; Tue, 16 Jul 2019 16:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=guyi5cfREEpW8tvU8zVccg1TTNRwwBommYtW/pXeOTk=; b=a9Vicg2ol3D4SWBwvqKbXy/43sBShH31KUP0MLWicrxL7neLFRc0oy2zEMa4ADFE4e fhPqj2lQ4goTqI4VTSRpeG3NCYCAGb/Ad8uFCzhTeMmXKvFnSQYuQf5S0g9SrOPYDa9Y mqZk28pvFrE62FlguL8r6DhIIcbl8xl7CEDDNWLZp+NUv2emHutqP+VhybAUJgZ0wNv7 cpsZg1hwd3cpeBRg+kK0cbrntVpA/1Y4+doAEKYT9Fa5zYfxJdj6IeoJg8SdnU976FtB bAusMuL0EC3J0Glsr+7bNDFV5TO4zuPNZpOKxkwB5I1GR92jUVfLiXFha9KHdB14u3u6 wZxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=guyi5cfREEpW8tvU8zVccg1TTNRwwBommYtW/pXeOTk=; b=oLmlw06WegrgamMaYAE6c/p2qjK/lmAh63smtzt/6PAPohrCCyPks2f1GiTvDiAqpo 6lNDel1G63hBFTcavV1NpKL+iQV4ZSsT0Bye+GYho7mC+GxJJVq7zmWy7vrWenYk9g0j hdhipG/Si1jF77lbG/IL1vZIJ4IG0F+hm9NREpxz21N6wki5B2/KHSVaz5JDpuZv6b2p +H/ZRm1UcxoDVfZlrXCgkEFctCND1y4yoIMWQPcZYLae08RT2Twk92XDgS1fTNKDmutn ZDb6k4/mz1zuPi4qHtLOu2JWcJc+DNTwd0d8sSA8r7fsMWnjFLBGkD4gmXVPLvJvbZ/N kT3g== X-Gm-Message-State: APjAAAWHeBEpfmVkouPGWonmXBj5D5YRFaiz+mO1md9t+ced5xVmSi6E NeYVcEYEN6yQCJAFEK8RYHhAvA== X-Google-Smtp-Source: APXvYqwd6tErJ/Kn9rVpJPZpHXApQZiy0NKt6Rzk4K/h2ANY3ukQHtcoM4EPs8FIJdEwttmpCLijYQ== X-Received: by 2002:a5d:518d:: with SMTP id k13mr38179782wrv.40.1563320715521; Tue, 16 Jul 2019 16:45:15 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id r5sm23590357wmh.35.2019.07.16.16.45.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 16:45:14 -0700 (PDT) In-Reply-To: <877e8rcl79.fsf@tcd.ie> (Basil L. Contovounesios's message of "Tue, 09 Jul 2019 15:54:34 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:163215 Archived-At: --=-=-= Content-Type: text/plain tags 35421 + patch quit "Basil L. Contovounesios" writes: > I had a patch prepared for giving image-rotate an optional prefix > argument, but then I got distracted by some imagemagick vs native > transformation issues, so I was waiting for the native support to > stabilise a bit before returning to this in earnest. Should have > something to show within a day or two. With a slight delay due to a camping trip, here it is: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Allow-counter-clockwise-rotations-in-image-rotate.patch >From 38e676d04f12a69289d4095bb9f61247c4f08ae8 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Tue, 16 Jul 2019 22:51:27 +0100 Subject: [PATCH] Allow counter-clockwise rotations in image-rotate * lisp/image.el (image-rotate): Extend with an optional argument specifying the rotation in degrees (bug#35421). * doc/lispref/display.texi (Showing Images): * etc/NEWS: Document the change. * test/lisp/image-tests.el (image-rotate): New test. --- doc/lispref/display.texi | 3 ++- etc/NEWS | 5 +++++ lisp/image.el | 22 +++++++++++++--------- test/lisp/image-tests.el | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a38569f726..4b10788862 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5992,7 +5992,8 @@ Showing Images of @samp{4} means to decrease the size by 40%. The default is 20%. @item r -Rotate the image by 90 degrees (@code{image-rotate}). +Rotate the image by 90 degrees clockwise (@code{image-rotate}). +A prefix means to rotate by 90 degrees counter-clockwise instead. @item o Save the image to a file (@code{image-save}). diff --git a/etc/NEWS b/etc/NEWS index 76ea1df821..4cc30dfcbd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2237,6 +2237,11 @@ The image parameters 'image-transform-rotation', buffer-local, so each buffer could have its own values for these parameters. ++++ +*** The command 'image-rotate' now accepts a prefix argument. +With a prefix argument, 'image-rotate' now rotates the image at point +90 degrees counter-clockwise, instead of the default clockwise. + ** Modules *** The function 'load' now behaves correctly when loading modules. diff --git a/lisp/image.el b/lisp/image.el index b58b1dc954..c3e28655c3 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -1028,16 +1028,20 @@ image--current-scaling (display-width (car (image-size image t)))) (/ (float display-width) image-width))) -(defun image-rotate () - "Rotate the image under point by 90 degrees clockwise." - (interactive) +(defun image-rotate (&optional angle) + "Rotate the image under point by ANGLE degrees clockwise. +If nil, ANGLE defaults to 90. Interactively, rotate the image 90 +degrees clockwise with no prefix argument, and counter-clockwise +with a prefix argument. Note that most image types support +rotations by only multiples of 90 degrees." + (interactive (and current-prefix-arg '(-90))) (let ((image (image--get-imagemagick-and-warn))) - (plist-put (cdr image) :rotation - (float (mod (+ (or (plist-get (cdr image) :rotation) 0) 90) - ;; We don't want to exceed 360 degrees - ;; rotation, because it's not seen as valid - ;; in exif data. - 360))))) + (setf (image-property image :rotation) + (float (mod (+ (or (image-property image :rotation) 0) + (or angle 90)) + ;; We don't want to exceed 360 degrees rotation, + ;; because it's not seen as valid in Exif data. + 360))))) (defun image-save () "Save the image under point." diff --git a/test/lisp/image-tests.el b/test/lisp/image-tests.el index 5a5b8ea1f7..01c81e3022 100644 --- a/test/lisp/image-tests.el +++ b/test/lisp/image-tests.el @@ -21,6 +21,8 @@ (require 'ert) (require 'image) +(eval-when-compile + (require 'cl-lib)) (defconst image-tests--emacs-images-directory (expand-file-name "../etc/images" (getenv "EMACS_TEST_DIRECTORY")) @@ -53,4 +55,25 @@ image-type-from-file-header-test (expand-file-name "splash.svg" image-tests--emacs-images-directory))))) +(ert-deftest image-rotate () + "Test `image-rotate'." + (cl-letf* ((image (list 'image)) + ((symbol-function 'image--get-imagemagick-and-warn) + (lambda () image))) + (let ((current-prefix-arg '(4))) + (call-interactively #'image-rotate)) + (should (equal image '(image :rotation 270.0))) + (call-interactively #'image-rotate) + (should (equal image '(image :rotation 0.0))) + (image-rotate) + (should (equal image '(image :rotation 90.0))) + (image-rotate 0) + (should (equal image '(image :rotation 90.0))) + (image-rotate 1) + (should (equal image '(image :rotation 91.0))) + (image-rotate 1234.5) + (should (equal image '(image :rotation 245.5))) + (image-rotate -154.5) + (should (equal image '(image :rotation 91.0))))) + ;;; image-tests.el ends here -- 2.20.1 --=-=-= Content-Type: text/plain I think this is a good solution for several reasons: 1. It does not require a new key binding, and it does not overly complicate the calling convention of the current key binding. 2. It turns image-rotate into a general image-rotating subroutine, which users and library authors alike can reuse. 2.1. It does not limit rotations of imagemagick images to multiples of 90 degrees. and I don't see any drawbacks, so I would like to push this to master, subject to comments/objections. Thanks, -- Basil --=-=-=--