From 88e4fb8cb886db2cabc40c0014dd60bc2e77490e Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Fri, 10 Apr 2026 11:03:18 +0200 Subject: [PATCH] Add project terminal launchers for Emacs --- .../desktop/.emacs.d/lisp/core/keybindings.el | 3 ++ .../.emacs.d/lisp/misc/custom-functions.el | 36 +++++++++++++++++++ .../desktop/.emacs.d/lisp/misc/terminal.el | 30 +++++++++++++++- .../desktop/.emacs.d/lisp/misc/which-key.el | 7 ++-- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el b/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el index 52bedd0..0eb9501 100644 --- a/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el +++ b/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el @@ -83,6 +83,9 @@ (with-eval-after-load 'projectile (define-key projectile-command-map (kbd "v") #'fscotto/project-vterm) + (define-key projectile-command-map (kbd "V") #'fscotto/project-multi-vterm) + (define-key projectile-command-map (kbd "x") #'fscotto/project-external-terminal) + (define-key projectile-command-map (kbd "a") #'fscotto/project-opencode) (define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status)) ;;;; LSP diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el index 0080e00..6f81b9d 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el @@ -23,6 +23,42 @@ (let ((default-directory (fscotto/project-root))) (vterm))) +(defun fscotto/project-multi-vterm () + "Open a new multi-vterm buffer in project root." + (interactive) + (let ((default-directory (fscotto/project-root))) + (multi-vterm))) + +(defun fscotto/launch-external-terminal (&optional command) + "Launch external terminal in project root, optionally running COMMAND." + (let* ((default-directory (file-name-as-directory (fscotto/project-root))) + (terminal-program (or (executable-find fscotto/external-terminal-program) + fscotto/external-terminal-program)) + (args (append + (list fscotto/external-terminal-working-directory-option + default-directory) + (when command + (append + (list fscotto/external-terminal-execute-option) + command))))) + (unless (file-executable-p terminal-program) + (user-error "External terminal not found: %s" fscotto/external-terminal-program)) + (apply #'start-process + "fscotto-external-terminal" + nil + terminal-program + args))) + +(defun fscotto/project-external-terminal () + "Open the external terminal in project root." + (interactive) + (fscotto/launch-external-terminal)) + +(defun fscotto/project-opencode () + "Open the external terminal in project root and run opencode." + (interactive) + (fscotto/launch-external-terminal '("opencode"))) + (defun fscotto/project-magit-status () "Open magit-status in project root." (interactive) diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/terminal.el b/dotfiles/desktop/.emacs.d/lisp/misc/terminal.el index 814c325..53d612f 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/terminal.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/terminal.el @@ -1,4 +1,32 @@ -;;; terminal.el -*- +;;; terminal.el -*- lexical-binding: t; -*- + +(defgroup fscotto nil + "Personal customization group." + :group 'applications) + +(defcustom fscotto/external-terminal-program "alacritty" + "Program used to launch external terminal windows." + :type 'string + :group 'fscotto) + +(defcustom fscotto/external-terminal-working-directory-option "--working-directory" + "Argument used to set the working directory for the external terminal." + :type 'string + :group 'fscotto) + +(defcustom fscotto/external-terminal-execute-option "-e" + "Argument used to execute a command in the external terminal." + :type 'string + :group 'fscotto) (use-package vterm :ensure t) + +(use-package multi-vterm + :ensure t + :after vterm + :commands (multi-vterm multi-vterm-next multi-vterm-prev)) + +(provide 'terminal) + +;;; terminal.el ends here diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el b/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el index 798f6c7..a034e80 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el @@ -141,13 +141,14 @@ ;; Actions "C-c p c" "Compile" "C-c p t" "Test" - "C-c p v" "Open term in project" + "C-c p v" "Open vterm in project" + "C-c p V" "Open multi-vterm in project" + "C-c p x" "Open external term" + "C-c p a" "Open opencode" "C-c p e" "Edit project config" "C-c p g" "Project Git status" - "C-c p x" "Open Terminal" "C-c p 4" "Other Window" "C-c p 5" "Other Frame" - "C-c p x 4" "Other Window" ;; Cache "C-c p i" "Invalidate cache")