From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: pop-up tool-bar Date: Thu, 7 Oct 2004 14:04:51 -0700 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1097183325 32685 80.91.229.6 (7 Oct 2004 21:08:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 7 Oct 2004 21:08:45 +0000 (UTC) Cc: Miguel Frasson , Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 07 23:08:36 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CFfV5-0001t7-00 for ; Thu, 07 Oct 2004 23:08:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CFfbq-0000nJ-Jg for ged-emacs-devel@m.gmane.org; Thu, 07 Oct 2004 17:15:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CFfbf-0000my-RS for emacs-devel@gnu.org; Thu, 07 Oct 2004 17:15:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CFfbf-0000mf-4J for emacs-devel@gnu.org; Thu, 07 Oct 2004 17:15:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CFfbf-0000mV-0u for emacs-devel@gnu.org; Thu, 07 Oct 2004 17:15:23 -0400 Original-Received: from [141.146.126.229] (helo=agminet02.oracle.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CFfUr-00088O-Rr for emacs-devel@gnu.org; Thu, 07 Oct 2004 17:08:22 -0400 Original-Received: from rgmgw1.us.oracle.com (rgmgw1.us.oracle.com [138.1.191.10]) by agminet02.oracle.com (Switch-3.1.4/Switch-3.1.0) with ESMTP id i97L4tNl006908; Thu, 7 Oct 2004 14:04:55 -0700 Original-Received: from rgmgw1.us.oracle.com (localhost [127.0.0.1]) by rgmgw1.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with ESMTP id i97L4t12026970; Thu, 7 Oct 2004 15:04:55 -0600 Original-Received: from dradamslap (dradams-lap.us.oracle.com [130.35.177.126]) by rgmgw1.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with SMTP id i97L4q7q026801; Thu, 7 Oct 2004 15:04:52 -0600 Original-To: "Stefan Monnier" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Importance: Normal In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:28060 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:28060 Good input. I wasn't even aware of `make-variable-frame-local', though I see now that it's at least as old as Emacs 20. I see you put "valid" in quotes, but I'm still not sure I know what you mean. If the next event is a (valid) mouse-down, that's seems to be OK. The mouse-down occurs at the right position in the buffer (as evidenced by the highlighted region and cursor position), so I don't think that's the pb. What happens, I think, is that when the tool-bar disappears, without your having moved the mouse relative to the display, the mouse nevertheless has moved relative to the displayed buffer -- so a region has been selected. Now that I think of it, that could provide a solution, if we could be sure to know the tool-bar height at all times in terms of # of buffer lines. We could scroll the buffer down that number of lines, to compensate for the buffer lines moving up relative to the display because the tool-bar disappears. Maybe I'll give that a try. (Looking at tool-bar margins and button-relief margins might be kind of a pain, though, and perhaps the tool-bar height is not always an integral number of buffer lines, and maybe we'll have to worry about different-size fonts - ugh.) Can you elaborate on your "Note" - Is it meant to apply to my original code or to your code (or both)? With my code, if I click "Buttons" and then delete the frame instead of clicking a button, it seems to behave as I would expect, at least on Windows: the frame is gone, that's all. Maybe I'm doing something wrong, but your code doesn't work for me: - The tool-bar doesn't disappear afterward, no matter how I end (click a button or do something else. - "Buttons" doesn't come back to the menu-bar, and I can't get it back again, even by turning tool-bar-mode on, then off. - I get this error when I click "Buttons": show-tool-bar-for-one-command: Wrong number of arguments: (lambda (hook function append local)... No doubt the first two symptoms are due to the last pb. Don't you need an unwind-protect to be sure to turn the mode back off, in case, for instance, the user does C-g -- or will the post-command-hook always take care of that? - Drew --------------- From: Stefan Monnier It looks like the problem is that the event you get from read-event is not "valid" any more after you remove the toolbar (becaue the position is changed). Using read-event is generally a source a trouble. But the alternatives aren't great either. Maybe you can try something like the appended code. Note: you should pay attention to the case where the frame has been deleted by the next command. Also, you declare your minor mode to be ":global t" but it is frame-local, so you should add (make-variable-frame-local 'tool-bar-here-mode) somewhere at the toplevel. Stefan (defun add-hook-once (hook function append local) "Same as `add-hook', but FUN is only run once. Also contrary to `add-hook', this is not idempotent." (let ((code (list 'lambda))) (setcdr code `(() (,function) (remove-hook ',hook ',code ',local))) (add-hook hook code append local))) ... (defun show-tool-bar-for-one-command () "Pop up the tool bar so you can click a button. The tool bar stays visible until one command is executed \(whether or not it was initiated by clicking a button)." (interactive) (tool-bar-here-mode 1) (add-hook-once 'post-command-hook `(lambda () ;; We're just now done with show-tool-bar-for-one-command. (add-hook-once 'post-command-hook (lambda () ;; We're done with the next command. (select-frame ',(selected-frame)) (tool--bar-here-mode -1))))))