From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Get current buffer name from command line? Date: Thu, 14 Aug 2014 00:08:51 +0200 Organization: WMI UAM Message-ID: <20140814000851.546f221b@aga-netbook> References: <20140813133234.6805a417@aga-netbook> <20140813224926.064de008@aga-netbook> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1407967768 20039 80.91.229.3 (13 Aug 2014 22:09:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2014 22:09:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 14 00:09:20 2014 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 1XHgjQ-0006s5-4i for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Aug 2014 00:09:20 +0200 Original-Received: from localhost ([::1]:50569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgjP-000600-Dq for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Aug 2014 18:09:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgj9-0005zb-3o for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 18:09:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHgj3-0004WK-My for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 18:09:03 -0400 Original-Received: from msg.wmi.amu.edu.pl ([150.254.78.50]:59237) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgj3-0004Vu-GW for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 18:08:57 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 0701D45791 for ; Thu, 14 Aug 2014 00:08:53 +0200 (CEST) Original-Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LnZAd6pMff8h for ; Thu, 14 Aug 2014 00:08:52 +0200 (CEST) Original-Received: from aga-netbook (unknown [185.13.171.31]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id DC57E45761 for ; Thu, 14 Aug 2014 00:08:52 +0200 (CEST) In-Reply-To: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.20; i686-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 150.254.78.50 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:99201 Archived-At: Dnia 2014-08-13, o godz. 17:40:07 Stefan Monnier napisa=C5=82(a): > > 1. So what exactly is "current-buffer"? Or, more precisely, why > > (progn (kill-buffer) (current-buffer)) > > didn't work? >=20 > current-buffer is something that changes all the time for > internal reasons. E.g. while processing the request coming from > emacsclient, the current-buffer will be temporarily changed to the > *server* buffer. That has no influence on display. >=20 > It's simply that most operations that touch a buffer do it on the > current-buffer, so if you want to look at a buffer's content, or > change it, or consult some of its variables, the way you typically do > it is by temporarily changing current-buffer. >=20 > The same holds for manipulating windows, which is why selected-window > may not always return what you think (as a user) as "the selected > window" (e.g. it may get temporarily changed by process-filter > handling a subprocess's output). I see. > > 2. Why "more often"? Is it possible that it won't? To be more > > precise on my requirements: I thought about writing a script (to be > > put into cron) which would gather data on what I'm doing at various > > times so that I can measure time spent on different activities. > > Since most of my computer time is spent in Emacs, this would be an > > important part of it. From the docstring of selected-window, it > > seems to be exactly what I'm looking for. Still, the words "more > > often" made me a bit suspicious;). >=20 > I think "emacsclient -e '(window-buffer (selected-window))'" will work > fine for your use case, but if you want to take idle time into > account, you might like to use a post-command-hook which sets a > global var to the "current time after last command" at which point > you could also set a global var to "the selected-window after last > command" which should be more reliable. OK, now I get it. Thanks for taking the time to explain this to me! > Stefan Best, --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Adam Mickiewicz University