From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Fix width tabs Date: Thu, 27 Oct 2022 10:40:27 +0300 Organization: LINKOV.NET Message-ID: <867d0lww7o.fsf@mail.linkov.net> References: <87wnhtfad7.fsf@gmail.com> <865ypcmx6s.fsf@mail.linkov.net> <87sfsgfd2b.fsf@gmail.com> <86mtimzt13.fsf@mail.linkov.net> <86fsock4f1.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11664"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: Matthias Meulien Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 27 09:57:57 2022 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 1onxm1-0002w9-1L for ged-emacs-devel@m.gmane-mx.org; Thu, 27 Oct 2022 09:57:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onxkQ-0001Ug-Cc; Thu, 27 Oct 2022 03:56:18 -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 1onxkA-0001Hl-OQ for emacs-devel@gnu.org; Thu, 27 Oct 2022 03:56:06 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onxk7-0008FD-M5 for emacs-devel@gnu.org; Thu, 27 Oct 2022 03:56:01 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 62A9C20002; Thu, 27 Oct 2022 07:55:53 +0000 (UTC) In-Reply-To: <86fsock4f1.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 21 Feb 2022 10:30:27 +0200") Received-SPF: pass client-ip=217.70.183.200; envelope-from=juri@linkov.net; helo=relay7-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298605 Archived-At: --=-=-= Content-Type: text/plain > OTOH, I can't imagine how you could implement a formatting function > without requiring two-pass tabs generation that is highly inefficient: > after the first pass you get the number of tabs, groups of tabs, > and their names. Then on the second pass you can pad names > with required amount of space proportional to the total number of tabs. > > So a more efficient implementation would be to modify the strings > that represent the tab names in the result of tab-bar-format-list > (e.g. by using advice-add for experimentation). But a drawback is > that then you need to rely on the details of implementation of the > internal data structure. I still see no other way to implement pixel-based filling/justifying of tab names. So here is a prototype to try that later will be adapted to tab-bar.el. It seems that's all we can do for nicer-looking tabs. At least, it resizes tabs like in web browsers. And the default value of tab-bar-tab-width-max is the same as in Firefox. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=tab-bar-tab-width-max.el Content-Transfer-Encoding: quoted-printable (require 'cl) (defcustom tab-bar-tab-width-max 220 "Maximum number of pixels allowed for the width of a tab name. When nil, there is no limit on maximum width." :type '(choice (const :tag "No limit" nil) (integer :tag "Max width" :value 220)) :group 'tab-bar :version "29.1") (defun tab-bar-format-list-pixelize (orig-fun &rest args) (let ((non-tab 0) ;; all non-tab items including buttons and indicators (num-tab 0) ;; number of adjustable tabs (tab-width tab-bar-tab-width-max) (items (apply orig-fun args))) (dolist (item items) (when (and (eq (nth 1 item) 'menu-item) (stringp (nth 2 item))) (let ((width (string-pixel-width (propertize (nth 2 item) 'face 'ta= b-bar)))) (if (or (not (memq (nth 3 item) '(ignore tab-bar-menu-bar))) (eq (nth 0 item) 'current-tab)) (setq num-tab (+ num-tab 1)) (if (not (eq (nth 0 item) 'align-right)) (setq non-tab (+ non-tab width)) (setq non-tab (+ non-tab 100))))))) (when (> num-tab 0) (setq tab-width (min (/ (- (frame-pixel-width) non-tab) num-tab) tab-= bar-tab-width-max))) (dolist (item items) (when (and (eq (nth 1 item) 'menu-item) (stringp (nth 2 item)) (or (and (not (memq (nth 3 item) '(ignore tab-bar-menu-bar= ))) (not (memq (nth 0 item) '(add-tab history-back hi= story-forward)))) (eq (nth 0 item) 'current-tab))) (let* ((width (string-pixel-width (propertize (nth 2 item) 'face 't= ab-bar))) (name (nth 2 item)) (len (length name)) (ins-pos (- len (if (get-text-property (1- len) 'close-tab n= ame) 1 0))) del-pos) (while (< (string-pixel-width (propertize (nth 2 item) 'face 'tab= -bar)) tab-width) (setf (substring (nth 2 item) ins-pos ins-pos) (apply 'propertize " " (text-properties-at 0 (nth 2 item)= )))) (while (> (string-pixel-width (propertize (nth 2 item) 'face 'tab= -bar)) tab-width) (setq name (nth 2 item) len (length name) del-pos (- len (if (get-text-property (1- len) 'close-tab= name) 1 0))) (setf (substring (nth 2 item) (1- del-pos) del-pos) ""))))) items)) (advice-add 'tab-bar-format-list :around 'tab-bar-format-list-pixelize '((name . tab-bar-format-list-pixelize))) --=-=-=--