summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorAndrii Kolomoiets <andreyk.mad@gmail.com>2020-06-19 02:21:55 +0300
committerDmitry Gutov <dgutov@yandex.ru>2020-06-19 03:44:01 +0300
commit6fe5c21c723c1ebf1d4df911761d14c47970262f (patch)
tree77f3f3d76e688bc38b57e69289fcf1624a647493 /lisp
parentfbf40c1d903d18286ecd7d2c1d7b117c88a1d5dd (diff)
downloademacs-6fe5c21c723c1ebf1d4df911761d14c47970262f.tar.gz
project-switch-to-buffer: Use the "other buffer" as default
* lisp/progmodes/project.el (project-switch-to-buffer): Pass the "other buffer" as DEF to read-buffer if it belongs to the current project (bug#41879).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/project.el22
1 files changed, 16 insertions, 6 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 7a41df614b9..89dcee97fa9 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -777,14 +777,24 @@ Arguments the same as in `compile'."
(defun project-switch-to-buffer ()
"Switch to a buffer in the current project."
(interactive)
- (let ((root (project-root (project-current t))))
+ (let* ((root (project-root (project-current t)))
+ (current-buffer (current-buffer))
+ (other-buffer (other-buffer current-buffer))
+ (other-name (buffer-name other-buffer))
+ (predicate
+ (lambda (buffer)
+ ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
+ (and (not (eq (cdr buffer) current-buffer))
+ (when-let ((file (buffer-local-value 'default-directory
+ (cdr buffer))))
+ (file-in-directory-p file root))))))
(switch-to-buffer
(read-buffer
- "Switch to buffer: " nil t
- (lambda (buffer)
- ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
- (when-let ((file (buffer-file-name (cdr buffer))))
- (file-in-directory-p file root)))))))
+ "Switch to buffer: "
+ (when (funcall predicate (cons other-name other-buffer))
+ other-name)
+ t
+ predicate))))
(defcustom project-kill-buffers-skip-conditions
'("\\*Help\\*")