From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Pawe=C5=82_?= =?UTF-8?Q?Kra=C5=9Bnicki?= Newsgroups: gmane.emacs.bugs Subject: bug#46476: Feature request: Right-aligning part of the modeline Date: Sat, 13 Feb 2021 17:30:16 +0100 Message-ID: References: <83ft20e5z0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29958"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46476@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 13 17:31:27 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1lAxpN-0007h3-II for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Feb 2021 17:31:25 +0100 Original-Received: from localhost ([::1]:36664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAxpM-000228-9m for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Feb 2021 11:31:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAxp4-00020S-3Y for bug-gnu-emacs@gnu.org; Sat, 13 Feb 2021 11:31:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAxp0-00064m-EV for bug-gnu-emacs@gnu.org; Sat, 13 Feb 2021 11:31:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lAxp0-0007Bt-BI for bug-gnu-emacs@gnu.org; Sat, 13 Feb 2021 11:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Pawe=C5=82_?= =?UTF-8?Q?Kra=C5=9Bnicki?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Feb 2021 16:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46476 X-GNU-PR-Package: emacs Original-Received: via spool by 46476-submit@debbugs.gnu.org id=B46476.161323383727607 (code B ref 46476); Sat, 13 Feb 2021 16:31:02 +0000 Original-Received: (at 46476) by debbugs.gnu.org; 13 Feb 2021 16:30:37 +0000 Original-Received: from localhost ([127.0.0.1]:34927 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lAxoa-0007BD-NN for submit@debbugs.gnu.org; Sat, 13 Feb 2021 11:30:36 -0500 Original-Received: from mail-pf1-f182.google.com ([209.85.210.182]:36545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lAxoX-0007Au-Ey for 46476@debbugs.gnu.org; Sat, 13 Feb 2021 11:30:36 -0500 Original-Received: by mail-pf1-f182.google.com with SMTP id z15so1543418pfc.3 for <46476@debbugs.gnu.org>; Sat, 13 Feb 2021 08:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LbRwrwuTnQ0MiZJ1m20NJqZEht0EP5aVipIlGQBtpHA=; b=I1q72aWORfa0OLqjQDzjM02P1OndrmCDjnyFgwI6lrYvwrc05/tQmMCK5RIfyyHA9K yxs9jVzTlcLIO8mePl6zagJs8Jj8e/1IRcP1tW9tXzd5YBaM05CRGnT8VmmyDjN7SK4D 576GJ0IyF5y3/6Kg/3lgQQqCQ2bwms7TsGR7ozcc1VoH3jCeJaDQo+/IQASBrP5ORNnD CXEQPyDXO9FSm031fwTkNwFEKZcOAr+J+q0oTVFMloED4YV4yVWTXFsqxD4AAo+AWqEY ZZYSos8DIY8QrnpmfYCwrRYD5NAvTmFCg4YXmIgcPZ42L+DNHWBP8eXzhe+3CudU4c87 +KJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LbRwrwuTnQ0MiZJ1m20NJqZEht0EP5aVipIlGQBtpHA=; b=gNAWmHG5bD/mWRggqIY9pcsVhpVVnlvkKL8RRxa4hcrfZyHNxBJZIMFlVJZSAY9ZJX Ucfiq1DBoTCvgaD6ksKx3QBZyHso1hHctAQomSnq9Leh9xvC2rDm8yAo4iVncbs4C2eF z4PitVsf3aU9k1qpt7bIOmqOO6Ei/JiGlpHgnLTRwifqKjhj+sPGYeeodVhr7EYPcG2k G2DWlP2fUCPsA3fLR8VZO/j8bqpvrf/b10I3ss7DOIub54N8SGEI362JBjf+ovKsdJ/r xzdi8nKlE9Gi6cMm7al54yZv9KJkDbPoNmP8+R8dTHsCVd6v5QKc5Vd6CKS0fCLQoQPp 7OOw== X-Gm-Message-State: AOAM532bhbzBrJJzjqzLBVWxUcuuk6d67swqTLbMemTf/bHRixC3rcIA qD0p/SI2I6Ksre3enoqpDPlSQCJqMzehV9eatkA= X-Google-Smtp-Source: ABdhPJyJFcsJDmhVmUAJzSUhbTo+hnMStwuYr/adOuNMfBNol7xPKxQeXlit1CZpGeXoCNH2leOZlse+o3vIuy2OMyU= X-Received: by 2002:a62:ce82:0:b029:1d9:1872:294b with SMTP id y124-20020a62ce820000b02901d91872294bmr7701804pfg.36.1613233827241; Sat, 13 Feb 2021 08:30:27 -0800 (PST) In-Reply-To: <83ft20e5z0.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199935 Archived-At: > Can you describe how is this done in Lisp? Sure. The most common solution is to use a text property that displays a space with the `:align-to' property. Here's a simplified version of the code from the popular `powerline' package: (defvar ml-text-scale-factor 1.0 "Ratio of mode-line text size to default text size, as a float. This is needed to make sure the text is properly aligned.") (defun ml-fill-to-center (reserve face) "Return empty space to the center, leaving RESERVE space on the right." (setq reserve (* ml-text-scale-factor reserve)) (propertize " " 'display `((space :align-to (- (+ center (.5 . right-margin)) ,reserve (.5 . left-margin)))) 'face face)) (defun ml-fill-to-right (reserve face) "Return empty space, leaving RESERVE space on the right." (setq reserve (* ml-text-scale-factor reserve)) (when (and window-system (eq 'right (get-scroll-bar-mode))) (setq reserve (- reserve 2))) ; May be 3 instead of 2 with some toolkits? (propertize " " 'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve))) 'face face)) (defun ml-render-2-part (left right &optional fill-face) "Show a modeline with left and right aligned parts." (concat left (ml-fill-to-right (string-width (format-mode-line right)) fill-face) right)) (defun ml-render-3-part (left center right &optional fill-face) "Show a modeline with left, center, and right aligned parts." (concat left (ml-fill-to-center (/ (string-width (format-mode-line center)) 2.0) fill-face) center (ml-fill-to-right (string-width (format-mode-line right)) fill-face) right)) ;; (setq mode-line-format '((:eval (ml-render-2-part "l" "r")))) ;; (setq mode-line-format '((:eval (ml-render-3-part "lllll" "c" "r")))) > The immediate question about this I have is what to do when the > mode-line string is too long for the window's width? Right now, we > simply chop the stuff on the right that doesn't fit, but if the > mode-line string has 2 or 3 different part, that should be revised, > right? I'm not sure. With the current Lisp solutions, the modeline gets chopped on the right too, and it seems that people either don't mind that at all, or they use custom "segment" logic. The idea here is that the modeline is composed of a few segments, with each having a priority number. As the window shrinks, the segments get hidden in discrete jumps starting from the lowest priority, until only the segment(s) with the highest priority number remain. I think there may not be any demand for an intermediate solution that would let the user configure hiding with granularity of left/center/right.