unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
@ 2018-12-05 17:07 Carlos Pita
  2018-12-29 21:33 ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Pita @ 2018-12-05 17:07 UTC (permalink / raw)
  To: 33631

Say I set the image to fit window's width. Then turn auto-revert-mode
on. This is for example to track a plot I'm updating from an interactive
python session using matplotlib. This kind of exploratory usage is
common nowadays and it would be nice if emacs supported it out of the
box. Problem is that each time the buffer reverts the image restores its
full size.

---

In GNU Emacs 26.1.90 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.1)
 of 2018-12-05 built on archlinux
Repository revision: c7897c27861fd8b2690f40e77402edced6aa0ceb
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
Recent messages:
Sent: import matplotlib...
Reverting buffer ‘fig.png’.
ImageMagick error: improper image header `/tmp/fig.png' @ error/png.c/ReadPNGImage/4092
Reverting buffer ‘fig.png’.
Creating customization items...
Creating group...
Creating group entries...done
Creating customization items ...done
Resetting customization items...done
Creating customization setup...done

Configured using:
 'configure --prefix=/home/carlos/local/stow/emacs-26
 --libexecdir=/home/carlos/local/stow/emacs-26/lib --with-x-toolkit=gtk3
 --with-xft --with-modules'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Custom

Minor modes in effect:
  projectile-mode: t
  pdf-occur-global-minor-mode: t
  diff-auto-refine-mode: t
  pyvenv-mode: t
  shell-dirtrack-mode: t
  xclip-mode: t
  winner-mode: t
  show-paren-mode: t
  ido-ubiquitous-mode: t
  ido-everywhere: t
  global-company-mode: t
  company-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa
derived epg mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail iimage vc-git whitespace
visual-fill-column autorevert filenotify image-file image-dired
projectile pdf-occur ibuf-ext ibuffer ibuffer-loaddefs tablist
tablist-filter semantic/wisent/comp semantic/wisent
semantic/wisent/wisent semantic/util-modes semantic/util semantic
semantic/tag semantic/lex semantic/fw mode-local cedet dired
dired-loaddefs pdf-isearch let-alist pdf-misc imenu pdf-tools pdf-view
bookmark pp jka-compr pdf-cache pdf-info tq pdf-util image-mode ox-md
ox-html table ox-beamer ox-latex ox-ascii ox-publish ox org-capture
org-protocol org-element avl-tree generator org org-macro org-footnote
org-pcomplete org-list org-faces org-entities noutline outline
org-version ob-python ob-emacs-lisp ob ob-tangle org-src ob-ref ob-lob
ob-table ob-keys ob-exp ob-comint ob-core ob-eval org-compat org-macs
org-loaddefs find-func cal-menu calendar cal-loaddefs cl-extra yasnippet
elec-pair highlight-indentation flymake-proc flymake warnings help-fns
radix-tree help-mode elpy find-file-in-project ivy delsel colir color
ivy-overlay ffap thingatpt windmove diff-mode elpy-shell pyvenv esh-var
esh-io esh-cmd esh-opt esh-ext esh-proc esh-arg esh-groups eshell
esh-module esh-mode esh-util elpy-profile elpy-django elpy-refactor
subr-x python tramp-sh tramp tramp-compat tramp-loaddefs trampver
ucs-normalize shell pcomplete parse-time format-spec advice json map
grep compile comint ansi-color files-x easy-mmode doom-themes-org
company-oddmuse company-keywords company-etags etags xref project
company-gtags company-dabbrev-code company-dabbrev company-files
company-capf company-cmake company-xcode company-clang company-semantic
company-eclim company-template company-bbdb doom-tomorrow-night-theme
doom-themes doom-themes-common xclip winner ring paren
ido-completing-read+ memoize s cus-edit minibuf-eldef ido gnus nnheader
gnus-util rmail rmail-loaddefs rfc2047 rfc2045 ietf-drums mail-utils
mm-util mail-prsvr wid-edit company edmacro kmacro pcase cus-start
cus-load finder-inf info package easymenu epg-config url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache url-vars seq byte-opt gv bytecomp byte-compile cconv
cl-loaddefs cl-lib time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads dbusbind inotify lcms2 dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 758495 39921)
 (symbols 48 46843 1)
 (miscs 40 2017 444)
 (strings 32 150123 7202)
 (string-bytes 1 4402350)
 (vectors 16 73258)
 (vector-slots 8 1213942 17774)
 (floats 8 570 543)
 (intervals 56 846 72)
 (buffers 992 37))





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
  2018-12-05 17:07 bug#33631: 26.1.90; Image mode should keep scale on auto-revert Carlos Pita
@ 2018-12-29 21:33 ` Juri Linkov
  2019-01-01 23:51   ` Carlos Pita
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2018-12-29 21:33 UTC (permalink / raw)
  To: Carlos Pita; +Cc: 33631

> Say I set the image to fit window's width. Then turn auto-revert-mode
> on. This is for example to track a plot I'm updating from an interactive
> python session using matplotlib. This kind of exploratory usage is
> common nowadays and it would be nice if emacs supported it out of the
> box. Problem is that each time the buffer reverts the image restores its
> full size.

I guess this happens only when the image buffer is not selected in a window
at the time when the revering happens?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
  2018-12-29 21:33 ` Juri Linkov
