From: Tino Calancha <tino.calancha@gmail.com>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: image-rotate: Accept angle as an argument
Date: Mon, 5 Sep 2016 16:52:48 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1609051650300.22704@calancha-pc> (raw)
In-Reply-To: <alpine.DEB.2.20.1609051451100.32022@calancha-pc>
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 <tino.calancha@gmail.com>
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 <tino.calancha@gmail.com>
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
next prev parent reply other threads:[~2016-09-05 7:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-05 5:52 image-rotate: Accept angle as an argument Tino Calancha
2016-09-05 7:52 ` Tino Calancha [this message]
2016-09-05 12:36 ` Lars Ingebrigtsen
2016-09-05 14:59 ` Stefan Monnier
2016-09-05 16:30 ` Tino Calancha
2016-09-05 16:52 ` Lars Ingebrigtsen
2016-09-05 17:28 ` Tino Calancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1609051650300.22704@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).