unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Some ideas to improve Tab Bar
@ 2020-11-25  0:35 Gabriel do Nascimento Ribeiro
  2020-11-25  7:47 ` Juri Linkov
  2020-11-26 23:08 ` Gabriel do Nascimento Ribeiro
  0 siblings, 2 replies; 9+ messages in thread
From: Gabriel do Nascimento Ribeiro @ 2020-11-25  0:35 UTC (permalink / raw)
  To: emacs-devel@gnu.org

Some little ideas on how Tab Bar can be further improved:

1. Options to disable `tab-bar-back-button' and `tab-bar-forward-button' when `tab-bar-history-mode' is on. This will be similar to what option `tab-bar-close-button-show' is to `tab-bar-close-button'.

2. Trim spaces of tab bar name. The tab bar name can have additional spaces on the right:
    2.1. When tab bar name name is set explicitly with `tab-bar-rename-tab';
    2.2. When `tab-bar-tab-hints' is true and `tab-bar-tab-name-function' returns an empty string;

3. An easier way to add more items to Tab Bar to make it act more like a general Bar. The following example was shared in Emacs Devel mailing list on how to add a simple clock to the right of Tab Bar:
=========================================
  (advice-add 'tab-bar-make-keymap-1 :around
              (lambda (orig-fun)
                (append (funcall orig-fun)
                        `((display-time menu-item
                                        ,(concat
                                          (propertize " " 'display '(space :align-to (- right 5)))
                                          (format-time-string "%H:%M"))
                                        ignore))))
              '((name . tab-bar-display-time)))
=========================================

4. Maybe deprecate `winner-mode' in favor to `tab-bar-history-mode', since these two modes have similar functions. Using `tab-bar-history-mode' with only one Tab is like using `winner-mode'.

Regards,
Gabriel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-25  0:35 Some ideas to improve Tab Bar Gabriel do Nascimento Ribeiro
@ 2020-11-25  7:47 ` Juri Linkov
  2020-11-25 17:19   ` Gabriel do Nascimento Ribeiro
  2020-11-26 23:08 ` Gabriel do Nascimento Ribeiro
  1 sibling, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2020-11-25  7:47 UTC (permalink / raw)
  To: Gabriel do Nascimento Ribeiro; +Cc: emacs-devel@gnu.org

> Some little ideas on how Tab Bar can be further improved:

Thanks for the ideas.

> 1. Options to disable `tab-bar-back-button' and
> `tab-bar-forward-button' when `tab-bar-history-mode' is on.  This will
> be similar to what option `tab-bar-close-button-show' is to
> `tab-bar-close-button'.

The most difficult part is to choose a good option name.
Maybe, `tab-bar-history-buttons-show' is not too bad.

> 2. Trim spaces of tab bar name. The tab bar name can have additional spaces on the right:
>     2.1. When tab bar name name is set explicitly with `tab-bar-rename-tab';
>     2.2. When `tab-bar-tab-hints' is true and `tab-bar-tab-name-function' returns an empty string;

Sorry, I don't understand what is the problem.
When the user intentionally adds spaces in case 2.1.,
then why there is a need to trim spaces?

> 3. An easier way to add more items to Tab Bar to make it act more like
> a general Bar.  The following example was shared in Emacs Devel
> mailing list on how to add a simple clock to the right of Tab Bar:
> =========================================
>   (advice-add 'tab-bar-make-keymap-1 :around
>               (lambda (orig-fun)
>                 (append (funcall orig-fun)
>                         `((display-time menu-item
>                                         ,(concat
>                                           (propertize " " 'display '(space :align-to (- right 5)))
>                                           (format-time-string "%H:%M"))
>                                         ignore))))
>               '((name . tab-bar-display-time)))
> =========================================

Do you propose to add functions that would allow doing this more easily?
Maybe using some hooks?

> 4. Maybe deprecate `winner-mode' in favor to `tab-bar-history-mode',
> since these two modes have similar functions.
> Using `tab-bar-history-mode' with only one Tab is like using
> `winner-mode'.

`winner-mode' should not be deprecated because it's still useful
for users who don't use tabs with `tab-bar-mode'.  So `winner-mode'
works fine when tabs are not used.  OTOH, `winner-mode' breaks tabs
when used with `tab-bar-mode', so `tab-bar-history-mode' is needed
to do the same when tabs are used.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-25  7:47 ` Juri Linkov
@ 2020-11-25 17:19   ` Gabriel do Nascimento Ribeiro
  2020-11-25 19:22     ` Juri Linkov
  2021-02-27 20:12     ` Juri Linkov
  0 siblings, 2 replies; 9+ messages in thread
From: Gabriel do Nascimento Ribeiro @ 2020-11-25 17:19 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> Some little ideas on how Tab Bar can be further improved:
>
> Thanks for the ideas.
>
>> 1. Options to disable `tab-bar-back-button' and
>> `tab-bar-forward-button' when `tab-bar-history-mode' is on.  This will
>> be similar to what option `tab-bar-close-button-show' is to
>> `tab-bar-close-button'.
>
> The most difficult part is to choose a good option name.
> Maybe, `tab-bar-history-buttons-show' is not too bad.
>

I would suggest `tab-bar-back-button-show'and `tab-bar-forward-button-show'.

>> 2. Trim spaces of tab bar name. The tab bar name can have additional spaces on the right:
>>     2.1. When tab bar name name is set explicitly with `tab-bar-rename-tab';
>>     2.2. When `tab-bar-tab-hints' is true and `tab-bar-tab-name-function' returns an empty string;
>
> Sorry, I don't understand what is the problem.
> When the user intentionally adds spaces in case 2.1.,
> then why there is a need to trim spaces?
>

Yes, if the user intentionally adds space and wants this behavior, that's
okay. But if he wants the trim function or any other custom formatting, it's not
possible.

Another scenario is 2.2, where `tab-bar-tab-hints' is true and
`tab-bar-tab-name-function' returns an empty string. In this cases, tabs will be
named with a trim space on the right as follow: "1 ", "2 ", "3 " etc and it's
not possible to format the names (unless using some `defadvice´ on
`tab-bar-make-keymap-1' is used to manually modify the output list of menu
items). I ran into this problem when trying to mimic how some window managers
works by default like DWM or i3, where worspaces are named with numbers only.

I think that having some option here to better control how tab names are
displayed would be helpful and the implementation is not hard. We can add a new
boolean option to trim tab names or add a new option where the user can specify
a custom function to be run to format the final tab name string. There are more
alternatives but these two are the simplest, I guess.


>> 3. An easier way to add more items to Tab Bar to make it act more like
>> a general Bar.  The following example was shared in Emacs Devel
>> mailing list on how to add a simple clock to the right of Tab Bar:
>> =========================================
>>   (advice-add 'tab-bar-make-keymap-1 :around
>>               (lambda (orig-fun)
>>                 (append (funcall orig-fun)
>>                         `((display-time menu-item
>>                                         ,(concat
>>                                           (propertize " " 'display '(space :align-to (- right 5)))
>>                                           (format-time-string "%H:%M"))
>>                                         ignore))))
>>               '((name . tab-bar-display-time)))
>> =========================================
>
> Do you propose to add functions that would allow doing this more easily?
> Maybe using some hooks?
>

I didn't think in any implementation, actually. But I could see the potential of
the Tab Bar towards a more general Bar and that many users would like a better
control on what is displayed there, like adding custom texts or buttons. I ran
into this idea by reading some threads here in emacs-devel. I know `mode-line'
is super customizable and a there is `header-line' also, but that means having
additional bars on the screen.

>> 4. Maybe deprecate `winner-mode' in favor to `tab-bar-history-mode',
>> since these two modes have similar functions.
>> Using `tab-bar-history-mode' with only one Tab is like using
>> `winner-mode'.
>
> `winner-mode' should not be deprecated because it's still useful
> for users who don't use tabs with `tab-bar-mode'.  So `winner-mode'
> works fine when tabs are not used.  OTOH, `winner-mode' breaks tabs
> when used with `tab-bar-mode', so `tab-bar-history-mode' is needed
> to do the same when tabs are used.

That's my point. We have two similar modes to handle window configuration
history which works on specific cases. That means having more code on Emacs,
more documentation, more configuration on init files, more keybindings, more
stuff to learn, more confusion etc. That would be great if we could have a
single way to work with window configuration history in all cases. Not using
tabs is similar to using only one tab, where tab-bar visibility can be
configured with `tab-bar-show' set to nil or 1.

Regards,
Gabriel



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-25 17:19   ` Gabriel do Nascimento Ribeiro
@ 2020-11-25 19:22     ` Juri Linkov
  2021-02-27 20:12     ` Juri Linkov
  1 sibling, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2020-11-25 19:22 UTC (permalink / raw)
  To: Gabriel do Nascimento Ribeiro; +Cc: emacs-devel

>> The most difficult part is to choose a good option name.
>> Maybe, `tab-bar-history-buttons-show' is not too bad.
>
> I would suggest `tab-bar-back-button-show'and `tab-bar-forward-button-show'.

This is fine since it's based on existing variable names.

>> Sorry, I don't understand what is the problem.
>> When the user intentionally adds spaces in case 2.1.,
>> then why there is a need to trim spaces?
>
> Yes, if the user intentionally adds space and wants this behavior, that's
> okay. But if he wants the trim function or any other custom formatting, it's not
> possible.
>
> Another scenario is 2.2, where `tab-bar-tab-hints' is true and
> `tab-bar-tab-name-function' returns an empty string. In this cases, tabs will be
> named with a trim space on the right as follow: "1 ", "2 ", "3 " etc and it's
> not possible to format the names (unless using some `defadvice´ on
> `tab-bar-make-keymap-1' is used to manually modify the output list of menu
> items). I ran into this problem when trying to mimic how some window managers
> works by default like DWM or i3, where worspaces are named with numbers only.
>
> I think that having some option here to better control how tab names are
> displayed would be helpful and the implementation is not hard. We can add a new
> boolean option to trim tab names or add a new option where the user can specify
> a custom function to be run to format the final tab name string. There are more
> alternatives but these two are the simplest, I guess.

A new boolean option would be too ad-hoc.  OTOH, a custom function to format
the final tab bar would be more preferable.  Maybe the same custom function
could be used to add more items like adding custom texts or buttons below:

>> Do you propose to add functions that would allow doing this more easily?
>> Maybe using some hooks?
>
> I didn't think in any implementation, actually. But I could see the potential of
> the Tab Bar towards a more general Bar and that many users would like a better
> control on what is displayed there, like adding custom texts or buttons. I ran
> into this idea by reading some threads here in emacs-devel. I know `mode-line'
> is super customizable and a there is `header-line' also, but that means having
> additional bars on the screen.

Mode line constructs can be used to format tab-line, e.g.:

  (global-tab-line-mode)
  (setq tab-line-format '(:eval mode-line-format))

but not tab-bar.  tab-bar needs a completely separate solution.

>> `winner-mode' should not be deprecated because it's still useful
>> for users who don't use tabs with `tab-bar-mode'.  So `winner-mode'
>> works fine when tabs are not used.  OTOH, `winner-mode' breaks tabs
>> when used with `tab-bar-mode', so `tab-bar-history-mode' is needed
>> to do the same when tabs are used.
>
> That's my point. We have two similar modes to handle window configuration
> history which works on specific cases. That means having more code on Emacs,
> more documentation, more configuration on init files, more keybindings, more
> stuff to learn, more confusion etc. That would be great if we could have a
> single way to work with window configuration history in all cases. Not using
> tabs is similar to using only one tab, where tab-bar visibility can be
> configured with `tab-bar-show' set to nil or 1.

I don't know, we need to ask the users of winner-mode whether they
can lose something after doing

 (defalias 'winner-mode 'tab-bar-history-mode)
 (defalias 'winner-undo 'tab-bar-history-back)
 (defalias 'winner-redo 'tab-bar-history-forward)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-25  0:35 Some ideas to improve Tab Bar Gabriel do Nascimento Ribeiro
  2020-11-25  7:47 ` Juri Linkov
@ 2020-11-26 23:08 ` Gabriel do Nascimento Ribeiro
  2020-11-27  8:22   ` Juri Linkov
  1 sibling, 1 reply; 9+ messages in thread
From: Gabriel do Nascimento Ribeiro @ 2020-11-26 23:08 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

Gabriel do Nascimento Ribeiro <gabriel376@hotmail.com> writes:

> Some little ideas on how Tab Bar can be further improved:
>
> 1. Options to disable `tab-bar-back-button' and `tab-bar-forward-button' when `tab-bar-history-mode' is on. This will be similar to what option `tab-bar-close-button-show' is to `tab-bar-close-button'.

The idea of this patch is to add a new option called
`tab-bar-history-buttons-show' to control the visibility of
`tab-bar-history-mode' back and forward buttons.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch to add option to control visibility of tab-bar-history buttons --]
[-- Type: text/x-diff, Size: 1142 bytes --]

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 2604955224..05611b48bb 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -296,6 +296,16 @@ tab-bar-back-button
 (defvar tab-bar-forward-button " > "
   "Button for going forward in tab history.")
 
+(defcustom tab-bar-history-buttons-show t
+  "Show back and forward buttons when `tab-bar-history-mode' is enabled."
+  :type 'boolean
+  :initialize 'custom-initialize-default
+  :set (lambda (sym val)
+         (set-default sym val)
+         (force-mode-line-update))
+  :group 'tab-bar
+  :version "28.1")
+
 (defcustom tab-bar-tab-hints nil
   "Show absolute numbers on tabs in the tab bar before the tab name.
 This helps to select the tab by its number using `tab-bar-select-tab'
@@ -415,7 +425,7 @@ tab-bar-make-keymap-1
          (tabs (funcall tab-bar-tabs-function)))
     (append
      '(keymap (mouse-1 . tab-bar-handle-mouse))
-     (when tab-bar-history-mode
+     (when (and tab-bar-history-mode tab-bar-history-buttons-show)
        `((sep-history-back menu-item ,separator ignore)
          (history-back
           menu-item ,tab-bar-back-button tab-bar-history-back

[-- Attachment #3: Type: text/plain, Size: 448 bytes --]


> 2. Trim spaces of tab bar name. The tab bar name can have additional spaces on the right:
>     2.1. When tab bar name name is set explicitly with `tab-bar-rename-tab';
>     2.2. When `tab-bar-tab-hints' is true and `tab-bar-tab-name-function' returns an empty string;
>

The idea of this patch is to add a new option called
`tab-bar-tab-name-format-function' where a custom function can be
specified to format the string value of `tab-name'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Patch to add option to specify custom function to format tab name --]
[-- Type: text/x-diff, Size: 2247 bytes --]

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 2604955224..82f3ca2385 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -334,6 +334,18 @@ tab-bar-tab-name-function
   :group 'tab-bar
   :version "27.1")
 
+(defcustom tab-bar-tab-name-format-function nil
+  "Function to format a tab name.
+Function get one argument, the tab name, and should return
+the formatted tab name."
+  :type 'function
+  :initialize 'custom-initialize-default
+  :set (lambda (sym val)
+         (set-default sym val)
+         (force-mode-line-update))
+  :group 'tab-bar
+  :version "28.1")
+
 (defun tab-bar-tab-name-current ()
   "Generate tab name from the buffer of the selected window."
   (buffer-name (window-buffer (minibuffer-selected-window))))
@@ -433,8 +445,9 @@ tab-bar-make-keymap-1
           ((eq (car tab) 'current-tab)
            `((current-tab
               menu-item
-              ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "")
-                                   (alist-get 'name tab)
+              ,(propertize (concat (funcall (or tab-bar-tab-name-format-function 'identity)
+                                            (concat (if tab-bar-tab-hints (format "%d " i) "")
+                                                    (alist-get 'name tab)))
                                    (or (and tab-bar-close-button-show
                                             (not (eq tab-bar-close-button-show
                                                      'non-selected))
@@ -445,8 +458,9 @@ tab-bar-make-keymap-1
           (t
            `((,(intern (format "tab-%i" i))
               menu-item
-              ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "")
-                                   (alist-get 'name tab)
+              ,(propertize (concat (funcall (or tab-bar-tab-name-format-function 'identity)
+                                            (concat (if tab-bar-tab-hints (format "%d " i) "")
+                                                    (alist-get 'name tab)))
                                    (or (and tab-bar-close-button-show
                                             (not (eq tab-bar-close-button-show
                                                      'selected))

[-- Attachment #5: Type: text/plain, Size: 18 bytes --]


Regards,
Gabriel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-26 23:08 ` Gabriel do Nascimento Ribeiro
@ 2020-11-27  8:22   ` Juri Linkov
  0 siblings, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2020-11-27  8:22 UTC (permalink / raw)
  To: Gabriel do Nascimento Ribeiro; +Cc: emacs-devel

> The idea of this patch is to add a new option called
> `tab-bar-history-buttons-show' to control the visibility of
> `tab-bar-history-mode' back and forward buttons.

Thanks, both patches look good.

> The idea of this patch is to add a new option called
> `tab-bar-tab-name-format-function' where a custom function can be
> specified to format the string value of `tab-name'.
>
> +(defcustom tab-bar-tab-name-format-function nil
...
> +  :type 'function
...
> +              ,(propertize (concat (funcall (or tab-bar-tab-name-format-function 'identity)

Since you use 'funcall' anyway, and defcustom's :type is 'function',
you can just set 'identity' as the default value:

  (defcustom tab-bar-tab-name-format-function 'identity
and
  ,(propertize (concat (funcall tab-bar-tab-name-format-function



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2020-11-25 17:19   ` Gabriel do Nascimento Ribeiro
  2020-11-25 19:22     ` Juri Linkov
@ 2021-02-27 20:12     ` Juri Linkov
  2021-03-01 23:15       ` Gabriel do Nascimento Ribeiro
  1 sibling, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2021-02-27 20:12 UTC (permalink / raw)
  To: Gabriel do Nascimento Ribeiro; +Cc: emacs-devel

>>> 3. An easier way to add more items to Tab Bar to make it act more like
>>> a general Bar.  The following example was shared in Emacs Devel
>>> mailing list on how to add a simple clock to the right of Tab Bar:
>>> =========================================
>>>   (advice-add 'tab-bar-make-keymap-1 :around
>>>               (lambda (orig-fun)
>>>                 (append (funcall orig-fun)
>>>                         `((display-time menu-item
>>>                                         ,(concat
>>>                                           (propertize " " 'display '(space :align-to (- right 5)))
>>>                                           (format-time-string "%H:%M"))
>>>                                         ignore))))
>>>               '((name . tab-bar-display-time)))
>>> =========================================
>>
>> Do you propose to add functions that would allow doing this more easily?
>> Maybe using some hooks?
>
> I didn't think in any implementation, actually. But I could see the potential of
> the Tab Bar towards a more general Bar and that many users would like a better
> control on what is displayed there, like adding custom texts or buttons. I ran
> into this idea by reading some threads here in emacs-devel. I know `mode-line'
> is super customizable and a there is `header-line' also, but that means having
> additional bars on the screen.

This thread was in
https://lists.gnu.org/archive/html/emacs-devel/2019-10/msg00672.html

And indeed, when display-time-mode or display-battery-mode is enabled,
it duplicates information about battery status or time in every mode line
of every window.

Instead of duplicating the same information in every mode line of every window,
now tab-bar-mode has a new variable tab-bar-format.  A new element
tab-bar-format-global can be added to its list.  In this case,
when `display-time-mode' is enabled and automatically updates the time string
every minute using a timer, it updates time on the tab bar,
without duplicating it in every mode line.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2021-02-27 20:12     ` Juri Linkov
@ 2021-03-01 23:15       ` Gabriel do Nascimento Ribeiro
  2021-03-02 19:46         ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Gabriel do Nascimento Ribeiro @ 2021-03-01 23:15 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

> This thread was in
> https://lists.gnu.org/archive/html/emacs-devel/2019-10/msg00672.html
>
> And indeed, when display-time-mode or display-battery-mode is enabled,
> it duplicates information about battery status or time in every mode line
> of every window.
>
> Instead of duplicating the same information in every mode line of every window,
> now tab-bar-mode has a new variable tab-bar-format.  A new element
> tab-bar-format-global can be added to its list.  In this case,
> when `display-time-mode' is enabled and automatically updates the time string
> every minute using a timer, it updates time on the tab bar,
> without duplicating it in every mode line.

Really nice! Thank you!

Do you happen to have some snippet demonstrating the use of the newly
added tab-bar variables/functions ?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Some ideas to improve Tab Bar
  2021-03-01 23:15       ` Gabriel do Nascimento Ribeiro
@ 2021-03-02 19:46         ` Juri Linkov
  0 siblings, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2021-03-02 19:46 UTC (permalink / raw)
  To: Gabriel do Nascimento Ribeiro; +Cc: emacs-devel

>> Instead of duplicating the same information in every mode line of every window,
>> now tab-bar-mode has a new variable tab-bar-format.  A new element
>> tab-bar-format-global can be added to its list.  In this case,
>> when `display-time-mode' is enabled and automatically updates the time string
>> every minute using a timer, it updates time on the tab bar,
>> without duplicating it in every mode line.
>
> Really nice! Thank you!
>
> Do you happen to have some snippet demonstrating the use of the newly
> added tab-bar variables/functions ?

Just add something like this to the init file:

(display-time-mode)
(setq tab-bar-format '(tab-bar-format-history
                       tab-bar-format-tabs
                       tab-bar-format-align-right
                       tab-bar-format-global))



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-02 19:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  0:35 Some ideas to improve Tab Bar Gabriel do Nascimento Ribeiro
2020-11-25  7:47 ` Juri Linkov
2020-11-25 17:19   ` Gabriel do Nascimento Ribeiro
2020-11-25 19:22     ` Juri Linkov
2021-02-27 20:12     ` Juri Linkov
2021-03-01 23:15       ` Gabriel do Nascimento Ribeiro
2021-03-02 19:46         ` Juri Linkov
2020-11-26 23:08 ` Gabriel do Nascimento Ribeiro
2020-11-27  8:22   ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).