From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: My read-buffer-function doesn't work when called by switch-to-buffer Date: Fri, 10 Mar 2023 22:10:29 +0100 Message-ID: <875yb8nvvk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20849"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.22; emacs 30.0.50 To: Users of the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 10 22:24:26 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pakDx-0005Eo-Sd for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 10 Mar 2023 22:24:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pakDM-000265-8V; Fri, 10 Mar 2023 16:23:48 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pakDL-00025x-DH for help-gnu-emacs@gnu.org; Fri, 10 Mar 2023 16:23:47 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pakDL-0000vr-5b for help-gnu-emacs@gnu.org; Fri, 10 Mar 2023 16:23:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=acncVzp9ChM6r4t8uoVv8xlCFEhFLSWlHW4sV+sKbew=; b=jFNWBmOmlzGz5+ 1HKRXG4m3v+IAUETAu3TWBGcwRAHCxRE0XzrmapSqENBQtdcrRKb593nv+QQ89YvO0gMpTbV0lDIW ImHGNOu+A2laj4xcWBT0juclLaMJMTu/5YnSt37eLAxrpy4HfbhNHQfzdAczKkf0umScPpG1saG/X sd3ehD7rt/a6cPVBECvFeHH1vwNK3YN2cY8F4FQ3y6krlbCBRbR8a0S3YKrF2xE9XoWNK3GHiFKzr d23s5WTrIXNmcgNMjFWUdOogrl0UjGx0E9Qmh0huLy3qxFsm++SeyzCHIti+cMDIvyp2+WNnxw7Ik 9KvJE5RvBJRp0QsHpWAQ==; Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pakDK-0004UP-KG for help-gnu-emacs@gnu.org; Fri, 10 Mar 2023 16:23:46 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 257DF27C005A for ; Fri, 10 Mar 2023 16:23:46 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 10 Mar 2023 16:23:46 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddukedgudeghecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpegfhffvufffkfggtgesthdtredttdertdenucfhrhhomhepvfgrshhsihhl ohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpeduvd euveejfeekueffieffhfethfdviedutddtgfeivddvhfevffelgfdujeetveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnodhmvg hsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedvleek qdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 10 Mar 2023 16:23:45 -0500 (EST) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:142970 Archived-At: Hi all, I would like that switch-to-buffer also suggests recent files. Given that it uses read-buffer which can be customized using a read-buffer-function, I thought that should be easy. That's what I have come up with: --8<---------------cut here---------------start------------->8--- (defun th/read-buffer-or-recentf (prompt &optional def require-match predicate) (when-let ((result (completing-read prompt (completion-table-in-turn #'internal-complete-buffer (completion-table-dynamic (lambda (s) recentf-list))) predicate require-match nil 'buffer-name-history def))) (cond ((get-buffer result) result) ((file-exists-p result) (buffer-name (find-file-noselect result))) (t result)))) (setq read-buffer-function #'th/read-buffer-or-recentf) --8<---------------cut here---------------end--------------->8--- The function th/read-buffer-or-recentf works fine when called standalone, i.e., when I evaluate (th/read-buffer-or-recentf "test: ") and type something which won't complete to an existing buffer, recent files pop up as completion candidates. Yay! However, when I do C-x b (switch-to-buffer), no matter what, recent files are not provided as completion candidates. But edebug convinces me that my function th/read-buffer-or-recentf is called. It just seems that the same completing-read call behaves differently when called directly and when being called by switch-to-buffer. Why is that and what can I do against it? Thanks, Tassilo