bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#43383: 26.3; `toggle-menu-bar-mode-from-frame'


From: Lars Ingebrigtsen
Subject: bug#43383: 26.3; `toggle-menu-bar-mode-from-frame'
Date: Mon, 14 Sep 2020 01:30:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Drew Adams <drew.adams@oracle.com> writes:

> I don't understand the doc string:
>
>  Toggle menu bar on or off, based on the status of the current frame.
>  See `menu-bar-mode' for more information.
>
> I have no idea what is meant by "based on the status of the current
> frame".  Is the status whether it shows the menu-bar?
>
> Furthermore, this seems to be used only in menu Options > Show/Hide.
> Which means it's only visible when the menu-bar is visible, right?

It's very confusing indeed, but the patch that introduces this has a
long essay about why it was added.

It's something to do with...  multi-tty?  Which clarifies the meaning of
"Toggle menu bar on or off, based on the status of the current frame."
somewhat, since the exegesis says that the (global) status may be...
wrong?

That sounds like a bug, doesn't it?

commit 6a5af08f8d3bb831a78edf17e9c38813bbfbb6f8
Author:     Karoly Lorentey <lorentey@elte.hu>
AuthorDate: Sun Mar 26 14:20:01 2006 +0000
Commit:     Karoly Lorentey <lorentey@elte.hu>
CommitDate: Sun Mar 26 14:20:01 2006 +0000

    Fix tool-bar and menu-bar toggles in Show/Hide menu to reflect the state of 
the current frame.
    
    * lisp/tool-bar.el (toggle-tool-bar-mode-from-frame): New function.
    
    * lisp/menu-bar.el (toggle-menu-bar-mode-from-frame): New function.
      (menu-bar-showhide-menu): Use them to change "Menu-bar" and
      "Tool-bar" toggles to reflect the state of the current frame.
    
    git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-537

diff --git a/README.multi-tty b/README.multi-tty
index 2ac27bafe5..442c4c92fd 100644
--- a/README.multi-tty
+++ b/README.multi-tty
@@ -404,17 +404,6 @@ is probably not very interesting for anyone else.)
 THINGS TO DO
 ------------
 
-** `tool-bar-mode', `scroll-bar-mode', `menu-bar-mode' and
-   'fringe-mode' are modes global to the entire Emacs session, not
-   just a single frame or a single terminal.  This means that their
-   status sometimes differs from what's actually displayed on the
-   screen.  As a consequence, the Options | Show/Hide menu sometimes
-   shows incorrect status, and you have to select an option twice for
-   it to have any visible effect on the current frame.
-
-   Change Emacs so that the status of the items in the Options |
-   Show/Hide menu correspond to the current frame.
-
 ** emacsclient -t on the console does not work after su:
 
        # su lorentey
@@ -1485,5 +1474,18 @@ DIARY OF CHANGES
 
    (Done in patch-500.)
 
+-- `tool-bar-mode', `scroll-bar-mode', `menu-bar-mode' and
+   'fringe-mode' are modes global to the entire Emacs session, not
+   just a single frame or a single terminal.  This means that their
+   status sometimes differs from what's actually displayed on the
+   screen.  As a consequence, the Options | Show/Hide menu sometimes
+   shows incorrect status, and you have to select an option twice for
+   it to have any visible effect on the current frame.
+
+   Change Emacs so that the status of the items in the Options |
+   Show/Hide menu correspond to the current frame.
+
+   (Done in patch-537.)
+
 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
 
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 75d68d0baa..a9987d589f 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -935,15 +935,15 @@ menu-bar-showhide-menu
        :button `(:toggle . tooltip-mode)))
 
 (define-key menu-bar-showhide-menu [menu-bar-mode]
-  '(menu-item "Menu-bar" menu-bar-mode
+  '(menu-item "Menu-bar" toggle-menu-bar-mode-from-frame
              :help "Toggle menu-bar on/off"
-             :button (:toggle . menu-bar-mode)))
+             :button (:toggle . (> (frame-parameter nil 'menu-bar-lines) 0))))
 
 (define-key menu-bar-showhide-menu [showhide-tool-bar]
-  (list 'menu-item "Tool-bar" 'tool-bar-mode
-       :help "Turn tool-bar on/off"
+  (list 'menu-item "Tool-bar" 'toggle-tool-bar-mode-from-frame
+       :help "Toggle tool-bar on/off"
        :visible `(display-graphic-p)
-       :button `(:toggle . tool-bar-mode)))
+       :button `(:toggle . (> (frame-parameter nil 'tool-bar-lines) 0))))
 
 (define-key menu-bar-options-menu [showhide]
   (list 'menu-item "Show/Hide" menu-bar-showhide-menu
@@ -1778,6 +1778,14 @@ menu-bar-mode
                         "Menu-bar mode disabled.  Use M-x menu-bar-mode to 
make the menu bar appear."))
   menu-bar-mode)
 
+(defun toggle-menu-bar-mode-from-frame (&optional arg)
+  "Toggle menu bar on or off, based on the status of the current frame.
+See `menu-bar-mode' for more information."
+  (interactive (list (or current-prefix-arg 'toggle)))
+  (if (eq arg 'toggle)
+      (menu-bar-mode (if (> (frame-parameter nil 'menu-bar-lines) 0) 0 1))
+    (menu-bar-mode arg)))
+
 (provide 'menu-bar)
 
 ;;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el
index be552854b1..023b90af5d 100644
--- a/lisp/tool-bar.el
+++ b/lisp/tool-bar.el
@@ -61,6 +61,16 @@ tool-bar-mode
                (display-graphic-p))
           (tool-bar-setup))))
 
+;;;###autoload
+;; Used in the Show/Hide menu, to have the toggle reflect the current frame.
+(defun toggle-tool-bar-mode-from-frame (&optional arg)
+  "Toggle tool bar on or off, based on the status of the current frame.
+See `tool-bar-mode' for more information."
+  (interactive (list (or current-prefix-arg 'toggle)))
+  (if (eq arg 'toggle)
+      (tool-bar-mode (if (> (frame-parameter nil 'tool-bar-lines) 0) 0 1))
+    (tool-bar-mode arg)))
+
 ;;;###autoload
 ;; We want to pretend the toolbar by standard is on, as this will make
 ;; customize consider disabling the toolbar a customization, and save


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]