From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: Re: image-rotate: Accept angle as an argument Date: Mon, 5 Sep 2016 16:52:48 +0900 (JST) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Trace: blaine.gmane.org 1473062050 9960 195.159.176.226 (5 Sep 2016 07:54:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Sep 2016 07:54:10 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: Emacs developers To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 05 09:54:06 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bgojC-0001bE-62 for ged-emacs-devel@m.gmane.org; Mon, 05 Sep 2016 09:54:02 +0200 Original-Received: from localhost ([::1]:52832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgojA-00065c-23 for ged-emacs-devel@m.gmane.org; Mon, 05 Sep 2016 03:54:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgoi8-00062F-Hw for emacs-devel@gnu.org; Mon, 05 Sep 2016 03:52:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgoi4-0004Pq-DC for emacs-devel@gnu.org; Mon, 05 Sep 2016 03:52:56 -0400 Original-Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgoi4-0004Ph-2B for emacs-devel@gnu.org; Mon, 05 Sep 2016 03:52:52 -0400 Original-Received: by mail-pf0-x243.google.com with SMTP id a143so6038151pfa.3 for ; Mon, 05 Sep 2016 00:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=IUJpekyfGQzi+K1DK1lIVeGKZGyBBN+Hiw+lqfFH4OE=; b=M2+xy7V5hmKpYfohhGqEhUCtKkHtQbY+npbuCaNqhJAC4wjTw2I+NZpLRuiADF1Xs3 wv68jMWeAvGvhsJIf3Q9Tm1OcQdVCltsrEOWFQf8+V58mXQutSxY3+pJO8gps/WbRIzz dgqRhBEKEcJi7wWXHspbxofIalJzj4OPILnJWO6SLRTzRi+gcrjQnpjbvYutGydDaPuu XQlTL9xjgZX1n8hM63RUhYQAfS7wvxG26XpQM7NCWkc6aZXtETbdX6iCTqOYyyq/7OHY 534ke+Q0JHr7fsvABvZTQQgyULaaoJxjpJuBxQQgWDnMLsLeALph9Qn2Tht94nTH3syO SVLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=IUJpekyfGQzi+K1DK1lIVeGKZGyBBN+Hiw+lqfFH4OE=; b=Df/YBDGVQ6aabKPwe046Nk+lMzlyRtpiaF/B/i41WVohf66/R/VaHQTX84vtnDR+Rd W1Ts6wbcX0p60lW5p3YbHWUY73nutn3lNlYG4YOdcCpBH430xX4T6q/ZHFfaekiZ8SnO EzfGuoiNjhTfIQVRxpZK6WeXCWmXObuWNgWBvt+Z+wJcsPW2tHjIytiNXQdccqY3BOnq Urx29xqf9IOGB+0zb7avGirYpLi8EbA7kh7pZt3zrpO48tcCup6DapFWdd9rYuxlLp/q 6T0BHFVXOG6e/f3eglfiMJ9Zu5WYb/y9OWKqQQs9SLr9Qe3E9yEOG2VT/GW7liYKmLCw F1tg== X-Gm-Message-State: AE9vXwOEzZyN9gYzLhN8nDZi3Pqx9S5Fcl1Z/VbXwkWnICJIpxKAHuSbVVaBVubx4J0STA== X-Received: by 10.98.86.154 with SMTP id h26mr61476642pfj.22.1473061971148; Mon, 05 Sep 2016 00:52:51 -0700 (PDT) Original-Received: from calancha-pc (69.191.218.133.dy.bbexcite.jp. [133.218.191.69]) by smtp.gmail.com with ESMTPSA id i73sm12716150pfi.35.2016.09.05.00.52.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Sep 2016 00:52:50 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207192 Archived-At: On Mon, 5 Sep 2016, Tino Calancha wrote: > > Hello, > lisp/image.el defines 'image-increase-size' and 'image-decrease-size', > with an argument N. We might allow for an argument in 'image-rotate' > as well. I would like also to modify 'image-increase-size' and 'image-decrease-size' as i did with 'image-rotate': A prefix argument prompt user for the size factor. Then you can perform arbitrary rotations and resize of an image using these commands as follows: ;; FILE is the file name of an image file: emacs -Q FILE: 1 r 15 RET ; rotate image 15 degrees 1 r -15 RET ; rotate image -15 degrees 1 + 50 RET ; increase image size 50% 1 - 40 RET ; decrease image size 40% So the proposal is 2 patches: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From aefda287d0d739c99f6e45f568a22b67f1eb19da Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Mon, 5 Sep 2016 16:26:03 +0900 Subject: [PATCH 1/2] image-rotate: Accept angle as an argument * lisp/image.el (image-rotate): Add argument ANGLE, the angle in degrees for the rotation. Add optional argument _ARG; in interactive calls, a non-nil value prompt for ANGLE. --- lisp/image.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/image.el b/lisp/image.el index e1f52de..cad8332 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -1008,12 +1008,21 @@ 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 (angle &optional _arg) + "Rotate the image under point by ANGLE degrees clockwise. +If ANGLE is a negative number, then rotate counterclockwise. +When called interactively with a prefix argument, prompt for ANGLE." + (interactive + (let* ((ask current-prefix-arg) + (default 90) + (prompt "Rotate image by ANGLE degrees: ") + (rotation (if ask + (read-number prompt default) + default))) + (list rotation ask))) (let ((image (image--get-imagemagick-and-warn))) (plist-put (cdr image) :rotation - (float (mod (+ (or (plist-get (cdr image) :rotation) 0) 90) + (float (mod (+ (or (plist-get (cdr image) :rotation) 0) angle) ;; We don't want to exceed 360 degrees ;; rotation, because it's not seen as valid ;; in exif data. -- 2.9.3 >From 7428267a2723315e9a8df3f7a687aeb66513dde4 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Mon, 5 Sep 2016 16:29:56 +0900 Subject: [PATCH 2/2] image-increase-size: Prompt for size factor in interactive calls * lisp/image.el (image-increase-size, image-decrease-size): Add optional argument _ARG; in interactive calls, a non-nil value prompt for the size factor. --- lisp/image.el | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/lisp/image.el b/lisp/image.el index cad8332..1bfa042 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -951,23 +951,36 @@ imagemagick-enabled-types (imagemagick-register-types) -(defun image-increase-size (n) - "Increase the image size by a factor of N. +(defun image-increase-size (n &optional _arg) + "Increase the image size. If N is 3, then the image size will be increased by 30%. The -default is 20%." - (interactive "P") - (image--change-size (if n - (1+ (/ n 10.0)) - 1.2))) - -(defun image-decrease-size (n) - "Decrease the image size by a factor of N. +default is 20%. +When called interactively with a prefix argument, prompt for N." + (interactive + (let* ((ask current-prefix-arg) + (default 20) + (num (if ask + (read-number "Increase image size by X %: " default) + default))) + (list (/ num 10.0) ask))) + (image--change-size (1+ (/ n 10.0)))) + +(defun image-decrease-size (n &optional _arg) + "Decrease the image size. If N is 3, then the image size will be decreased by 30%. The -default is 20%." - (interactive "P") - (image--change-size (if n - (- 1 (/ n 10.0)) - 0.8))) +default is 20%. +When called interactively with a prefix argument, prompt for N." + (interactive + (let* ((ask current-prefix-arg) + (default 20) + (num (if ask + (read-number "Decrease image size by X %: " default) + default))) + (list (/ num 10.0) ask))) + (let ((decrease (/ n 10.0))) + (image--change-size (if (< decrease 1) + (- 1 decrease) + 0)))) (defun image--get-image () (let ((image (get-text-property (point) 'display))) -- 2.9.3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.9) of 2016-09-05 Repository revision: 62e4dc4660cb3b29cfffcad0639e51c7f382ced8