From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: Add function to rotate/transpose all windows Date: Mon, 30 Sep 2024 10:57:57 +0200 Message-ID: <0d879e95-c37e-416d-b439-daa6384c4f30@gmx.at> References: <87setpdv21.fsf@gmail.com> <86zfnxcg57.fsf@gnu.org> <877cb09ln4.fsf@gmail.com> <9005cccc-7545-4257-b2c0-885a13d3bde2@gmx.at> <86o74aa41b.fsf@gnu.org> <3d4546ac-70d9-4865-b42d-0dc50cb0f3a7@gmx.at> <878qvcgqpu.fsf@gmail.com> <0138d382-8e63-4b53-8c2c-fece826a7d0a@gmx.at> <87plooaw1w.fsf@gmail.com> <87v7yeykr0.fsf@gmail.com> <19ca7821-e034-4ae5-9ff6-570243329d74@gmx.at> <87r09224pe.fsf@gmail.com> <87ikudk62k.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17825"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Eli Zaretskii , emacs-devel@gnu.org To: pranshu sharma Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 30 10:58:55 2024 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 1svCF4-0004Wt-S7 for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Sep 2024 10:58:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svCEO-0005Fe-Ew; Mon, 30 Sep 2024 04:58:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svCEM-00059f-S2 for emacs-devel@gnu.org; Mon, 30 Sep 2024 04:58:11 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svCEK-0002kw-DF; Mon, 30 Sep 2024 04:58:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.at; s=s31663417; t=1727686679; x=1728291479; i=rudalics@gmx.at; bh=YA29TohS87XXcNUqzlxhL/cfFJZl+hCQfoAH5SGkI58=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=R63xOWfxKXegSphs3f34i+mrVGjuclISTv4RSCcmblzddMj/QL6W1Bql52GQb+lB AylmuUD7QKN8DvdTluijY2A3k3N0/OsHcJBtesOKN+4oZ8T7mgfY5Y64hM+JvC4dd LM7cxZhglaf05amq4TG8eg8F5liumNQJcKYRZCB3avY1onTJ8b3l+U0ddDNhFFtSE YwZSBpW599sHIcOiYmiDTiTxwPqMilJ9zFWBUgVVtvSWJ1lYpbuc5fhjFLnkEUo9X SWMKIbzrRV6lwAQz0k+L7UiC8UF/frhT4GKMibmlO5Lv7gJkzoHFmckksF8vIImM8 /ACcNuQg5KqBmanztg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from [192.168.31.113] ([212.95.5.26]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MoO6C-1s6iC71UYC-00mOYU; Mon, 30 Sep 2024 10:57:59 +0200 Content-Language: en-US In-Reply-To: <87ikudk62k.fsf@gmail.com> X-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Wpf+0oSJvcAenlW5qjL5Z2hp Received-SPF: pass client-ip=212.227.17.20; envelope-from=rudalics@gmx.at; helo=mout.gmx.net X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324210 Archived-At: > Hello Martin, > > After some work, ... remarkable work ... > the code is now complete and uses pixels instead colums > of. It can do everything the orignal transpose frame could (flip, > transpose, rotate), and results are the same. > > Some function are like opposites, eg flip-frame-horizontally and > flip-frame-verticly, I thought about merging them and using prefix arg, > but then prefix arg already in use for if or not to apply to partial > subtree instead frame. > > English is not my first language, so I was unable to make the docstring= s > for the more complex function, and I don't know how to explain what > transpose does. Let's hope someone will eventually proofread this as soon as we agree on a final version. > Also I think your error was coming from scroll and tool bars(should be > fixed now cuz pixels), but since terminal does not have them I couldnt > run into too small for splitting error on terminal. I rotated my windows a number of times and see no shrinking any more. Even with pixelwise resizing it's impossible to exclude that windows shrink over time but that's unavoidable unless one uses some heuristics. So I think that your code handles this well now. > (defun window--subtree-with-size (window &optional next) > "Like `window--subtree' but each window is replaced with the > list: (WINDOW PIXEL-HEIGHT PIXEL-WIDTH), and window-edges is replaced > with the list: (PIXEL-HEIGHT PIXEL-WIDTH)." As a rule, the first line of a doc-string should be a complete sentence and be at most 72 columns wide (see Appendix D.6 of the Elisp manual). And you should describe all arguments like WINDOW and NEXT. Alternatively, we could give 'window-tree' an optional PIXELWISE argument so it returns the pixel edges of windows. > (let (list) > (while window > (setq list > (cons > (cond > ((window-top-child window) > (cons t (cons (list (window-pixel-height window) (window-pixel-= width window)) Lines should not exceed 80 characters and you probably want to use 'cons' instead of 'list' here. > (window--subtree-with-size (window-top-child window) t)))) > ((window-left-child window) > (cons nil (cons (list (window-pixel-height window) (window-pixe= l-width window)) > (window--subtree-with-size (window-left-child window) t)))) > (t (list window (window-pixel-height window) (window-pixel-width= window)))) > list)) > (setq window (when next (window-next-sibling window)))) > (nreverse list))) > > > (defun rotate-frame-anticlockwise (subtree-only) > "If SUBTREE-ONLY is nil, rotate the whole frame anti clockwise else = only > apply on the subtree of selected window." > (interactive "P") > (apply-rearrange-frame subtree-only '(right . above) nil)) I think you should rename all these into something like 'rotate-windows-anticlockwise' and 'transpose-windows' (we are already using plurals in 'transpose-lines' and 'transpose-chars'). And we do not rotate the entire frame - the minibuffer window stays in place, for example. So I would try to say (defun rotate-windows-anticlockwise (&optional frame window) "Rotate windows of FRAME anticlockwise by 90 degrees. FRAME must be a live frame and defaults to the selected frame. By default rotate the root window of FRAME (or its main window if it differs from the root window). If WINDOW is non-nil ..." Which means that we need the additional features: (1) Rotate windows on any live frame. (2) Run the function on 'window-main-window' of FRAME unless WINDOW is defined and never rotate a side window. Rotating side windows would cause completely undefined behavior because their slots are expected to never change. Hence, if WINDOW is specified and is a side window, say that you cannot rotate side windows. (3) "subtree of selected window" is an undefined concept. You should say something like "to transpose all windows in the same combination as WINDOW" instead. But note that with a slightly more complex layout, no average user will know what that combination is (think of C-x 2 C-x 3 C-x o C-x o C-x 3). We could eventually try to flash all windows that would be affected by the change but that would be non-trivial. > (defun apply-rearrange-frame (subtree-only conf norm-size) I'd call this something like 'transpose-windows--rearrange' so you can change its behavior whenever you want. > "Transpose frame, or if SUBTREE-ONLY is non-nil, selected window." > (if (eq (next-window) (selected-window)) > (message "No windows to transpose.") > (let* ((win-tree (car (window--subtree-with-size > (if subtree-only > (window-parent (selected-window)) > (frame-root-window))))) Is fwin not the same as what 'frame-first-window' returns? If not, please telly why in a comment. > (fwin (if subtree-only > (selected-window) > (let ((win (window-child (frame-root-window)))) > (while (not (window-live-p win)) > (setq win (window-child win))) > win)))) > (mapc (lambda (win) > (when (and (windowp win) > (not (eq win fwin))) > (delete-window win))) Please tell in a comment why you flatten win-tree her. > (flatten-list win-tree)) > (toggle-window-split win-tree fwin conf norm-size) > (select-window fwin)))) > > (defun toggle-window-split (subtree cwin conf norm-size) Should become window--... and have its arguments described. > (pcase-let ((`(,ilen . ,flen) (if (car subtree) > (cons (float (car (cadr subtree))) > (float (window-pixel-width cwin))) > (cons (float (cadr (cadr subtree))) > (float (window-pixel-height cwin)))))) > (mapc > (pcase-lambda (`(,win . ,size)) > (let ((split-size (- (if norm-size > size > (round (* flen (/ size ilen)))))) > (split-type > (funcall (if (car subtree) 'car 'cdr) conf))) > (if (listp win) > (toggle-window-split win (split-window cwin > split-size > split-type > t > (seq-some > (lambda (x) > (and (windowp x) x)) > (flatten-list win))) > conf norm-size) Here I'd write (let ((refer (seq-some (lambda (x) (and (windowp x) x)) (flatten-list win)))) (toggle-window-split win (split-window cwin split-size split-type t refer) conf norm-size)) but I won't argue about styles. > (nreverse (cdddr subtree)))) > (unless (windowp (caaddr subtree)) > (toggle-window-split (caddr subtree) cwin conf norm-size)))) Whenever using things like cdddr, caaddr or caddr, please say in a comment what these are supposed to be. You have condensed the original version of your code considerably so please think about people who eventually want to understand what the code does. Many thanks, martin