From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Jonas Bernoulli Newsgroups: gmane.emacs.devel Subject: Re: Let mode-line packages distinguish the selected-window Date: Sat, 26 Oct 2019 21:27:29 +0200 Message-ID: <877e4r5mu6.fsf@bernoul.li> References: <87blu3pqyc.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="137616"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 26 21:28:04 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iORjG-000ZVH-2h for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 21:28:02 +0200 Original-Received: from localhost ([::1]:41586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iORjE-0004E5-5g for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 15:28:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50111) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iORiv-00047M-An for emacs-devel@gnu.org; Sat, 26 Oct 2019 15:27:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iORiu-0005W6-3A for emacs-devel@gnu.org; Sat, 26 Oct 2019 15:27:41 -0400 Original-Received: from mail.hostpark.net ([212.243.197.30]:51718) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iORit-0005Vn-TR for emacs-devel@gnu.org; Sat, 26 Oct 2019 15:27:40 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id DA1FF16620; Sat, 26 Oct 2019 21:27:37 +0200 (CEST) X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Original-Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10124) with ESMTP id oWgfmvYKXlCR; Sat, 26 Oct 2019 21:27:37 +0200 (CEST) Original-Received: from p2 (212-51-149-230.fiber7.init7.net [212.51.149.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 6AB37161BE; Sat, 26 Oct 2019 21:27:37 +0200 (CEST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.243.197.30 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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 Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241476 Archived-At: Stefan Monnier writes: >> To deal with this the packages mentioned above resort to using several >> hook functions and advice to keep track of "the" selected window and >> then they do something like: > > AFAIK since Emacs-24.4 only one hook is needed: Well it seems I (or any of the maintainers of the other packages, really) should have asked a bit earlier. oO >> Because keeping remembered-selected-window up-to-date involves several >> hooks and advises this is rather ugly and fragile. > > With `pre-redisplay-function(s)` is should be "easy and reliable". That's very promising indeed. The minibuffer window needs to be handled a bit differently, I think: (defun moody--set-active-window (_) (let ((win (selected-window))) (unless (minibuffer-window-active-p win) (setq moody--active-window win)))) (add-hook 'pre-redisplay-functions #'moody--set-active-window) >> In summary, please add a way for functions that format elements of the >> mode-line to determine whether these elements are going to be used in >> the selected or some other window. > > Despite what the above may suggest, I fully agree: while it's now easy > to "roll your own", this is a common need and we should provide this > info directly. That would be nice. (And no Eli, I don't have a patch ready. Not much of a C guy. Not at all really.) But even though I suggested something like that, I feel the remembered-selected-window approach is a bit hackish. IMO it would be nicer if instead of that variable regular selected-window would return "that window" while a new function/variable named something like mode-line-window returned the "window whose mode-line is currently being updated". But that would be a breaking change, so maybe not. Jonas