Subject: 29.0.50; set-frame-width and frame-width are not exactly complimentary

From: Pankaj Jangid <[email-masked]>
Date: Sat, 09 Jul 2022 08:58:46 +0530

I have written a small lisp function to toggle width of frame to twice
and half. This is not behaving as desired. Here is my lisp.

--8<---------------cut here---------------start------------->8---
(defun my/toggle-frame-width ()
  "Toggle \"frame-width\"."
  (interactive)
  
  (let ((width (frame-width)))
	(if (and (> width 75) (< width 85))
		(set-frame-width nil (* width 2))
	  (set-frame-width nil (/ width 2))
	(message "Frame size: %sx%s" (frame-width) (frame-height)))))
(global-set-key (kbd "<f9>") 'my/toggle-frame-width)
--8<---------------cut here---------------end--------------->8---

Steps:
1. emacs -Q
2. Evaluate above lisp. (WARN) This binds <f9> also.
3. Pres <f9> a couple of times 

Result:
After a couple of iterations. The frame-width is getting smaller and
smaller.

Desired behaviour:
It should only toggle the width to double and half alternately.

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
 of 2022-07-09 built on anant
Repository revision: 29c8866c7fcd325995c6fc9b2b18537855fee52c
Repository branch: master
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --prefix=/home/pankaj/.local --with-pgtk'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XIM
GTK3 ZLIB

Important settings:
  value of $LANG: en_IN.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Group

Minor modes in effect:
  gnus-undo-mode: t
  winner-mode: t
  windmove-mode: t
  editorconfig-mode: t
  marginalia-mode: t
  which-key-mode: t
  hl-line-mode: t
  savehist-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-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
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort vc-hg vc-git diff-mode vc-bzr vc-src vc-sccs vc-svn vc-cvs
vc-rcs log-view pcvs-util vc vc-dispatcher mail-extr emacsbug gnus-async
gnus-ml disp-table nndraft nnmh utf-7 nnml nnfolder cl-extra epa-file
network-stream nsm gnus-agent gnus-srvr gnus-score score-mode nnvirtual
gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls dig nntp
gnus-cache gnus-sum shr pixel-fill kinsoku url-file url-dired svg dom
gnus-group gnus-undo .gnus gnus-start gnus-dbus dbus xml gnus-cloud
nnimap nnmail mail-source utf7 netrc nnoo parse-time gnus-spec gnus-int
gnus-range message sendmail yank-media puny dired dired-loaddefs rfc822
mml mml-sec epa derived epg rfc6068 epg-config mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev
gmm-utils mailheader gnus-win gnus nnheader gnus-util mail-utils range
mm-util mail-prsvr wid-edit checkdoc lisp-mnt corfu init my-init
org-element avl-tree generator org org-macro org-footnote org-pcomplete
pcomplete org-list org-faces org-entities noutline outline easy-mmode
org-version ob-plantuml ob-sql ob-css ob-js ob-java ob-C cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs ob-python python ob-R ob ob-tangle org-src ob-ref ob-lob
ob-table ob-exp ob-comint ob-emacs-lisp ob-core ob-eval org-table
oc-basic bibtex iso8601 time-date ol org-keys oc org-compat advice
org-macs org-loaddefs format-spec cal-menu calendar cal-loaddefs server
winner windmove modus-vivendi-theme modus-themes delight eglot array
filenotify jsonrpc ert pp ewoc debug backtrace help-mode find-func xref
flymake-proc flymake warnings pcase project imenu editorconfig
rust-utils thingatpt rust-mode rust-rustfmt rust-playpen rust-compile
compile text-property-search comint ansi-color ring rust-cargo
marginalia which-key exec-path-from-shell hl-line savehist avoid
cus-load finder-inf tex-site cider-autoloads clojure-mode-autoloads
compat-autoloads corfu-autoloads denote-autoloads
dockerfile-mode-autoloads eglot-autoloads rx marginalia-autoloads
markdown-mode-autoloads php-mode-autoloads prettier-autoloads
f-autoloads dash-autoloads request-autoloads rust-mode-autoloads
use-package-ensure-system-package-autoloads system-packages-autoloads
info vertico-autoloads which-key-autoloads package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map byte-opt gv bytecomp byte-compile cconv
url-vars cl-loaddefs cl-lib early-init rmc iso-transl tooltip eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine 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 emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
faces cus-face macroexp files window text-properties overlay sha1 md5
base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo gtk pgtk
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 818637 38632)
 (symbols 48 37719 0)
 (strings 32 158969 5703)
 (string-bytes 1 4933609)
 (vectors 16 59200)
 (vector-slots 8 724066 31648)
 (floats 8 367 165)
 (intervals 56 690 0)
 (buffers 992 26))