all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#22105: 25.1.50; REGRESSION - `modify-frame-parameters'
@ 2015-12-07  6:03 Drew Adams
  2015-12-07 10:35 ` martin rudalics
  2019-08-08  4:07 ` Stefan Kangas
  0 siblings, 2 replies; 15+ messages in thread
From: Drew Adams @ 2015-12-07  6:03 UTC (permalink / raw)
  To: 22105

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

I really hope that you can fix this problem.  It is important to the way
I use Emacs.  I'm reporting this from a dev snapshot (master), but the
same recipe exhibits the same problem with (pre)release 25 builds.

Starting with a build of 2014-10-20, my code that thumbifies frames
(shrinks them to thumbnail size, and restores them) has been broken.
There is no problem with release 24.5 (which came out after 2014-10-20,
IIRC, but from a different dev branch) or with earlier releases or
builds.

All builds since then have problems for frame thumbifying, but there has
seemingly been a lot of changes to the frame code, so the broken
behavior has changed in different ways over the past year or so.  For
this reason of instability (dev changes), and because debugging these
problem(s) seems to take me a long time, I've not filed a bug report
about this until now.

I have a recipe to reproduce a problem, but I don't know whether it is
the only problem.  In general, thumbifying not only does not resize
frames properly, it even changes - if I thumbify & dethumbify the same
frame repeatedly - the thumb size can change a lot.

But such wild changes are not what you will see with this test recipe.
The recipe here reports a single problem that is easy to see.

[This is not the same as bug #14032, which was fixed, though I see now
(after long hours of debugging) that the description seems a bit
similar.  In particular, suppressing the use of scroll bars does not
help.]


To reproduce the problem, use the attached file, test-thumb.el.  Start
with: runemacs.exe -Q --debug-init -l "/PATH/TO/test-thumb.el"

You will use `C-z' to thumbify and dethumbify the *scratch* frame (it's
a toggle).  There is a call to `debug' in `thumfr-thumbify-frame', which
thumbifies.  To see the problem quickly you can comment that out.

The intended behavior (and the behavior in Emacs release 24.5 and prior)
is that once a frame has been thumbified, thumbifying it again, after
dethumbifying, should show it in the same way - its frame parameters
should be restored to those it had when first thumbified.  And this,
regardless of whether the dethumbified frame has changed parameter
values.  IOW, the shape etc. of a thumbnail frame should be determined
once and for all the first time the frame is thumbified.

The behavior instead is that thumbifying results in mirroring the latest
unthumbified frame parameters (with only the `font' parameter changed).
At least that's what I see with the recipe, which shows this problem for
parameter `height'.

Essentially the recipe is this:

1. Thumbify, then dethumbify, to see the expected behavior (can be
   repeated).

2. Then when unthumbified, manually resize the frame, to reduce its
   height noticeably.  Then thumbify.  The thumbnail frame should be the
   same size (e.g., same height) as before, but instead it mirrors the
   aspet ratio of the frame before thumbifying (reduced height).

Below is the detailed recipe.  Note that if you comment-out the call to
`(debug)', or if you just use `c' when the debugger opens, then you can
see the problem - the call to `modify-frame-parameters' after `(debug)'
seems to do nothing.

If instead you use `d' to step through the debugger, so that the first
sexp (the call to `modify-frame-parameters) is stepped through, then
there is no problem - the frame gets the proper size because of that
call.  It is as if the call to `modify-frame-parameters' is ignored
(or optimized away?), unless the debugger steps through it.


RECIPE 1:

1. runemacs.exe -Q --debug-init -l "/PATH/TO/test-thumb.el"

2. Optional, to see frame parameters using `C-o' (command `foo', at end
   of file): `C-x 5 b *Messages*'.

3. With buffer *scratch* selected (focused): `C-z', to thumbify.
   Then `c' to skip through the debugger.

4. `C-z', to dethumbify.

5. Repeat #3 and #4 as many times as you like.  No problem, so far.

6. With the frame normal size (dethumbified), manually (e.g., with
   the mouse) resize it to reduce the height noticeably.

