[Top][All Lists]

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

My read-buffer-function doesn't work when called by switch-to-buffer

From: Tassilo Horn
Subject: My read-buffer-function doesn't work when called by switch-to-buffer
Date: Fri, 10 Mar 2023 22:10:29 +0100
User-agent: mu4e 1.9.22; emacs 30.0.50

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
                      (completion-table-in-turn #'internal-complete-buffer
                                                 (lambda (s) recentf-list)))
                      predicate require-match nil 'buffer-name-history def)))
     ((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?


reply via email to

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