From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Auto-resizing of images in image-mode Date: Mon, 20 Apr 2020 02:58:31 +0300 Organization: LINKOV.NET Message-ID: <87h7xfvwy0.fsf@mail.linkov.net> References: <83r1wqgcl1.fsf@gnu.org> <87eesnayhf.fsf@mail.linkov.net> <83sgh2d2zo.fsf@gnu.org> <874ktg5pgt.fsf@mail.linkov.net> <83r1wjin8y.fsf@gnu.org> <87y2qrvzag.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="38350"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Apr 20 02:13:20 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQK3q-0009qJ-WE for ged-emacs-devel@m.gmane-mx.org; Mon, 20 Apr 2020 02:13:19 +0200 Original-Received: from localhost ([::1]:55442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQK3q-0007Pm-1F for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Apr 2020 20:13:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47922 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQK32-0006pa-RQ for emacs-devel@gnu.org; Sun, 19 Apr 2020 20:12:29 -0400 Original-Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQK32-0000u1-75 for emacs-devel@gnu.org; Sun, 19 Apr 2020 20:12:28 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:56547) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jQK2z-0000s7-VI; Sun, 19 Apr 2020 20:12:26 -0400 X-Originating-IP: 91.129.99.85 Original-Received: from mail.gandi.net (m91-129-99-85.cust.tele2.ee [91.129.99.85]) (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 040B4E0003; Mon, 20 Apr 2020 00:12:19 +0000 (UTC) In-Reply-To: <87y2qrvzag.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 20 Apr 2020 02:19:51 +0300") Received-SPF: pass client-ip=217.70.183.196; envelope-from=juri@linkov.net; helo=relay4-d.mail.gandi.net X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer [fuzzy] X-Received-From: 217.70.183.196 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:247344 Archived-At: --=-=-= Content-Type: text/plain >>> If this looks good, I could send a complete patch. >> >> Please do, and thanks. > > It seems image-window-resize and image-window-resize-delay could be > combined into one defcustom that will be either nil or number, will post > the patch ASAP. Here is a complete patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=image-auto-resize.patch diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 22d7d91314..2d07c59494 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -53,11 +53,38 @@ image-mode-new-window-functions "Special hook run when image data is requested in a new window. It is called with one argument, the initial WINPROPS.") +(defcustom image-auto-resize t + "Non-nil to resize the image upon first display. +Its value should be one of the following: + - nil, meaning no resizing. + - t, meaning to fit the image to the window height and width. + - `fit-height', meaning to fit the image to the window height. + - `fit-width', meaning to fit the image to the window width. + - A number, which is a scale factor (the default size is 1)." + :type '(choice (const :tag "No resizing" nil) + (other :tag "Fit height and width" t) + (const :tag "Fit height" fit-height) + (const :tag "Fit width" fit-width) + (number :tag "Scale factor" 1)) + :version "27.1" + :group 'image) + +(defcustom image-keep-auto-resize 1 + "Non-nil to resize the image whenever the window's dimensions change. +This will always keep the image fit into the window. +When non-nil, the value should be a number of seconds to wait before +resizing according to the value specified in `image-auto-resize'." + :type '(choice (const :tag "No auto-resize on window size change" nil) + (integer :tag "Wait for number of seconds before resize" 1)) + :version "27.1" + :group 'image) + ;; FIXME this doesn't seem mature yet. Document in manual when it is. (defvar-local image-transform-resize nil "The image resize operation. Its value should be one of the following: - nil, meaning no resizing. + - t, meaning to fit the image to the window height and width. - `fit-height', meaning to fit the image to the window height. - `fit-width', meaning to fit the image to the window width. - A number, which is a scale factor (the default size is 1).") @@ -418,6 +445,7 @@ image-multi-frame ;; Transformation keys (define-key map "sf" 'image-mode-fit-frame) + (define-key map "sb" 'image-transform-fit-both) (define-key map "sh" 'image-transform-fit-to-height) (define-key map "sw" 'image-transform-fit-to-width) (define-key map "sr" 'image-transform-set-rotation) @@ -459,2 +504,2 @@ image-mode-map :help "Resize image to match the window height"] ["Fit to Window Width" image-transform-fit-to-width :help "Resize image to match the window width"] + ["Fit to Window Height and Width" image-transform-fit-both + :help "Resize image to match the window height and width"] ["Rotate Image..." image-transform-set-rotation :help "Rotate the image"] @@ -557,6 +599,7 @@ image-mode (major-mode-suspend) (setq major-mode 'image-mode) + (setq image-transform-resize image-auto-resize) (if (not (image-get-display-property)) (progn @@ -599,7 +642,8 @@ image-mode--setup-mode (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) (add-hook 'after-revert-hook #'image-after-revert-hook nil t) - (add-hook 'window-state-change-functions #'image--window-state-change nil t) + (when image-keep-auto-resize + (add-hook 'window-state-change-functions #'image--window-state-change nil t)) (run-mode-hooks 'image-mode-hook) (let ((image (image-get-display-property)) @@ -756,7 +800,7 @@ image-toggle-display-image filename)) ;; If we have a `fit-width' or a `fit-height', don't limit ;; the size of the image to the window size. - (edges (and (null image-transform-resize) + (edges (and (eq image-transform-resize t) (window-inside-pixel-edges (get-buffer-window)))) (type (if (image--imagemagick-wanted-p filename) 'imagemagick @@ -865,7 +910,9 @@ image--window-state-change ;; image resizing happens later during redisplay. So if those ;; consecutive calls happen without any redisplay between them, ;; the costly operation of image resizing should happen only once. - (run-with-idle-timer 1 nil #'image-fit-to-window window)) + (when (numberp image-keep-auto-resize) + (run-with-idle-timer image-keep-auto-resize nil + #'image-fit-to-window window))) (defun image-fit-to-window (window) "Adjust size of image to display it exactly in WINDOW boundaries." @@ -1268,7 +1314,7 @@ image-transform-properties `image-transform-resize' and `image-transform-rotation'. The return value is suitable for appending to an image spec." (setq image-transform-scale 1.0) - (when (or image-transform-resize + (when (or (not (memq image-transform-resize '(nil t))) (/= image-transform-rotation 0.0)) ;; Note: `image-size' looks up and thus caches the untransformed ;; image. There's no easy way to prevent that. @@ -1302,5 +1345,11 @@ image-transform-properties (setq image-transform-resize 'fit-width) (image-toggle-display-image)) +(defun image-transform-fit-both () + "Fit the current image both to the height and width of the current window." + (interactive) + (setq image-transform-resize t) + (image-toggle-display-image)) + (defun image-transform-set-rotation (rotation) "Prompt for an angle ROTATION, and rotate the image by that amount. ROTATION should be in degrees." --=-=-=--