From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#32672: 27.0.50; image resize on window resizing Date: Fri, 21 Sep 2018 02:15:45 +0300 Organization: LINKOV.NET Message-ID: <87fty3sp6a.fsf@mail.linkov.net> References: <87pnxmyjgt.fsf@mail.linkov.net> <87ftyfoakb.fsf@mail.linkov.net> <5B98B33D.7000605@gmx.at> <871s9ycnjl.fsf@mail.linkov.net> <5B9A15DA.5000403@gmx.at> <87efdxnfww.fsf@mail.linkov.net> <5B9B7253.5060808@gmx.at> <87pnxexr2m.fsf@mail.linkov.net> <5B9E1E0E.7070805@gmx.at> <87h8ip2eby.fsf@mail.linkov.net> <5B9F4DBD.5020009@gmx.at> <877ejjzr9s.fsf@mail.linkov.net> <5BA20763.8070305@gmx.at> <875zz1t6y1.fsf@mail.linkov.net> <5BA34D7E.4030509@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1537487713 7917 195.159.176.226 (20 Sep 2018 23:55:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Sep 2018 23:55:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 32672@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 21 01:55:09 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1g38mq-0001v7-CZ for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Sep 2018 01:55:08 +0200 Original-Received: from localhost ([::1]:53178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g38ow-0004ri-9I for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Sep 2018 19:57:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g38oj-0004qa-BN for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2018 19:57:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g38oh-0002nS-1J for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2018 19:57:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43214) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g38og-0002nN-Tj for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2018 19:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g38og-0000iK-SZ for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2018 19:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Sep 2018 23:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32672 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32672-submit@debbugs.gnu.org id=B32672.15374877652623 (code B ref 32672); Thu, 20 Sep 2018 23:57:02 +0000 Original-Received: (at 32672) by debbugs.gnu.org; 20 Sep 2018 23:56:05 +0000 Original-Received: from localhost ([127.0.0.1]:47466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g38nk-0000gC-UQ for submit@debbugs.gnu.org; Thu, 20 Sep 2018 19:56:05 -0400 Original-Received: from pop.dreamhost.com ([64.90.62.162]:60866 helo=pdx1-sub0-mail-a36.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g38nj-0000g4-Kp for 32672@debbugs.gnu.org; Thu, 20 Sep 2018 19:56:03 -0400 Original-Received: from pdx1-sub0-mail-a36.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTP id C89C67EDA7; Thu, 20 Sep 2018 16:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=HvrcDLJVAxpZk32Nm/4mKPpCqNc=; b= mGDE37D5FMSsiQIoNGKN52kFaAlT7Z+OFQdPVn2KS8/ZBy2vYbP/coKqfAx5sXpU 8kfYp5LswKPFIg/FmeAo98zRUPEWLVhi+n+gHcB2Gjkc/sGVCD1FoQnlhg2JV+BG iBDwwshi7hhGG2LVVbExMAwrbDI+8GdmZYUc2XEBpds= Original-Received: from localhost.linkov.net (m91-129-107-237.cust.tele2.ee [91.129.107.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTPSA id D366B7EDB7; Thu, 20 Sep 2018 16:56:01 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a36 X-DH-BACKEND: pdx1-sub0-mail-a36 In-Reply-To: <5BA34D7E.4030509@gmx.at> (martin rudalics's message of "Thu, 20 Sep 2018 09:34:22 +0200") 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: 208.118.235.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:150500 Archived-At: >> But the problem is that the buffer-local hook will have such idiomatic code: >> >> (with-current-buffer (window-buffer window) >> ... > > Where does 'window' come from? At the time 'buffer-list-update-hook' > gets called, there's no guarantee that the buffer whose local hook > runs is even shown in a window. Thank you, now it's possible to finish this feature, it gets 'window' using get-buffer-window-list: diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 19fa28d440..3355ee6109 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -574,6 +574,9 @@ image-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-size-change-functions (debounce 'image-size-window-change 1) nil t) + (add-hook 'buffer-list-update-hook 'image-size-buffer-change nil t) + (run-mode-hooks 'image-mode-hook) (let ((image (image-get-display-property)) (msg1 (substitute-command-keys @@ -822,6 +826,42 @@ image-after-revert-hook (get-buffer-window-list (current-buffer) 'nomini 'visible)) (image-toggle-display-image))) +(defun image-size-window-change (&optional frame) + (let (buffers) + (walk-windows (lambda (window) + (with-current-buffer (window-buffer window) + (when (derived-mode-p 'image-mode) + (push (current-buffer) buffers)))) + 'nomini (or frame 'visible)) + (mapc (lambda (buffer) (image-size-buffer-change buffer)) + (delq nil (delete-dups buffers))))) + +(defun image-size-buffer-change (&optional buffer) + (with-current-buffer (or buffer (current-buffer)) + (when (derived-mode-p 'image-mode) + (let* ((spec (image-get-display-property)) + (spec (and (eq (car-safe spec) 'image) spec)) + (max-width (plist-get (cdr spec) :max-width)) + (max-height (plist-get (cdr spec) :max-height)) + (windows (and (or max-width max-height) + (get-buffer-window-list + (current-buffer) 'nomini 'visible))) + min-width min-height min-window) + (mapc (lambda (window) + (let* ((edges (window-inside-pixel-edges window)) + (width (- (nth 2 edges) (nth 0 edges))) + (height (- (nth 3 edges) (nth 1 edges)))) + (setq min-width (if min-width (min min-width width) width)) + (setq min-height (if min-height (min min-height height) height)) + (when (and (= min-width width) + (= min-height height)) + (setq min-window window)))) + windows) + (when (or (and min-width max-width (not (= min-width max-width))) + (and min-height max-height (not (= min-height max-height)))) + (with-selected-window min-window + (image-toggle-display-image))))))) + ;;; Animated images