From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: set-window-buffer bugs Date: Sat, 5 Dec 2015 13:19:52 -0800 Message-ID: References: <87fuzgboub.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1449350429 29814 80.91.229.3 (5 Dec 2015 21:20:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Dec 2015 21:20:29 +0000 (UTC) Cc: "jenia.ivlev" To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 05 22:20:29 2015 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 1a5KFm-0004cO-PH for geh-help-gnu-emacs@m.gmane.org; Sat, 05 Dec 2015 22:20:26 +0100 Original-Received: from localhost ([::1]:47799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a5KFm-0006vN-2C for geh-help-gnu-emacs@m.gmane.org; Sat, 05 Dec 2015 16:20:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a5KFZ-0006sc-Tx for help-gnu-emacs@gnu.org; Sat, 05 Dec 2015 16:20:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a5KFZ-0007fn-7M for help-gnu-emacs@gnu.org; Sat, 05 Dec 2015 16:20:13 -0500 Original-Received: from mail-yk0-x22a.google.com ([2607:f8b0:4002:c07::22a]:33164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a5KFZ-0007fa-44 for help-gnu-emacs@gnu.org; Sat, 05 Dec 2015 16:20:13 -0500 Original-Received: by ykdv3 with SMTP id v3so158575992ykd.0 for ; Sat, 05 Dec 2015 13:20:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=JJBZ1bm60QQRNwiVVboGezYHCJAPMrICUP2GdtOIPak=; b=teLB8gkOUtTyHyBfxoit5N8OByjvR+x0iwQgjgqkLr+wlGJab8jvnHdj2905F7zLxX L+0ATl+FwNutcfA76I399Yhke+dlsakzhoodwtQrYXjmfEUh2OTPqsgG2jIY8cWRW43X 04NaV7ETJ0owWy/saybLve4+TZOtCx6yyDni3cbOKXIc3dkrRLYA8N5g+y74foklC3nI hWWOQi1j9Qj4oT3MQK8UKhP480Kj9KYrZTQk7fU8fBxFHqM1ObYaDMdQGOnPlGiswtqc Qzx1rYToo4KhQXCCG/dwKcLAO5GaUaMwu7K4RYlwOdKyJ/b1Ek/IO4CPksQ7QASHPgrE T/eQ== X-Received: by 10.129.50.214 with SMTP id y205mr18269876ywy.147.1449350412375; Sat, 05 Dec 2015 13:20:12 -0800 (PST) Original-Received: by 10.37.95.214 with HTTP; Sat, 5 Dec 2015 13:19:52 -0800 (PST) In-Reply-To: <87fuzgboub.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c07::22a 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:108309 Archived-At: jenia.ivlev wrote: > Hello. > > Using dired, I want find-buffer-other-window to open in the exact > same window. > > So I made this little program: > > > (define-key dired-mode-map "o" 'dired-find-file-other-opened-window) > > (defun dired-find-file-other-opened-window () > (interactive) > (set-window-buffer (frame-first-window) (dired-get-filename 'no-dir)) > (dired-find-file-other-window)) > > > It turns out that you needed to have visited that file already for > this to work. [snip] > I mean, I don't get it. Why do I need to have visited the file before? > And in any case, how do I fix this? I just want it to open in the > (frame-first-window) that's all. Correct, the second argument to `set-window-buffer' must be a buffer (or the name of a buffer), not the name of the file. The distinction between buffers and files is an important one. As one small practical consideration, there can be many files named "foo.txt", but only one buffer named "foo.txt". If you're not sure which (file or buffer) is appropriate for a given function, check out its documentation (e.g. `C-h f set-window-buffer RET'). In many cases, as with `set-window-buffer', the name itself gives a hint. All that said, I think the command below will do what you want. The function `find-file-noselect' is the one that visits the file and creates a buffer. If the file is already open, it returns the existing buffer. It's a variant of `find-file' (the command bound to `C-x C-f') with the difference that it doesn't display the buffer - useful to us here because we want to handle that part ourselves. (defun dired-find-file-other-opened-window () (interactive) (let* ((file (dired-get-filename 'no-dir)) (buffer (find-file-noselect file))) (set-window-buffer (frame-first-window) buffer))) Hope that helps -- john