From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: How to know the buffer I will return to from the minibuffer? Date: Thu, 14 Feb 2019 15:38:18 +0000 (UTC) Message-ID: References: <87r2caonep.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="212564"; mail-complaints-to="usenet@blaine.gmane.org" To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Feb 14 16:48:17 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guJFJ-000tAq-BM for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Feb 2019 16:48:17 +0100 Original-Received: from localhost ([127.0.0.1]:50552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guJFI-0001Ia-8F for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Feb 2019 10:48:16 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guJ5v-0002uO-9P for help-gnu-emacs@gnu.org; Thu, 14 Feb 2019 10:38:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guJ5u-0001CK-5Q for help-gnu-emacs@gnu.org; Thu, 14 Feb 2019 10:38:35 -0500 Original-Received: from aserp2130.oracle.com ([141.146.126.79]:40360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guJ5r-00015O-PI for help-gnu-emacs@gnu.org; Thu, 14 Feb 2019 10:38:32 -0500 Original-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1EFXnos040966; Thu, 14 Feb 2019 15:38:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=OOeaiRaQbKZuDwwhWhaIJylGsNBZqaonNQwqep7RTxg=; b=aVk5nLrsopToTtldKfM9ruG+yYsUZH4NPdj+RqgVbEcb6lUfTucqXtutGH+FOhRLufR0 w49Z+V+WzXvcvfYfACXiODEs1+OMCcPNJYlMl3wL5+yM2PbWsgi0C3kokW7EgVtpsbSL yjvaONXPUwfcOE33z9REd7APZWIAuayrkHfRsg8SNdaDXLtUUDq9p6Mpz5oF4vUzM9RD 3ldPucMOyyMpgkxl/D5QuIeUItEqt0F2sbxryMjcf0bWFT42aSpuv6VnivjsmFnRmqmM Z9Pra/La4Up2GDex4SaUDNiSICfqkfBdEsqChNKb5rf8QJu2re2j1DAcbuCW/mXp5yYB Ag== Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qhre5rpt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Feb 2019 15:38:19 +0000 Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1EFcJ52018970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Feb 2019 15:38:19 GMT Original-Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1EFcID0020651; Thu, 14 Feb 2019 15:38:19 GMT In-Reply-To: <87r2caonep.fsf@mbork.pl> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4810.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9167 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=918 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902140109 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.help:119404 Archived-At: > I am writing an interactive command to be used while in the minibuffer. > I need to know the buffer I was in when I issued the command that put > me in the minibuffer (like M-: or M-!). I tried (other-buffer > (current-buffer)) and (last-buffer (current-buffer)), but to no avail. > Then I re-read the docs for `other-buffer' and used this: (other-buffer > (current-buffer) t), and it seemed to work. The question is, how > reliable it is. Am I doing this correctly? If you use Icicles then that buffer is the value of variable `icicle-pre-minibuffer-buffer': Buffer that was current before the minibuffer became active. and its window is the last-used window showing it: (icicle-mru-window-for-buffer icicle-pre-minibuffer-buffer 'noMNI 0) When minibuffer setup occurs, the variable is set using function `icicle-last-non-minibuffer-buffer', which does this: (let ((live-bufs (icicle-remove-if (lambda (buf) (not (buffer-live-p buf))) (buffer-list)))) (or (car bufs) (car live-bufs))) If you don't use Icicles you can do the same kind of thing. Use `minibuffer-setup-hook' to set a variable to the last live non-minibuffer buffer. This is `icicle-mru-window-for-buffer': (defun icicle-mru-window-for-buffer (buffer &optional minibuf all-frames) "Return the most recently used window for BUFFER. Optional args MINIBUF and ALL-FRAMES are as for `get-buffer-window-list'." (let* ((wins (get-buffer-window-list buffer minibuf all-frames)) (mru-win (car wins)) (mru-time (window-use-time mru-win)) wtime) (unless (listp mru-time) (setq mru-time (seconds-to-time mru-time))) (dolist (win (cdr wins)) (setq wtime (window-use-time win)) (unless (listp wtime) (setq wtime (seconds-to-time wtime))) (unless (time-less-p wtime mru-time) (setq mru-time wtime mru-win win))) mru-win))