From 28f17b91b44e007f02d3e267208cdf5036999380 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 4 Feb 2023 13:04:14 -0500 Subject: [PATCH] common/home-manager: make fish and emacs play nice Signed-off-by: Xe Iaso --- common/home-manager/emacs/default.nix | 12 ++++++++- common/home-manager/emacs/xe-tools.el | 18 +++++++++++-- common/home-manager/fish/default.nix | 39 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/common/home-manager/emacs/default.nix b/common/home-manager/emacs/default.nix index 23adc29..1dc72f5 100644 --- a/common/home-manager/emacs/default.nix +++ b/common/home-manager/emacs/default.nix @@ -32,6 +32,7 @@ in { (setq inhibit-startup-screen t) (menu-bar-mode -1) + (tab-bar-mode 1) (electric-pair-mode) @@ -140,7 +141,7 @@ in { (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*"))) (setq dashboard-banner-logo-title "Have you ever been far even as decided to use even go want to do look more like?") ;(add-to-list 'dashboard-items '(agenda) t) - (setq dashboard-week-agenda t) + ;(setq dashboard-week-agenda t) ''; }; @@ -542,6 +543,15 @@ in { pname = "xe-tools"; src = ./xe-tools.el; }); + + bindStar = { + "C-s c" = "xe/tabnew-shell"; + "C-a c" = "xe/tabnew-shell"; + "C-s h" = "split-window-vertically"; + "C-a h" = "split-window-vertically"; + "C-s v" = "split-window-horizontally"; + "C-a v" = "split-window-horizontally"; + }; }; }; }; diff --git a/common/home-manager/emacs/xe-tools.el b/common/home-manager/emacs/xe-tools.el index 9cbc98b..d6cc16d 100644 --- a/common/home-manager/emacs/xe-tools.el +++ b/common/home-manager/emacs/xe-tools.el @@ -1,3 +1,8 @@ +;;; xe-tools --- Xe's tools + +;;; Commentary: + +;;; Code: (defun xe/count-buffers (&optional display-anyway) "Display or return the number of buffers." (interactive) @@ -6,14 +11,23 @@ (message "%d buffers in this Emacs" buf-count)) buf-count)) (defun xe/look-of-disapproval () - "Just in case we need this" + "Just in case we need this." (interactive) (insert "ಠ_ಠ")) (defun xe/enable-minor-mode (my-pair) - "Enable minor mode if filename match the regexp. MY-PAIR is a cons cell (regexp . minor-mode)." + "Enable minor mode if filename match the regexp. MY-PAIR is a cons +cell (regexp . minor-mode)." (if (buffer-file-name) (if (string-match (car my-pair) buffer-file-name) (funcall (cdr my-pair))))) +(defun xe/tabnew-shell () + "Opens a shell in a new tab (tmux Control-b c)." + (tab-bar-new-tab 1) + (vterm) + (evil-set-initial-state 'vterm-mode 'emacs) + (rename-uniquely)) + (provide 'xe-tools) +;;; xe-tools.el ends here diff --git a/common/home-manager/fish/default.nix b/common/home-manager/fish/default.nix index 1d9fa40..2e60d9e 100644 --- a/common/home-manager/fish/default.nix +++ b/common/home-manager/fish/default.nix @@ -16,6 +16,20 @@ in { function fish_greeting;end ''; + ".config/fish/functions/vterm_printf.fish".text = '' + function vterm_printf; + if begin; [ -n "$TMUX" ] ; and string match -q -r "screen|tmux" "$TERM"; end + # tell tmux to pass the escape sequences through + printf "\ePtmux;\e\e]%s\007\e\\" "$argv" + else if string match -q -- "screen*" "$TERM" + # GNU screen (screen, screen-256color, screen-256color-bce) + printf "\eP\e]%s\007\e\\" "$argv" + else + printf "\e]%s\e\\" "$argv" + end + end + ''; + ".config/fish/functions/fish_prompt.fish".source = ./fish_prompt.fish; ".config/fish/functions/fish_right_prompt.fish".source = ./fish_right_prompt.fish; @@ -59,6 +73,31 @@ in { # Set GPG TTY set -x GPG_TTY (tty) ''; + + ".config/fish/conf.d/emacs.fish".text = '' + if [ "$INSIDE_EMACS" = 'vterm' ] + function clear + vterm_printf "51;Evterm-clear-scrollback"; + tput clear; + end + + function e + vterm_printf "51;Efind-file"; + end + + function vterm_prompt_end; + vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd) + end + functions --copy fish_prompt vterm_old_fish_prompt + function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.' + # Remove the trailing newline from the original prompt. This is done + # using the string builtin from fish, but to make sure any escape codes + # are correctly interpreted, use %b for printf. + printf "%b" (string join "\n" (vterm_old_fish_prompt)) + vterm_prompt_end + end + end + ''; }; home.packages = [ pkgs.fishPlugins.foreign-env ];