7. `C-z', to thumbify.  Use `c' to skip through the debugger.

You will see that the thumbified height (e.g. aspect ratio) reflects
what the unthumbified height had.  This is the bug.  The thumbnail
should be the same as before - its height should not change.

The call to `enlarge-font' just before that `modify-frame-parameters'
shrinks the frame proportionately, so after manually reducing the
height, the result is a similarly reduced-height thumbnail.  But the
`modify-frame-parameters' that follows `enlarge-font' should correct
this by restoring the set of frame parameters that were recorded from
the first thumbifying.  (They are recorded in frame parameter
`thumfr-non-thumbnail-frame'.)


RECIPE 2: Same as RECIPE 1, but this time, at step 7, step through the
debugger.  You will see that there is no bug - the thumbified frame has
the right height.  The code is correct, I think.  But that call to
`modify-frame-parameters' does not seem to do what it should, unless you
step through it with the debugger.

The behavior without using the debugger at all (e.g., with `(debug)'
commented out) shows the bug too.  The call to `modify-parameters' seems
to be optimized away or otherwise neglects to apply the parameter
changes.  The height parameter (as an example) is left as it was after
the call to `enlarge-font'.

Here is perhaps a clue to the problem: Variable `thumfr-frame-parameters'
has value ((menu-bar-lines . 0)).  If you comment-out that line, to
give it a value of (()), then there is no bug.  You can also uncomment
the commented-out lines, to give it a value of, say,
((tool-bar-lines . 0) (scroll-bar-width . 6) (scroll-bar-height . 6)),
and then there is no bug either.  It seems that it is the presence of
the `menu-bar-lines' sexp that is problematic.

I think this bug was introduced on or before 2014-10-20.  At least
that's when I started seeing similar problems.  Thanks for taking
a look.


In GNU Emacs 25.1.50.1 (i686-pc-mingw32)
 of 2015-12-04
Bzr revision: ffefb6e899fbcdcbd79cb34292d57b7bc3043fcc
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/snapshot/trunk --enable-checking=yes
 --enable-check-lisp-object-type --without-compress-install 'CFLAGS=-Og
 -ggdb3' LDFLAGS=-Lc:/Devel/emacs/lib 'CPPFLAGS=-DGC_MCHECK=1
 -Ic:/Devel/emacs/include''

[-- Attachment #2: test-thumb.el --]
[-- Type: application/octet-stream, Size: 7638 bytes --]

;; RECIPE 1:

;; 1. runemacs.exe -Q --debug-init -l "/PATH/TO/test-thumb.el"

;; 2. Optional, to check frame parameters, using `foo' (at end of file):
;;    C-x 5 b *Messages

;; 3. With buffer *scratch* selected: C-z  ; To thumbify.  Then `c' to skip through the debugger.

;; 4. C-z  ; To dethumbify

;; 5. Repeat #3 and #4, if you like.

;; 6. With the frame normal size (dethumbified), manually (e.g., with the
;;    mouse) resize it to reduce the height.

;; 7. C-z  ; To thumbify.  Use `c' to skip through the debugger.

;; You will see that the thumbified height (e.g. aspect ratio) reflects
;; what the unthumbified height was.  This is the bug.  The thumbnail
;; should be the same as before - its height should not change.

;; RECIPE 2: Same as recipe 1, but this time, at step 7, step through the
;; debugger.  You will see that there is no bug - the thumbified frame
;; has the right height.

;; The behavior without using the debugger at all shows the bug.  The
;; call to `modify-parameters' seems to be optimized away or otherwise
;; neglects to apply the parameter changes.  The height parameter (as
;; an example) is left as it was after the call to `enlarge-font'.

;; I think this bug was introduced on or before 2014-10-20.  At least
;; that's when I started seeing similar problems.



(defun enlarge-font (&optional increment frame)
  ""
  (interactive "p")
  (setq frame  (or frame  (selected-frame)))
  (let ((fontname  (cdr (assq 'font (frame-parameters frame))))
        (count     100))
    (setq fontname  (frcmds-enlarged-font-name fontname frame increment))
    (while (and (not (x-list-fonts fontname))  (wholenump (setq count  (1- count))))
      (setq fontname  (frcmds-enlarged-font-name fontname frame increment)))
    (unless (x-list-fonts fontname) (error "Cannot change font size"))
    (modify-frame-parameters frame (list (cons 'font fontname)))))

(defun frcmds-enlarged-font-name (fontname frame increment)
  ""
  (when (query-fontset fontname)
    (let ((ascii  (assq 'ascii (aref (fontset-info fontname frame) 2))))
      (when ascii (setq fontname  (nth 2 ascii)))))
  (let ((xlfd-fields  (x-decompose-font-name fontname)))
    (unless xlfd-fields (error "Cannot decompose font name"))
    (let ((new-size  (+ (string-to-number (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
                        increment)))
      (unless (> new-size 0) (signal 'font-too-small (list new-size)))
      (aset xlfd-fields xlfd-regexp-pixelsize-subnum (number-to-string new-size)))
    ;; Set point size & width to "*", so frame width will adjust to new font size
    (aset xlfd-fields xlfd-regexp-pointsize-subnum "*")
    (aset xlfd-fields xlfd-regexp-avgwidth-subnum "*")
    (x-compose-font-name xlfd-fields)))

(defvar thumfr-font-difference 8 "")

(defun thumfr--frame-parameters-:set-function (sym defs)
  ""
  (custom-set-default sym defs)
  (dolist (frm  (frame-list))
    (when (and (frame-live-p frm)  (frame-parameter frm 'thumfr-thumbnail-frame))
      (modify-frame-parameters frm thumfr-frame-parameters))))

(defcustom thumfr-frame-parameters
  '(
    (menu-bar-lines . 0) ; <======================
;;;;    (tool-bar-lines . 0)
;;;     (scroll-bar-width . 6)
;;;     (scroll-bar-height . 6)
    )
  ""
  :type '(repeat (cons symbol sexp))
  :group 'convenience
  :set 'thumfr--frame-parameters-:set-function)

(defun thumfr-thumfr-parameter-p (parameter+value)
  ""
  (memq (car parameter+value) '(;; thumfr-is-a-thumbnail-frame
                                thumfr-thumbnail-frame
                                thumfr-non-thumbnail-frame)))

(defun thumfr-thumbnail-frame-p (&optional frame)
  ""
  (interactive)
  (frame-parameter frame 'thumfr-is-a-thumbnail-frame))

(defun thumfr-toggle-thumbnail-frame (&optional frame)
  ""
  (interactive)
  (setq frame  (or frame  (selected-frame)))
  (if (thumfr-thumbnail-frame-p frame)
      (thumfr-dethumbify-frame frame)
    (thumfr-thumbify-frame frame)))

(defun thumfr-remove-if (pred xs)
  ""
  (let ((result  ()))
    (dolist (x  xs)  (unless (funcall pred x) (push x result)))
    (nreverse result)))

(defun thumfr-thumbify-frame (&optional frame)
  ""
  (interactive)
  (message "TH 1, THUMBNAIL-P: %S" (thumfr-thumbnail-frame-p))
  (setq frame  (or frame  (selected-frame)))
  (let* ((fr-params  (frame-parameters frame))
         (to-thumb   (frame-parameter frame 'thumfr-non-thumbnail-frame))
         (other      (thumfr-remove-if #'thumfr-thumfr-parameter-p fr-params)))

    (unless (thumfr-thumbnail-frame-p)
      (set-frame-parameter frame 'thumfr-thumbnail-frame other)
      (condition-case thumfr-thumbify-frame
          (progn
            (enlarge-font (- thumfr-font-difference) frame)
            (debug) ; @@@@@ Comment out `(debug)', or use `c' in debugger, to see the problem.
            ;; @@@@@@ THIS CALL TO `modify-frame-parameters' does not work (does nothing).
            (when to-thumb (modify-frame-parameters frame to-thumb))
            (modify-frame-parameters frame thumfr-frame-parameters)
            (set-frame-parameter frame 'thumfr-is-a-thumbnail-frame t)) ; SUCCESSFUL - thumbified
        (font-too-small                 ; Try again, with a larger font.
         (set-frame-parameter frame 'thumfr-non-thumbnail-frame to-thumb)
         (set-frame-parameter frame 'thumfr-is-a-thumbnail-frame nil)
         (unless (> thumfr-font-difference 0)
           (error (error-message-string thumfr-thumbify-frame)))
         (let ((thumfr-font-difference  (1- thumfr-font-difference)))
           (thumfr-thumbify-frame frame)))
        (error
         (set-frame-parameter frame 'thumfr-non-thumbnail-frame to-thumb)
         (set-frame-parameter frame 'thumfr-is-a-thumbnail-frame nil)
         (error (error-message-string thumfr-thumbify-frame))))))
  (message "TH 2, THUMBNAIL-P: %S" (thumfr-thumbnail-frame-p)))

(defun thumfr-dethumbify-frame (&optional frame)
  "Restore thumbnail FRAME to original size (default: selected frame)."
  (interactive)
  (message "DE 1, THUMBNAIL-P: %S" (thumfr-thumbnail-frame-p))
  (setq frame  (or frame  (selected-frame)))
  (let* ((fr-params  (frame-parameters frame))
         (to-normal  (frame-parameter frame 'thumfr-thumbnail-frame))
         (other      (thumfr-remove-if #'thumfr-thumfr-parameter-p fr-params)))
    (when (thumfr-thumbnail-frame-p)    ; No-op if not a thumbnail.
      (set-frame-parameter frame 'thumfr-non-thumbnail-frame other) ; ????
      (condition-case thumfr-dethumbify-frame
          (progn
            (enlarge-font thumfr-font-difference frame) ; In `frame-cmds.el'.
            (modify-frame-parameters frame to-normal)
            (set-frame-parameter frame 'thumfr-is-a-thumbnail-frame nil)) ; SUCCESSFUL - dethumbified
        (error
         (set-frame-parameter frame 'thumfr-thumbnail-frame to-normal)
         (set-frame-parameter frame 'thumfr-is-a-thumbnail-frame t)
         (error (error-message-string thumfr-dethumbify-frame))))
      (select-frame-set-input-focus frame)))
  (message "DE 2, THUMBNAIL-P: %S" (thumfr-thumbnail-frame-p)))


;; This setting didn't help.  I tried it, hoping that perhaps this bug was related to bug #14032.
;; (setq default-frame-alist '((vertical-scroll-bars) (horizontal-scroll-bars)
;;                             (scroll-bar-height . 0) (scroll-bar-width . 0)))


;; Misc. debug help.
(setq pop-up-frames t) ; To see *Messages*
(global-set-key "\C-z" 'thumfr-toggle-thumbnail-frame)
(defvar foo nil "")
(setq pop-up-frames t)
(defun foo ()
  (interactive)
  (setq foo (frame-parameters))
  (describe-variable 'foo))
(global-set-key "\C-o" 'foo)

(provide 'test-thumb)


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

end of thread, other threads:[~2020-09-07 17:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-07  6:03 bug#22105: 25.1.50; REGRESSION - `modify-frame-parameters' Drew Adams
2015-12-07 10:35 ` martin rudalics
2015-12-07 17:00   ` Drew Adams
2015-12-08  9:17     ` martin rudalics
2015-12-08 14:07       ` martin rudalics
2015-12-12 10:44         ` martin rudalics
2015-12-12 10:59           ` Eli Zaretskii
2015-12-12 13:46             ` martin rudalics
2016-04-30 22:29               ` Lars Ingebrigtsen
2016-05-01  1:26                 ` Drew Adams
2019-08-08  4:07 ` Stefan Kangas
2019-08-08 15:18   ` Drew Adams
2020-09-07 16:28     ` Lars Ingebrigtsen
2020-09-07 16:35       ` Eli Zaretskii
     [not found]     ` <<87sgbt5z63.fsf@gnus.org>
     [not found]       ` <<83y2llmtn7.fsf@gnu.org>
2020-09-07 17:11         ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.