From 0a56b3ffb55df2b6b07daffb4ceebda02c702f6e Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 29 Apr 2013 07:59:51 +0300 Subject: [PATCH] Extract prelude-start-or-switch-to --- core/prelude-core.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/prelude-core.el b/core/prelude-core.el index e3e0748..653f08c 100644 --- a/core/prelude-core.el +++ b/core/prelude-core.el @@ -268,13 +268,16 @@ buffer is not visiting a file." (file-writable-p buffer-file-name)) (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))) -(defun prelude-switch-or-start (function buffer) - "If BUFFER is current, bury it, otherwise invoke FUNCTION." - (if (equal (buffer-name (current-buffer)) buffer) - (bury-buffer) - (if (get-buffer buffer) - (switch-to-buffer buffer) - (funcall function)))) +(defun prelude-start-or-switch-to (function buffer-name) + "Invoke FUNCTION if there is no buffer with BUFFER-NAME. +Otherwise switch to the buffer named BUFFER-NAME. Don't clobber +the current buffer." + (if (not (get-buffer buffer-name)) + (progn + (split-window-sensibly (selected-window)) + (other-window 1) + (funcall function)) + (switch-to-buffer-other-window buffer-name))) (defun prelude-insert-date () "Insert a timestamp according to locale's date and time format."