help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get current buffer name from command line?


From: Stefan Monnier
Subject: Re: Get current buffer name from command line?
Date: Wed, 13 Aug 2014 17:40:07 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]