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: Mon, 30 Sep 2024 16:29:23 +1000 Message-ID: <87ikudk62k.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> <87v7yeykr0.fsf@gmail.com> <19ca7821-e034-4ae5-9ff6-570243329d74@gmx.at> <87r09224pe.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="20763"; 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 Mon Sep 30 12:59:34 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 1svE7p-0005Kp-QI for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Sep 2024 12:59:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svE6n-0004cI-Jh; Mon, 30 Sep 2024 06:58:29 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svA3Z-0002q5-Du for emacs-devel@gnu.org; Mon, 30 Sep 2024 02:38:56 -0400 Original-Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svA2W-0004cN-3J for emacs-devel@gnu.org; Mon, 30 Sep 2024 02:38:35 -0400 Original-Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5dc93fa5639so1967647eaf.1; Sun, 29 Sep 2024 23:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727678150; x=1728282950; 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=T756k7mUqazIge9Bq5JkzCykahFmGLgWaTMbdZe0DRI=; b=SO5+i4NJ1IR9xPnKo6TDfsqCrNPIY++AKGDVbKEIf/EKYGcnGDVh9nBdJHBjUFqxci j1gspBjqR4n+M7QgeqwLNJZMM0VV4sYXfSkuQk8dTuKeFGvkjuAJlB2uiqCoeO7U+94H 8sc/nsf73sGG2nkAQHNY16iLUtDNhcYjL1fZhfs9B8goxM0ZEQ+UA68BA7OCcWoYpEvC m6fJcI1vIdS0WzSloEWJ+e4DbPxWu55avXik6MSOgn8BSofkFfpE2TtXlJ62nJjNYCc9 WRG/3b6Bb88BwaoDE2kAL0cKJnn0piAvGjvI0GoM+RK5TxOviHDJ5oPDsU3woUdqPBlL Etaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727678150; x=1728282950; 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=T756k7mUqazIge9Bq5JkzCykahFmGLgWaTMbdZe0DRI=; b=MzQCaAXURx6bt8KyrJ3CIJmlyN5qRLR5Pk2KakO2AXyTeBBuq1J7HN6h1ZqiGO78/o tOJqOGfY76FVMBiQ2B0oas8qd/t+XoGDhrS/7ebrhC9tXW6FaENQDyvG4DW+jyPjR+3v dWtgNAQQC7ijTrUb+G4t/7TFfVNWHb734eIBtlzs73sDnd7Xcq/l1/dwXuRhNTIjaVUp 3NGVZXwIjZhGBOuMIXzshUf0G3dsUJgWrEzsae/Sqnm91MLy/rwJ+QAE27IpCx7bCQNU YPXKyRdflrlGbBh/Vw5WzxJlwh75kGGxB1Rd6qrDT6iu4sRbVZBzkbpx/g6btjMhNyK1 +mcw== X-Forwarded-Encrypted: i=1; AJvYcCWhjZEpcDRLcjVy8tuPP0guIYL13lYs/t/Oj8Nb/aEMdmcHCazvsNTpUxUfqBXFlxnBtoOSDfEUOcKfNA==@gnu.org X-Gm-Message-State: AOJu0YxrqTEQ5cP3o678fwstYVmWqIsiBgUv9szp7o7Vg70tN6oJzFYh RBweyIH6YJtg1LiirkV2emFQAku43XTvW1QwfJoffNejrcrGDC2MsZFPhw== X-Google-Smtp-Source: AGHT+IFACeCORouBGfSqM+c0V7PgTHsERDc3eMfmiVS2wMo+lmb7lEjqAvQuFetFqrpiMdCCFCbolA== X-Received: by 2002:a17:90b:111:b0:2e0:876c:8cb4 with SMTP id 98e67ed59e1d1-2e0b8e8b687mr13267560a91.30.1727677769460; Sun, 29 Sep 2024 23:29:29 -0700 (PDT) Original-Received: from pebl ([2001:8003:7816:8300:d7b5:178d:8f03:afa2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e0b6c7f58csm7026447a91.20.2024.09.29.23.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Sep 2024 23:29:29 -0700 (PDT) In-Reply-To: (martin rudalics's message of "Sun, 29 Sep 2024 16:48:15 +0200") Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=pranshusharma366@gmail.com; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Sep 2024 06:58:27 -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:324217 Archived-At: Hello Martin, After some 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 docstrings for the more complex function, and I don't know how to explain what transpose does. 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. ----------------------------- (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)." (let (list) (while window (setq list (cons (cond ((window-top-child window) (cons t (cons (list (window-pixel-height window) (window-pixel-width window)) (window--subtree-with-size (window-top-child window) t)))) ((window-left-child window) (cons nil (cons (list (window-pixel-height window) (window-pixel-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)) (defun rotate-frame-clockwise (subtree-only) "Like `rotate-frame-anticlockwise' but rotate clockwise instead." (interactive "P") (apply-rearrange-frame subtree-only '(left . below) nil)) (defun flip-frame-horizontally (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 '(below . left) t)) (defun flip-frame-verticly (subtree-only) "Like `flip-frame-horizontally' but flip verticlly instead." (interactive "P") (apply-rearrange-frame subtree-only '(above . right) t)) (defun transpose-frame (subtree-only) (interactive "P") (apply-rearrange-frame subtree-only '(right . below) nil)) (defun apply-rearrange-frame (subtree-only conf norm-size) "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))))) (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))) (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) (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) (split-window cwin split-size split-type t win)))) (mapcar (lambda (e) (pcase-let* ((`(,size ,window?) (if (windowp (car e)) (list (cdr e) (car e)) (list (cadr e) e)))) (cons window? (if (car subtree) (car size) (cadr size))))) (nreverse (cdddr subtree)))) (unless (windowp (caaddr subtree)) (toggle-window-split (caddr subtree) cwin conf norm-size))))