From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Get current buffer name from command line? Date: Wed, 13 Aug 2014 17:40:07 -0400 Message-ID: References: <20140813133234.6805a417@aga-netbook> <20140813224926.064de008@aga-netbook> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1407966064 32414 80.91.229.3 (13 Aug 2014 21:41:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2014 21:41:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 13 23:40:54 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 1XHgHu-0003CE-IZ for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Aug 2014 23:40:54 +0200 Original-Received: from localhost ([::1]:50424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgHu-0007V2-7U for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Aug 2014 17:40:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgHZ-0007Ti-CI for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 17:40:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHgHR-00036P-Sn for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 17:40:33 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:42757) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHgHR-00036H-JF for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 17:40:25 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XHgHQ-0002zH-CJ for help-gnu-emacs@gnu.org; Wed, 13 Aug 2014 23:40:24 +0200 Original-Received: from 192-171-34-171.cpe.pppoe.ca ([192.171.34.171]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Aug 2014 23:40:24 +0200 Original-Received: from monnier by 192-171-34-171.cpe.pppoe.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Aug 2014 23:40:24 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 37 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 192-171-34-171.cpe.pppoe.ca User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:ibdiJXDOYFaOTBgnDsDakYkUmmc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:99199 Archived-At: > 1. So what exactly is "current-buffer"? Or, more precisely, why > (progn (kill-buffer) (current-buffer)) > didn't work? 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. 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. 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). > 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;). 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. Stefan