From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: pranshu sharma Newsgroups: gmane.emacs.devel Subject: Re: Add function to rotate/transpose all windows Date: Sun, 29 Sep 2024 17:36:19 +1000 Message-ID: <87v7yeykr0.fsf@gmail.com> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10136"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , emacs-devel@gnu.org To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 29 10:12:00 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 1sup27-0002Wg-BX for ged-emacs-devel@m.gmane-mx.org; Sun, 29 Sep 2024 10:11:59 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sup1T-0007Ri-UA; Sun, 29 Sep 2024 04:11:19 -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 1suoTj-0004FD-Lj for emacs-devel@gnu.org; Sun, 29 Sep 2024 03:36:27 -0400 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suoTi-0000ZE-45; Sun, 29 Sep 2024 03:36:27 -0400 Original-Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-20b58f2e1f4so5974805ad.2; Sun, 29 Sep 2024 00:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727595384; x=1728200184; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=rL6/ES9K1vp90t6pus161F0DfAi57ju7ZXXg05O3ibY=; b=bTQ6/Ir/WxWMB1Y2O279OOoQDlyCrnleCmxEReS/pg5rg/RDa/azieS1raeHTf/Aif kT6dutO/jipSZb6KDv8MHT7JmJ2JTRsCaC/Hjo3jQkp8uphHb5ieyFr93F6vWcU8gI1N phu/o4lSeyK5sUA5sH1gzFLD/W/oqilVKzqRuyNqm5xl6vgOAyPbesyl5SWENW05ERXM /JZQiMCWg08SW0djoMF8BembowKw6G4mfCu0xbMig7lRc3uzEv6v9FU/y+tvJ46Pj2pc iCFs/oKvZzMOe77q6E55idx4dbRqWhbDBhDhgym2GrDI/cxh+6aHQyioDRoqbaDFI0Tb u9Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727595384; x=1728200184; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rL6/ES9K1vp90t6pus161F0DfAi57ju7ZXXg05O3ibY=; b=PNT7c3ZXp+wiI53fx9vWrUpmk9B/1RCiZ7T3gORZSOlwx4NXeVUJ9SXeZiCC63caWS 5AW2KujyWO8bc+WTDnNM+KyGj8gkHsPJoD0B5llcclRF+p8v2I7tiVNM4mxdhLzFOP/E xu9LwweT99GxHOv4Q8vFkmpZ1I1hu4vEYS5WL6SRTWlYXTH8k62MWyAq8Wdd4DKiqZII ke170VtS4NLotnAOJyQIN7/JblE2yNnepftTpjHxFgDkwK10zjxl0N/wEjkPLpVkF0pe heqMSEVzggCLEj40QsnXjhfkhKc8oCH00XSI4gHoeGZR/1jzyXjKR8iwvzs40VRjBuNj zNbw== X-Forwarded-Encrypted: i=1; AJvYcCUAL/4Q57AWYrMyZIR6F/CJIU6gZzhYH4TOlYU5QjG/TOB+ac6VF11D3WBzm4Yv+xcjvs7vJJPhdUtM3w==@gnu.org X-Gm-Message-State: AOJu0YwLU5IYqqB5ImPgpEvCdvQJuisye+PNFSvVCIwQJUgyh0RY4OUL uhhO2caiIkXYJGvSfFF9sFgZnxzPjwvz5TqsurQIju+FxOtowe+P5MzH+Q== X-Google-Smtp-Source: AGHT+IEwH2KaS49vwS+aUWIhazTRLNEki/uztrnHMOtzBUVb9cAC5PDk4ck4bQkKTsKBawF+SRY0xA== X-Received: by 2002:a17:902:ce12:b0:205:8275:768 with SMTP id d9443c01a7336-20b36aee9edmr122669635ad.21.1727595383798; Sun, 29 Sep 2024 00:36:23 -0700 (PDT) Original-Received: from pebl ([2001:8003:7816:8300:bbce:8c3e:8e68:23c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e6e7e8sm35935955ad.309.2024.09.29.00.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Sep 2024 00:36:23 -0700 (PDT) In-Reply-To: (martin rudalics's message of "Sat, 28 Sep 2024 16:48:25 +0200") Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=pranshusharma366@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 29 Sep 2024 04:11:18 -0400 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:324184 Archived-At: >> In a scinario like this, where (caddar (window-tree)) is a list, the >> function does not work as it will not have any anchor point. > > Do you mean that your function doesn't work because A has to be split > twice - once to produce B and then to produce C? Something like that, but I fixed now, see code below > What is the anchor point here? Does it work because you have to split A > once only and then deal with the split off window only? I don't know > how to help you but I suppose your function should work by extracting > from the window tree all windows on the same level and recursively apply > itself on the respective tails of the window tree at that level. The problem was that I was splitting off another window as I was not already desyroying the whole tree. Thanks for your explenation, I found out I was only over complicating it by not destroying windows, so I gave up that approach. This time instead of calling delete-other-windows, I recusivly walked window subtree and deleted them. The following code implements transpose-frame and which works fine, I tested with some random window layouts and it worked for all. It uses the split-window refer argument. The code: ----------------------------------------- (defun transpose-frame (arg) "Transpose frame, or if arg is non-nil, selected window." (interactive "P") (when-let* ((win-tree (car (window--subtree (if arg (window-parent (selected-window)) (frame-root-window))))) (fwin (if arg (selected-window) (let ((win (window-child (frame-root-window)))) (while (not (window-live-p win)) (setq win (window-child win))) win))) (_ (not (windowp win-tree)))) (toggle-window-split (let* (delist (res (deepmap (lambda (e) (if (windowp e) (prog1 (cons e (window-edges e)) (unless (equal fwin e) (push e delist))) e)) win-tree))) (mapc 'delete-window delist) res) fwin))) ;; Is there already another inbuilt funcion like this? (defun deepmap(func ls) (if (null ls) () (cons (if (listp (car ls)) (deepmap func (car ls)) (funcall func (car ls))) (deepmap func (cdr ls))))) (defun toggle-window-split (subtree cwin) (pcase-let* ((`(,eee . ,flen) (if (car subtree) (cons 1 (window-width cwin)) (cons 0 (window-height cwin)))) (ilen (float (- (nth (+ 2 eee) (cadr subtree)) (nth (+ eee 0) (cadr subtree)))))) (mapc (pcase-lambda (`(,win . ,size)) (if (listp win) (toggle-window-split win (split-window cwin (- (round (* flen (/ size ilen)))) (car subtree) nil (seq-some (lambda (x) (and (windowp x) x)) (flatten-list win)))) (split-window cwin (- (round (* flen (/ size ilen)))) (car subtree) nil win))) (mapcar (lambda (e) (pcase-let ((`(,edges ,window?) (if (windowp (car e)) (list (cdr e) (car e)) (list (cadr e) e)))) (cons window? (- (nth (+ 2 eee) edges) (nth eee edges))))) (nreverse (cdddr subtree)))) (unless (windowp (caaddr subtree)) (toggle-window-split (caddr subtree) cwin)))) -----------------------------------------