@ 2019-01-01 23:51   ` Carlos Pita
  2019-01-03  0:08     ` Carlos Pita
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Pita @ 2019-01-01 23:51 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 33631

I'm refreshing the image from an org mode code block or,
alternatively, an interactive ipython buffer, so all of my previous
attempts have indeed been with an unselected image mode buffer.

Nevertheless I tried the same but updating the image from an external
process while keeping the image buffer selected and the behavior is
the same, the image is resized to the default (initial) size.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
  2019-01-01 23:51   ` Carlos Pita
@ 2019-01-03  0:08     ` Carlos Pita
  2019-01-03  0:29       ` Carlos Pita
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Pita @ 2019-01-03  0:08 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 33631

Sorry Juri, you were right, when the image buffer is selected the
reported problem doesn't happen.

Now, I realized that that is a particular case of this: if the image
is configured to fit to width, it will always fit to the current
buffer width when auto-reverting, not the image buffer width. So if
the current buffer is in a narrow window the image will be scaled
down, while if the current buffer happens to be in a wide window the
image will be scaled up.

I will try to fix that and submit a patch.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
  2019-01-03  0:08     ` Carlos Pita
@ 2019-01-03  0:29       ` Carlos Pita
  2019-06-23 20:50         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Pita @ 2019-01-03  0:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 33631

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

Here is a patch. image-transform-properties was not working on the
window of the current buffer, so I added a call to get-window-buffer.
In image-toggle-display-image (called from the auto-revert hook) this
was already being done, but the call to current-buffer was redundant
since it's the default, so I removed it. There are many other calls to
window-inside-pixel-edges around there but they don't seem to be
evaluated during auto-revert.

Regards
--
Carlos

[-- Attachment #2: 0001-Fix-auto-revert-resizing-33631.patch --]
[-- Type: text/x-patch, Size: 1886 bytes --]

From e4067b71b60c2507ce337b61e1282c1dc8e6ebcc Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Wed, 2 Jan 2019 21:25:27 -0300
Subject: [PATCH] Fix auto-revert resizing #33631

---
 lisp/image-mode.el | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index c0186f0..9bf2ef3 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -756,8 +756,7 @@ image-toggle-display-image
 	 ;; 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)
-		     (window-inside-pixel-edges
-		      (get-buffer-window (current-buffer)))))
+		     (window-inside-pixel-edges (get-buffer-window))))
 	 (type (if (fboundp 'imagemagick-types)
 		   'imagemagick
 		 (image-type file-or-data nil data-p)))
@@ -1161,6 +1160,7 @@ image-transform-properties
     ;; Note: `image-size' looks up and thus caches the untransformed
     ;; image.  There's no easy way to prevent that.
     (let* ((size (image-size spec t))
+           (edges (window-inside-pixel-edges (get-buffer-window)))
 	   (resized
 	    (cond
 	     ((numberp image-transform-resize)
@@ -1170,13 +1170,11 @@ image-transform-properties
 	     ((eq image-transform-resize 'fit-width)
 	      (image-transform-fit-width
 	       (car size) (cdr size)
-	       (- (nth 2 (window-inside-pixel-edges))
-		  (nth 0 (window-inside-pixel-edges)))))
+	       (- (nth 2 edges) (nth 0 edges))))
 	     ((eq image-transform-resize 'fit-height)
 	      (let ((res (image-transform-fit-width
 			  (cdr size) (car size)
-			  (- (nth 3 (window-inside-pixel-edges))
-			     (nth 1 (window-inside-pixel-edges))))))
+			  (- (nth 3 edges) (nth 1 edges)))))
 		(cons (cdr res) (car res)))))))
       `(,@(when (car resized)
 	    (list :width (car resized)))
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#33631: 26.1.90; Image mode should keep scale on auto-revert
  2019-01-03  0:29       ` Carlos Pita
@ 2019-06-23 20:50         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 20:50 UTC (permalink / raw)
  To: Carlos Pita; +Cc: Juri Linkov, 33631

Carlos Pita <carlosjosepita@gmail.com> writes:

> Here is a patch. image-transform-properties was not working on the
> window of the current buffer, so I added a call to get-window-buffer.

Sounds like the correct solution; I've applied your patch to the Emacs
trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-23 20:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 17:07 bug#33631: 26.1.90; Image mode should keep scale on auto-revert Carlos Pita
2018-12-29 21:33 ` Juri Linkov
2019-01-01 23:51   ` Carlos Pita
2019-01-03  0:08     ` Carlos Pita
2019-01-03  0:29       ` Carlos Pita
2019-06-23 20:50         ` Lars Ingebrigtsen

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).