From 3dc1582585d1e0405e214bd4e07fee8c1a66e27a Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Tue, 24 Jun 2025 18:53:38 +0700 Subject: [PATCH] emacs: joe/project-vterm and joe/project-silent-shell-command with binding --- .config/emacs/init.org | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index 8c71b41..09a8eb3 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -551,6 +551,19 @@ Ligatures... are they that useful? (message "No region selected"))) (define-key ctl-x-x-map (kbd "a") #'joe/get-ascii-in-region) + +(defun joe/project-silent-shell-command (command) + (interactive (list (or (bound-and-true-p joe/shell-command-silent-default) + (read-string "Shell command: ")))) + (let* ((project-root (when (project-current) + (project-root (project-current)))) + (default-directory (or project-root default-directory)) + (exit-code (call-process-shell-command command nil nil))) + (unless (zerop exit-code) + (message "Command failed: %s in %s (project: %s) -> exit: %d" + command default-directory project-root exit-code)))) + +(global-set-key (kbd "C-M-r") #'joe/project-silent-shell-command) #+end_src ** Text @@ -1475,6 +1488,22 @@ These are functions to load a project specific file given the conventions I use. (when (project-current) (dirvish-dwim (project-root (project-current))))) +(defun joe/project-vterm () + "Start an inferior shell in the current project's root directory. +If a buffer already exists for running a shell in the project's root, +switch to it. Otherwise, create a new shell buffer. +With \\[universal-argument] prefix arg, create a new inferior shell buffer even +if one already exists." + (interactive) + (require 'comint) + (let* ((default-directory (project-root (project-current t))) + (default-project-shell-name (project-prefixed-buffer-name "shell")) + (shell-buffer (get-buffer default-project-shell-name))) + (if (and shell-buffer (not current-prefix-arg)) + (if (comint-check-proc shell-buffer) + (pop-to-buffer shell-buffer (bound-and-true-p display-comint-buffer-action)) + (vterm shell-buffer)) + (vterm (generate-new-buffer-name default-project-shell-name))))) (evil-define-key 'normal joe/evil-space-mode-map (kbd "_") #'joe/project-dirvish-dwim) (define-key project-prefix-map "t" #'joe/project-open-project-todo) @@ -1482,7 +1511,7 @@ These are functions to load a project specific file given the conventions I use. (define-key project-prefix-map "n" #'joe/project-open-project-notes) (define-key project-prefix-map "r" #'joe/project-open-project-readme) (define-key project-prefix-map "l" #'joe/project-open-project-license) -(define-key project-prefix-map "s" #'eat-project) +(define-key project-prefix-map "s" #'joe/project-vterm) (define-key project-prefix-map "S" #'eat-project-other-window) ;; Remape this (define-key project-prefix-map "C-r" #'project-query-replace-regexp)