unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66464: Vc mode-line
@ 2023-10-11 16:29 Juri Linkov
  2023-10-16  1:11 ` Dmitry Gutov
  2023-10-31  7:40 ` Juri Linkov
  0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2023-10-11 16:29 UTC (permalink / raw)
  To: 66464

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

In order to prepare for making the vc mode-line more customizable,
here is refactoring that helps to avoid code duplication in
vc-hg-mode-line-string, and at the same time makes
vc-git-mode-line-string less hackish while keeping it short.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-mode-line-string.patch --]
[-- Type: text/x-diff, Size: 8104 bytes --]

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 5c21a5b884e..80c79db93ca 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -416,15 +416,22 @@ vc-git--symbolic-ref
 
 (defun vc-git-mode-line-string (file)
   "Return a string for `vc-mode-line' to put in the mode line for FILE."
-  (let* ((rev (vc-working-revision file 'Git))
+  (let* ((backend-name "Git")
+         (state (vc-state file))
+         (status (vc-mode-line-status state))
+         (state-echo (nth 0 status))
+         (face (nth 1 status))
+         (indicator (nth 2 status))
+         (rev (vc-working-revision file 'Git))
          (disp-rev (or (vc-git--symbolic-ref file)
                        (and rev (substring rev 0 7))))
-         (def-ml (vc-default-mode-line-string 'Git file))
-         (help-echo (get-text-property 0 'help-echo def-ml))
-         (face   (get-text-property 0 'face def-ml)))
-    (propertize (concat (substring def-ml 0 4) disp-rev)
-                'face face
-                'help-echo (concat help-echo "\nCurrent revision: " rev))))
+         (state-string (concat backend-name indicator disp-rev)))
+    (propertize
+     state-string
+     'face face
+     'help-echo (concat state-echo " under the " backend-name
+                        " version control system"
+                        "\nCurrent revision: " rev))))
 
 (cl-defstruct (vc-git-extra-fileinfo
             (:copier nil)
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index c3e563a1f10..a749a4b02f7 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -354,8 +354,10 @@ vc-hg-mode-line-string
   (let* ((backend-name "Hg")
          (truename (file-truename file))
          (state (vc-state truename))
-         (state-echo nil)
-         (face nil)
+         (status (vc-mode-line-status state))
+         (state-echo (nth 0 status))
+         (face (nth 1 status))
+         (indicator (nth 2 status))
          (rev (and state
                    (let ((default-directory
                           (expand-file-name (vc-hg-root truename))))
@@ -363,33 +365,10 @@ vc-hg-mode-line-string
                       "."
                       (and vc-hg-use-file-version-for-mode-line-version
                            truename)))))
-         (rev (or rev "???")))
+         (rev (or rev "???"))
+         (state-string (concat backend-name indicator rev)))
     (propertize
-     (cond ((or (eq state 'up-to-date)
-                (eq state 'needs-update))
-            (setq state-echo "Up to date file")
-            (setq face 'vc-up-to-date-state)
-            (concat backend-name "-" rev))
-           ((eq state 'added)
-            (setq state-echo "Locally added file")
-            (setq face 'vc-locally-added-state)
-            (concat backend-name "@" rev))
-           ((eq state 'conflict)
-            (setq state-echo "File contains conflicts after the last merge")
-            (setq face 'vc-conflict-state)
-            (concat backend-name "!" rev))
-           ((eq state 'removed)
-            (setq state-echo "File removed from the VC system")
-            (setq face 'vc-removed-state)
-            (concat backend-name "!" rev))
-           ((eq state 'missing)
-            (setq state-echo "File tracked by the VC system, but missing from the file system")
-            (setq face 'vc-missing-state)
-            (concat backend-name "?" rev))
-           (t
-            (setq state-echo "Locally modified file")
-            (setq face 'vc-edited-state)
-            (concat backend-name ":" rev)))
+     state-string
      'face face
      'help-echo (concat state-echo " under the " backend-name
                         " version control system"))))
diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index a4de0a6e791..94c3682b4aa 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -705,6 +733,46 @@ vc-mode-line
   (force-mode-line-update)
   backend)
 
+(defun vc-mode-line-status (state)
+  (let (state-echo face indicator)
+    (cond ((or (eq state 'up-to-date)
+               (eq state 'needs-update))
+           (setq state-echo "Up to date file")
+           (setq face 'vc-up-to-date-state)
+           (setq indicator "-"))
+          ((stringp state)
+           (setq state-echo (concat "File locked by" state))
+           (setq face 'vc-locked-state)
+           (setq indicator (concat ":" state ":")))
+          ((eq state 'added)
+           (setq state-echo "Locally added file")
+           (setq face 'vc-locally-added-state)
+           (setq indicator "@"))
+          ((eq state 'conflict)
+           (setq state-echo "File contains conflicts after the last merge")
+           (setq face 'vc-conflict-state)
+           (setq indicator "!"))
+          ((eq state 'removed)
+           (setq state-echo "File removed from the VC system")
+           (setq face 'vc-removed-state)
+           (setq indicator "!"))
+          ((eq state 'missing)
+           (setq state-echo "File tracked by the VC system, but missing from the file system")
+           (setq face 'vc-missing-state)
+           (setq indicator "?"))
+          ((eq state 'ignored)
+           (setq state-echo "File tracked by the VC system, but ignored")
+           (setq face 'vc-ignored-state)
+           (setq indicator "!"))
+          (t
+           ;; Not just for the 'edited state, but also a fallback
+           ;; for all other states.  Think about different symbols
+           ;; for 'needs-update and 'needs-merge.
+           (setq state-echo "Locally modified file")
+           (setq face 'vc-edited-state)
+           (setq indicator ":")))
+    (list state-echo face indicator)))
+
 (defun vc-default-mode-line-string (backend file)
   "Return a string for `vc-mode-line' to put in the mode line for FILE.
 Format:
@@ -718,47 +786,15 @@ vc-default-mode-line-string
 
 This function assumes that the file is registered."
   (let* ((backend-name (symbol-name backend))
-	 (state   (vc-state file backend))
-	 (state-echo nil)
-	 (face nil)
-	 (rev     (vc-working-revision file backend)))
+         (state (vc-state file backend))
+         (rev (vc-working-revision file backend))
+         (status (vc-mode-line-status state))
+         (state-echo (nth 0 status))
+         (face (nth 1 status))
+         (indicator (nth 2 status))
+         (state-string (concat backend-name indicator rev)))
     (propertize
-     (cond ((or (eq state 'up-to-date)
-		(eq state 'needs-update))
-	    (setq state-echo "Up to date file")
-	    (setq face 'vc-up-to-date-state)
-	    (concat backend-name "-" rev))
-	   ((stringp state)
-	    (setq state-echo (concat "File locked by" state))
-	    (setq face 'vc-locked-state)
-	    (concat backend-name ":" state ":" rev))
-           ((eq state 'added)
-            (setq state-echo "Locally added file")
-	    (setq face 'vc-locally-added-state)
-            (concat backend-name "@" rev))
-           ((eq state 'conflict)
-            (setq state-echo "File contains conflicts after the last merge")
-	    (setq face 'vc-conflict-state)
-            (concat backend-name "!" rev))
-           ((eq state 'removed)
-            (setq state-echo "File removed from the VC system")
-	    (setq face 'vc-removed-state)
-            (concat backend-name "!" rev))
-           ((eq state 'missing)
-            (setq state-echo "File tracked by the VC system, but missing from the file system")
-	    (setq face 'vc-missing-state)
-            (concat backend-name "?" rev))
-           ((eq state 'ignored)
-            (setq state-echo "File tracked by the VC system, but ignored")
-            (setq face 'vc-ignored-state)
-            (concat backend-name "!" rev))
-	   (t
-	    ;; Not just for the 'edited state, but also a fallback
-	    ;; for all other states.  Think about different symbols
-	    ;; for 'needs-update and 'needs-merge.
-	    (setq state-echo "Locally modified file")
-	    (setq face 'vc-edited-state)
-	    (concat backend-name ":" rev)))
+     state-string
      'face face
      'help-echo (concat state-echo " under the " backend-name
 			" version control system"))))

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

* bug#66464: Vc mode-line
  2023-10-11 16:29 bug#66464: Vc mode-line Juri Linkov
@ 2023-10-16  1:11 ` Dmitry Gutov
  2023-10-16 17:14   ` Juri Linkov
  2023-10-31  7:40 ` Juri Linkov
  1 sibling, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-10-16  1:11 UTC (permalink / raw)
  To: Juri Linkov, 66464

On 11/10/2023 19:29, Juri Linkov wrote:
> In order to prepare for making the vc mode-line more customizable,
> here is refactoring that helps to avoid code duplication in
> vc-hg-mode-line-string, and at the same time makes
> vc-git-mode-line-string less hackish while keeping it short.

LGTM, thanks!





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

* bug#66464: Vc mode-line
  2023-10-16  1:11 ` Dmitry Gutov
@ 2023-10-16 17:14   ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2023-10-16 17:14 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66464

>> In order to prepare for making the vc mode-line more customizable,
>> here is refactoring that helps to avoid code duplication in
>> vc-hg-mode-line-string, and at the same time makes
>> vc-git-mode-line-string less hackish while keeping it short.
>
> LGTM, thanks!

Ok, now pushed to master.





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

* bug#66464: Vc mode-line
  2023-10-11 16:29 bug#66464: Vc mode-line Juri Linkov
  2023-10-16  1:11 ` Dmitry Gutov
@ 2023-10-31  7:40 ` Juri Linkov
  2023-11-09 16:41   ` Juri Linkov
  1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-10-31  7:40 UTC (permalink / raw)
  To: 66464

close 66464 30.0.50
stop

> In order to prepare for making the vc mode-line more customizable,
> here is refactoring that helps to avoid code duplication in
> vc-hg-mode-line-string, and at the same time makes
> vc-git-mode-line-string less hackish while keeping it short.

After more thinking I see no way to join project and vc
indicators on the mode line, so I'm closing this feature request.





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

* bug#66464: Vc mode-line
  2023-10-31  7:40 ` Juri Linkov
@ 2023-11-09 16:41   ` Juri Linkov
  2023-11-10  2:04     ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-11-09 16:41 UTC (permalink / raw)
  To: 66464

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

reopen 66464
thanks

>> In order to prepare for making the vc mode-line more customizable,
>> here is refactoring that helps to avoid code duplication in
>> vc-hg-mode-line-string, and at the same time makes
>> vc-git-mode-line-string less hackish while keeping it short.
>
> After more thinking I see no way to join project and vc
> indicators on the mode line, so I'm closing this feature request.

It would be a pity not to add this handy feature.
So here is a small patch that joins the project name and vc status
on the mode line:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-display-status-with-project.patch --]
[-- Type: text/x-diff, Size: 1763 bytes --]

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index c16fb63b2ff..63d7036f299 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -153,7 +153,9 @@ vc-follow-symlinks
 (defcustom vc-display-status t
   "If non-nil, display revision number and lock status in mode line.
 Otherwise, not displayed."
-  :type 'boolean
+  :type '(choice (const :tag "Show project name and status" with-project)
+                 (const :tag "Show backend and status" t)
+                 (const :tag "Show only backend name" nil))
   :group 'vc)
 
 
@@ -683,7 +685,9 @@ vc-mode-line
 	   (ml-echo (get-text-property 0 'help-echo ml-string)))
       (setq vc-mode
 	    (concat
-	     " "
+	     (unless (and (eq vc-display-status 'with-project)
+			  (bound-and-true-p project-mode-line))
+	       " ")
 	     (propertize
 	      ml-string
 	      'mouse-face 'mode-line-highlight
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 707fc7cfc07..0313f6ec827 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -423,7 +423,10 @@ vc-git-mode-line-string
                (rev (vc-working-revision file 'Git))
                (disp-rev (or (vc-git--symbolic-ref file)
                              (and rev (substring rev 0 7))))
-               (state-string (concat backend-name indicator disp-rev)))
+               (state-string (concat (unless (and (eq vc-display-status 'with-project)
+                                                  (bound-and-true-p project-mode-line))
+                                       backend-name)
+                                     indicator disp-rev)))
     (propertize state-string 'face face 'help-echo
                 (concat state-echo " under the " backend-name
                         " version control system"

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

* bug#66464: Vc mode-line
  2023-11-09 16:41   ` Juri Linkov
@ 2023-11-10  2:04     ` Dmitry Gutov
  2023-11-10  7:33       ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-11-10  2:04 UTC (permalink / raw)
  To: Juri Linkov, 66464

On 09/11/2023 18:41, Juri Linkov wrote:
> It would be a pity not to add this handy feature.
> So here is a small patch that joins the project name and vc status
> on the mode line:

Could you described the intended look?

Two mode-line entries one right by another, without a space between?

And with the backend name removed? Wouldn't you say we're losing some 
useful information this way? Or perhaps the backend name is not essential.

In any case, it seems like

   (const :tag "Show project name and status" with-project)

describes the option inaccurately, since VC's mode line doesn't show the 
project name. And if you customize 'vc-display-status' to 'with-project' 
but don't set project-mode-line to t, the project name won't be shown at 
all.





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

* bug#66464: Vc mode-line
  2023-11-10  2:04     ` Dmitry Gutov
@ 2023-11-10  7:33       ` Juri Linkov
  2023-11-10 23:54         ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-11-10  7:33 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66464

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

>> It would be a pity not to add this handy feature.
>> So here is a small patch that joins the project name and vc status
>> on the mode line:
>
> Could you described the intended look?

Here is the screenshot how the mode line looks like:


[-- Attachment #2: project_branch.png --]
[-- Type: image/png, Size: 30946 bytes --]

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


> Two mode-line entries one right by another, without a space between?

The format is "project-branch" instead of "backend-branch".

> And with the backend name removed? Wouldn't you say we're losing some
> useful information this way? Or perhaps the backend name is not essential.

I'm sure that showing the backend name in all file buffers is useless
for most users and wastes the precious screen space.

But I don't propose to change the default.

> In any case, it seems like
>
>   (const :tag "Show project name and status" with-project)
>
> describes the option inaccurately, since VC's mode line doesn't show the
> project name.

Technically it's not vc-mode that shows the project name indeed.
I already tried such things as calling '(project-mode-line-format)'
from 'vc-mode-line-string'.  But it's an unnecessary complication.

> And if you customize 'vc-display-status' to 'with-project' but don't
> set project-mode-line to t, the project name won't be shown at all.

This is why the condition already handles this case:

  (and (eq vc-display-status 'with-project)
       (bound-and-true-p project-mode-line))

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

* bug#66464: Vc mode-line
  2023-11-10  7:33       ` Juri Linkov
@ 2023-11-10 23:54         ` Dmitry Gutov
  2023-11-11 18:50           ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-11-10 23:54 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 66464

On 10/11/2023 09:33, Juri Linkov wrote:
>>> It would be a pity not to add this handy feature.
>>> So here is a small patch that joins the project name and vc status
>>> on the mode line:
>>
>> Could you described the intended look?
> 
> Here is the screenshot how the mode line looks like:

Thanks.

>> Two mode-line entries one right by another, without a space between?
> 
> The format is "project-branch" instead of "backend-branch".

It might also be misread as a directory name. E.g. I have directories 
called "emacs" and "emacs-master" (thanks to git-worktree), and they get 
automatically assigned the corresponding project names. The new 
mode-line with your customization looks like "emacs-master-master". But 
that could just be my problem.

>> And with the backend name removed? Wouldn't you say we're losing some
>> useful information this way? Or perhaps the backend name is not essential.
> 
> I'm sure that showing the backend name in all file buffers is useless
> for most users and wastes the precious screen space.

Hmm, I suppose since we're in a situation where one VCS (Git) is used 
99% of the time, the indication might be unnecessary. But it's also a 
reminder that this mode-line item is for VC. Anyway...

> But I don't propose to change the default.
> 
>> In any case, it seems like
>>
>>    (const :tag "Show project name and status" with-project)
>>
>> describes the option inaccurately, since VC's mode line doesn't show the
>> project name.
> 
> Technically it's not vc-mode that shows the project name indeed.
> I already tried such things as calling '(project-mode-line-format)'
> from 'vc-mode-line-string'.  But it's an unnecessary complication.

That's probably an overkill indeed, also because the user would have to 
customize project-mode-line to nil, and then some projects might not be 
VC-controlled, which would result in no mode-line element at all.

>> And if you customize 'vc-display-status' to 'with-project' but don't
>> set project-mode-line to t, the project name won't be shown at all.
> 
> This is why the condition already handles this case:
> 
>    (and (eq vc-display-status 'with-project)
>         (bound-and-true-p project-mode-line))

What happens if mode-line-format doesn't contain 
project-mode-line-format, or has it in the wrong place? E.g. if the user 
(or third-party package) customized the mode-line.

It's probably not terrible not to support that (after all, that would be 
a combination of two non-default customizations).

Anyway, I've raised the questions, but I don't have strong objections to 
your patch. Perhaps consider changing the description from

   (const :tag "Show project name and status" with-project)

to

   (const :tag "Show only status next to project name" with-project)

and, maybe, check that project-mode-line-format precedes the vc-mode 
indicator in the current mode-line format. And otherwise keep the 
separating " ". If that makes sense to you.





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

* bug#66464: Vc mode-line
  2023-11-10 23:54         ` Dmitry Gutov
@ 2023-11-11 18:50           ` Juri Linkov
  2023-11-11 22:05             ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-11-11 18:50 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66464

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

>> The format is "project-branch" instead of "backend-branch".
>
> It might also be misread as a directory name. E.g. I have directories
> called "emacs" and "emacs-master" (thanks to git-worktree), and they get
> automatically assigned the corresponding project names. The new mode-line
> with your customization looks like "emacs-master-master". But that could
> just be my problem.

I had the same problem even after enabling project-mode-line,
so needed to remove the branch name from project names.

>> I'm sure that showing the backend name in all file buffers is useless
>> for most users and wastes the precious screen space.
>
> Hmm, I suppose since we're in a situation where one VCS (Git) is used 99%
> of the time, the indication might be unnecessary. But it's also a reminder
> that this mode-line item is for VC. Anyway...

The problem is that the useless word "Git" (with big G)
between the project name and the branch name is a big distraction.

>>> And if you customize 'vc-display-status' to 'with-project' but don't
>>> set project-mode-line to t, the project name won't be shown at all.
>> This is why the condition already handles this case:
>>    (and (eq vc-display-status 'with-project)
>>         (bound-and-true-p project-mode-line))
>
> What happens if mode-line-format doesn't contain project-mode-line-format,
> or has it in the wrong place? E.g. if the user (or third-party package)
> customized the mode-line.

Indeed, for such cases this option can't be used.  I believe we should
better document such situation in the docstring.

> Anyway, I've raised the questions, but I don't have strong objections to
> your patch. Perhaps consider changing the description from
>
>   (const :tag "Show project name and status" with-project)
>
> to
>
>   (const :tag "Show only status next to project name" with-project)

Currently the options are aligned and provide a nice review
what the user will see on the mode line:

 :type '(choice (const :tag "Show project name and status" with-project)
                (const :tag "Show backend and status" t)
                (const :tag "Show only backend name" nil))

So I'd rather like to describe more details in the docstring.

> and, maybe, check that project-mode-line-format precedes the vc-mode
> indicator in the current mode-line format. And otherwise keep the
> separating " ". If that makes sense to you.

Probably it should be sufficient to describe this in the docstring
like in this patch?

PS: Probably we could also add another option `no-backend'
that will show only an indicator and the branch name.
But the dangling indicator such as "-" or "*" before the branch name
doesn't look nice when there is a space that separates it
from the project name, e.g. "project -branch".


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-display-status-with-project.patch --]
[-- Type: text/x-diff, Size: 2099 bytes --]

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index c16fb63b2ff..6e4be6414d2 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -152,8 +152,15 @@ vc-follow-symlinks
 
 (defcustom vc-display-status t
   "If non-nil, display revision number and lock status in mode line.
-Otherwise, not displayed."
-  :type 'boolean
+If nil, it's not displayed.
+When the value is `with-project' then instead of the backend name
+a project name can be displayed before the revision number and lock
+status.  This works only in case when you enable `project-mode-line'
+and don't change the default order of `project-mode-line' and
+`vc-mode' in `mode-line-format'."
+  :type '(choice (const :tag "Show project name and status" with-project)
+                 (const :tag "Show backend and status" t)
+                 (const :tag "Show only backend name" nil))
   :group 'vc)
 
 
@@ -683,7 +690,9 @@ vc-mode-line
 	   (ml-echo (get-text-property 0 'help-echo ml-string)))
       (setq vc-mode
 	    (concat
-	     " "
+	     (unless (and (eq vc-display-status 'with-project)
+			  (bound-and-true-p project-mode-line))
+	       " ")
 	     (propertize
 	      ml-string
 	      'mouse-face 'mode-line-highlight
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 707fc7cfc07..0313f6ec827 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -423,7 +423,10 @@ vc-git-mode-line-string
                (rev (vc-working-revision file 'Git))
                (disp-rev (or (vc-git--symbolic-ref file)
                              (and rev (substring rev 0 7))))
-               (state-string (concat backend-name indicator disp-rev)))
+               (state-string (concat (unless (and (eq vc-display-status 'with-project)
+                                                  (bound-and-true-p project-mode-line))
+                                       backend-name)
+                                     indicator disp-rev)))
     (propertize state-string 'face face 'help-echo
                 (concat state-echo " under the " backend-name
                         " version control system"

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

* bug#66464: Vc mode-line
  2023-11-11 18:50           ` Juri Linkov
@ 2023-11-11 22:05             ` Dmitry Gutov
  2023-11-12  8:07               ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-11-11 22:05 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 66464

On 11/11/2023 20:50, Juri Linkov wrote:
> Currently the options are aligned and provide a nice review
> what the user will see on the mode line:
> 
>   :type '(choice (const :tag "Show project name and status" with-project)
>                  (const :tag "Show backend and status" t)
>                  (const :tag "Show only backend name" nil))
> 
> So I'd rather like to describe more details in the docstring.

I don't like the semantics of this sentence (it implies that VC's mode 
line item will show the project name but it doesn't), but I'm not going 
to argue more.

> Probably it should be sufficient to describe this in the docstring
> like in this patch?

It's good, thank you.

> PS: Probably we could also add another option `no-backend'
> that will show only an indicator and the branch name.
> But the dangling indicator such as "-" or "*" before the branch name
> doesn't look nice when there is a space that separates it
> from the project name, e.g. "project -branch".

It would probably make more sense to me, but having both might be overkill.

FWIW, with the custom mode-line that I use (smart-mode-line) the results 
of these two options would look the same -- space-separated anyway.





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

* bug#66464: Vc mode-line
  2023-11-11 22:05             ` Dmitry Gutov
@ 2023-11-12  8:07               ` Juri Linkov
  2023-11-12 10:59                 ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-11-12  8:07 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66464

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

>> PS: Probably we could also add another option `no-backend'
>> that will show only an indicator and the branch name.
>> But the dangling indicator such as "-" or "*" before the branch name
>> doesn't look nice when there is a space that separates it
>> from the project name, e.g. "project -branch".
>
> It would probably make more sense to me, but having both might be overkill.
>
> FWIW, with the custom mode-line that I use (smart-mode-line) the results of
> these two options would look the same -- space-separated anyway.

Oh, this means that removing a space is useless for such mode-lines.

Ok, then let's add a much cleaner option `no-backend'.
Then anyone who doesn't like that space could customize
the mode line with something like

  (define-advice vc-mode-line (:after (&rest _args) remove-space)
    (setq vc-mode (string-trim-left vc-mode)))


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-display-status-no-backend.patch --]
[-- Type: text/x-diff, Size: 2896 bytes --]

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index c16fb63b2ff..f65ee150603 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -152,8 +152,12 @@ vc-follow-symlinks
 
 (defcustom vc-display-status t
   "If non-nil, display revision number and lock status in mode line.
-Otherwise, not displayed."
-  :type 'boolean
+If nil, only the backend name is displayed.  When the value
+is `no-backend', then no backend name is displayed before the
+revision number and lock status."
+  :type '(choice (const :tag "Show only revision/status" no-backend)
+                 (const :tag "Show backend and revision/status" t)
+                 (const :tag "Show only backend name" nil))
   :group 'vc)
 
 
@@ -766,7 +769,9 @@ vc-default-mode-line-string
                (rev (vc-working-revision file backend))
                (`(,state-echo ,face ,indicator)
                 (vc-mode-line-state state))
-               (state-string (concat backend-name indicator rev)))
+               (state-string (concat (unless (eq vc-display-status 'no-backend)
+                                       backend-name)
+                                     indicator rev)))
     (propertize state-string 'face face 'help-echo
                 (concat state-echo " under the " backend-name
                         " version control system"))))
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 707fc7cfc07..27eebe79148 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -423,7 +423,9 @@ vc-git-mode-line-string
                (rev (vc-working-revision file 'Git))
                (disp-rev (or (vc-git--symbolic-ref file)
                              (and rev (substring rev 0 7))))
-               (state-string (concat backend-name indicator disp-rev)))
+               (state-string (concat (unless (eq vc-display-status 'no-backend)
+                                       backend-name)
+                                     indicator disp-rev)))
     (propertize state-string 'face face 'help-echo
                 (concat state-echo " under the " backend-name
                         " version control system"
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 89b2814a0a3..9df517ea847 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -365,7 +365,9 @@ vc-hg-mode-line-string
                             (and vc-hg-use-file-version-for-mode-line-version
                                  truename)))))
                (rev (or rev "???"))
-               (state-string (concat backend-name indicator rev)))
+               (state-string (concat (unless (eq vc-display-status 'no-backend)
+                                       backend-name)
+                                     indicator rev)))
     (propertize state-string 'face face 'help-echo
                 (concat state-echo " under the " backend-name
                         " version control system"))))

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

* bug#66464: Vc mode-line
  2023-11-12  8:07               ` Juri Linkov
@ 2023-11-12 10:59                 ` Dmitry Gutov
  2023-11-13  7:11                   ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-11-12 10:59 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 66464

On 12/11/2023 10:07, Juri Linkov wrote:
> Oh, this means that removing a space is useless for such mode-lines.
> 
> Ok, then let's add a much cleaner option `no-backend'.
> Then anyone who doesn't like that space could customize
> the mode line with something like
> 
>    (define-advice vc-mode-line (:after (&rest _args) remove-space)
>      (setq vc-mode (string-trim-left vc-mode)))

That certainly works for me.

Thanks!





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

* bug#66464: Vc mode-line
  2023-11-12 10:59                 ` Dmitry Gutov
@ 2023-11-13  7:11                   ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2023-11-13  7:11 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66464

close 66464 30.0.50
thanks

>> Oh, this means that removing a space is useless for such mode-lines.
>> Ok, then let's add a much cleaner option `no-backend'.
>> Then anyone who doesn't like that space could customize
>> the mode line with something like
>>    (define-advice vc-mode-line (:after (&rest _args) remove-space)
>>      (setq vc-mode (string-trim-left vc-mode)))
>
> That certainly works for me.

Thanks for helping to arrive at this good solution.





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

end of thread, other threads:[~2023-11-13  7:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 16:29 bug#66464: Vc mode-line Juri Linkov
2023-10-16  1:11 ` Dmitry Gutov
2023-10-16 17:14   ` Juri Linkov
2023-10-31  7:40 ` Juri Linkov
2023-11-09 16:41   ` Juri Linkov
2023-11-10  2:04     ` Dmitry Gutov
2023-11-10  7:33       ` Juri Linkov
2023-11-10 23:54         ` Dmitry Gutov
2023-11-11 18:50           ` Juri Linkov
2023-11-11 22:05             ` Dmitry Gutov
2023-11-12  8:07               ` Juri Linkov
2023-11-12 10:59                 ` Dmitry Gutov
2023-11-13  7:11                   ` 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).