aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-06-17 17:40:02 +1000
committerYuchen Pei <id@ypei.org>2023-06-17 17:40:02 +1000
commit2445425165e761e0f2c1aa78372259a6fe302a22 (patch)
tree66f77f95f83056a0de95e4a4159219a3f3cac964
parent093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 (diff)
Adding a function to switch or create a shell buffer
-rw-r--r--emacs/.emacs.d/init/ycp-prog.el1
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el17
2 files changed, 18 insertions, 0 deletions
diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el
index 9ab868b..4e2daf5 100644
--- a/emacs/.emacs.d/init/ycp-prog.el
+++ b/emacs/.emacs.d/init/ycp-prog.el
@@ -82,6 +82,7 @@
'(shell-mode . my-shell-with-directory))
(my-keybind shell-mode-map "<f2>" #'my-restart-shell)
(add-hook 'shell-mode-hook 'my-shell-disable-company-if-remote)
+ (my-keybind global-map "<f10>" #'my-switch-or-create-shell-buffer)
)
(my-package eshell
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index 6b7c705..210d7ef 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -138,5 +138,22 @@ some of the references to the identifiers."
(toggle-debug-on-error))
)
+(require 'my-buffer)
+
+(defun my-switch-or-create-shell-buffer (arg)
+ "Switch to or create a shell buffer.
+
+If there's no buffer with shell mode, or with a prefix-arg,
+create a shell buffer using `my-shell-with-directory'"
+ (interactive "P")
+ (if (or arg
+ (not (seq-filter
+ (lambda (buffer)
+ (with-current-buffer buffer
+ (derived-mode-p 'shell-mode)))
+ (buffer-list))))
+ (call-interactively 'my-shell-with-directory)
+ (my-buffer-quick-major-mode 'shell-mode)))
+
(provide 'my-prog)
;;; my-prog.el ends here