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: Re: My read-buffer-function doesn't work when called by switch-to-buffer Date: Thu, 16 Mar 2023 10:18:15 +0100 Message-ID: <87ttylhwyd.fsf@gnu.org> References: <875yb8nvvk.fsf@gnu.org> <87y1o486wo.fsf@web.de> <87fsabslcj.fsf@gnu.org> <874jqq63vn.fsf@web.de> <87h6upyenm.fsf@gnu.org> <87sfe9bien.fsf@web.de> <874jqms6s2.fsf@gnu.org> <87mt4dn8qi.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39081"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.22; emacs 30.0.50 Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 16 10:23:11 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 1pcjpG-0009tX-DH for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 16 Mar 2023 10:23:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcjp4-0002rf-Df; Thu, 16 Mar 2023 05:22:58 -0400 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 1pcjp2-0002rT-LH for help-gnu-emacs@gnu.org; Thu, 16 Mar 2023 05:22:56 -0400 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 1pcjp2-00032D-D4; Thu, 16 Mar 2023 05:22:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=zoXbIbLCcMSH0Re878WR7tiLsbrXZNqN9sBuT2ZJXWU=; b=K4l+qdSZigXBRf ZCpH4oOWOdzECsXTIss97BVPVo4cs/iM5DD2BQaI+ZgMs3lnzgXj20k8TTBXnP861UrUy9ztlNfXy Bp0k6OgaETLcqNjpiyADPeUJvJBttRcM+G8VzKUZfOsYgTj3tD8pJ9/9X+Ewn2q2L3uYpSNSz/dzu U4Nqkv256PbP1vBftlaae7mfXdHoVehDmSX24t0j2AcR2SdLEMSL1ibF79OQVS31vaoCOee//PCfF J+xnDnUUta2lsmcr9d01wo47fkboWJe+qCU6dhxORnTDpPRfebJ20qxts+IVlHsaViUHIy1oxPWBy veu0w9L3fSFKs6CHUsrA==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcjp2-00066w-1p; Thu, 16 Mar 2023 05:22:56 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id CCC8D27C0054; Thu, 16 Mar 2023 05:22:53 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 16 Mar 2023 05:22:53 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeftddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvvefuffgjkfggtgesthdtredttdertdenucfhrhhomhepvfgrshhs ihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpe dujedtheduvdelffejkeetgedvheelhedvueefhfeukeekkeehvdfggeegffevgfenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnod hmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedv leekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Mar 2023 05:22:53 -0400 (EDT) In-reply-to: <87mt4dn8qi.fsf@web.de> 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:143040 Archived-At: Michael Heerdegen writes: >> Hm, but then it would be pretty specific to `switch-to-buffer' >> instead of a general `read-buffer-function'. E.g., I just found out >> it's quite convienient to be able to use `append-to-buffer' to append >> to a buffer whose file I haven't found already but is in >> recentf-list. > > Depends on what you want of course. It doesn't make sense for > everything (not for `kill-buffer' for example). Good point (although it doesn't really hurt). I now made my function a bit customizable depending on `this-command'. --8<---------------cut here---------------start------------->8--- (defconst th/read-buffer-or-recentf-command-alist "Alist with entries of the form (CMD . COMPLETES). COMPLETES is a list defining what's completed where entries can be: - `buffers': completion for all buffers - `buffers-except': completion for all buffers except the current one - `recentf': completion for recent files which will be found on demand" '((kill-buffer buffers) (switch-to-buffer buffers-except recentf) (pop-to-buffer buffers-except recentf))) (defun th/read-buffer-or-recentf (prompt &optional def require-match predicate) (let* ((tables (or (mapcar (lambda (syms) (pcase syms ('buffers #'internal-complete-buffer) ('buffers-except (internal-complete-buffer-except (current-buffer))) ('recentf (completion-table-dynamic (lambda (s) recentf-list))) (unknown (error "Unknown case %S" unknown)))) (cdr (assoc this-command th/read-buffer-or-recentf-command-alist))) (list #'internal-complete-buffer (completion-table-dynamic (lambda (s) recentf-list))))) (completion-table (apply #'completion-table-in-turn tables))) ;; Bind minibuffer-setup-hook to nil so that we can be sure our completion ;; table is used. `read-buffer-to-switch' (called by `switch-to-buffer') ;; sets `internal-complete-buffer' using `minibuffer-with-setup-hook' ;; before `read-buffer-function' is invoked by `read-buffer', so we'd be ;; restricted to buffers. (let ((minibuffer-setup-hook nil)) (when-let ((result (completing-read prompt completion-table 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)))))) (setopt read-buffer-function #'th/read-buffer-or-recentf) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo