summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/basic.el b/basic.el
index b2ab6d0..aa087f1 100644
--- a/basic.el
+++ b/basic.el
@@ -527,6 +527,43 @@ Don't ask me to confirm my choice. --- Durand"
(define-key global-map (vector ?\s-Z) #'undo-only)
+;;; Don't create a scratch buffer
+
+(defun durand-read-buffer-to-switch (prompt)
+ "Read the name of a buffer to switch to, prompting with PROMPT.
+Return the name of the buffer as a string.
+
+This function is intended for the `switch-to-buffer' family of
+commands since these need to omit the name of the current buffer
+from the list of completions and default values.
+
+Modified to stop creating a buffer, when there is only one buffer
+left. --- 2022-11-17 22:56:20.746698"
+ (let ((rbts-completion-table (internal-complete-buffer-except))
+ (default-buffer (other-buffer (current-buffer))))
+ (cond
+ ((string= (buffer-name default-buffer) "*scratch*")
+ (kill-buffer default-buffer)
+ (setq default-buffer (current-buffer))))
+ (minibuffer-with-setup-hook
+ (lambda ()
+ (setq minibuffer-completion-table rbts-completion-table)
+ ;; Since rbts-completion-table is built dynamically, we
+ ;; can't just add it to the default value of
+ ;; icomplete-with-completion-tables, so we add it
+ ;; here manually.
+ (if (and (boundp 'icomplete-with-completion-tables)
+ (listp icomplete-with-completion-tables))
+ (setq-local icomplete-with-completion-tables
+ (cons rbts-completion-table
+ icomplete-with-completion-tables))))
+ (read-buffer
+ prompt default-buffer
+ (confirm-nonexistent-file-or-buffer)))))
+
+(advice-add #'read-buffer-to-switch :override
+ #'durand-read-buffer-to-switch)
+
;;; Save close
;;;###autoload