From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: Recognizing active/inactive mode-line in (:eval ...) form in mode-line-string Date: Fri, 01 Mar 2013 20:21:00 +0100 Message-ID: <87lia70vvn.fsf@web.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362165560 8883 80.91.229.3 (1 Mar 2013 19:19:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Mar 2013 19:19:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 01 20:19:43 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UBVUc-0002xP-GT for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 20:19:42 +0100 Original-Received: from localhost ([::1]:50181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBVUH-0003Ru-8L for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 14:19:21 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:40183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBVU5-0003NM-H1 for help-gnu-emacs@gnu.org; Fri, 01 Mar 2013 14:19:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBVU3-0000Al-F0 for help-gnu-emacs@gnu.org; Fri, 01 Mar 2013 14:19:09 -0500 Original-Received: from mout.web.de ([212.227.17.12]:58355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBVU3-0000AY-5b for help-gnu-emacs@gnu.org; Fri, 01 Mar 2013 14:19:07 -0500 Original-Received: from drachen.dragon ([92.74.177.220]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0MBCNl-1U42gu0COb-00A8wT; Fri, 01 Mar 2013 20:19:05 +0100 Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (Alessandro Piras's message of "Thu, 28 Feb 2013 12:25:27 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Provags-ID: V02:K0:f95D1rKh0Q5yEz/uA1k2+AZ8gRW9SyZkMrC1l6weB5t THSsA7RqXS3PA8M12IBuMhuDx/uvJunhZoHstCegMdc7nTgRif mZfbcl5/pqJ9XpubR4d9OZrWCT6YD6eQcJKyN8mQ3teZGAQG4n RRof+8rQANj+GFMhvkK/BWDNvVrIEtZ9avk+hJP6FamJ0CRnAD a35MijkEtviBZayzyMc5S4eXwngkqn6UWkfat3QMYA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89313 Archived-At: Alessandro Piras writes: > Is there a way to know if the mode-line is active in a (:eval ...) > form inside the mode-line-string? > > A simple example: > mode-line-string => > ("%e" (:eval (if "foo" "bar"))) > > I would like to see "foo" on the mode-line of the active window, > "bar" on the others. This is a very good question! AFAICT, when the mode-line of any window is calculated, it is temporarily selected. This would mean that such a condition doesn't exist. So, you'll need some trick, e.g. something like --8<---------------cut here---------------start------------->8--- (add-hook 'post-command-hook (lambda () (setq my-selected-window (selected-window)))) (push '(:eval (if (eq (selected-window) my-selected-window) "foo" "bar")) default-mode-line-format) --8<---------------cut here---------------end--------------->8--- i.e., try to remember and update the selected window in a global variable. Probably this can be achieved more elegantly than above. Note that you still may have to force a mode-line update to always have the right "foo" or "bar". Regards, Michael.