From 4882df48470205eee65861457816506b3dd07e0b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 9 Dec 2015 01:17:08 -0500 Subject: [PATCH] Redo tmux library + ex commands --- core/lib/defuns-term.el | 52 ++++++++++++++++++++++++++++++++++------- private/my-commands.el | 5 +++- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/core/lib/defuns-term.el b/core/lib/defuns-term.el index a7741125d..ba7e56af3 100644 --- a/core/lib/defuns-term.el +++ b/core/lib/defuns-term.el @@ -1,21 +1,55 @@ ;;; defuns-tmux.el -(defun narf--send-to-tmux (command) - (shell-command (format "tmux send-keys %s" command))) +;;;###autoload +(defun tmux (command &optional run) + (shell-command (format (concat "tmux send-keys " (if run "C-u %s Enter" "%s")) + (shell-quote-argument command)))) (evil-define-interactive-code "" "Ex tmux argument (a mix between and )" :ex-arg shell (list (when (evil-ex-p) (evil-ex-file-arg)))) -;;;###autoload (autoload 'narf:send-to-tmux "defuns-term" nil t) -(evil-define-command narf:send-to-tmux (command &optional bang) +;;;###autoload (autoload 'narf:tmux-cd "defuns-term" nil t) +(evil-define-command narf:tmux-cd (&optional bang) + (interactive "") + (if bang + (narf/tmux-cd-to-project) + (narf/tmux-cd-to-here))) + +;;;###autoload (autoload 'narf:tmux "defuns-term" nil t) +(evil-define-operator narf:tmux (beg end &optional command bang) "Sends input to tmux. Use `bang' to append to tmux" - (interactive "") - (narf--send-to-tmux (format (if bang "%s" "C-u %s Enter") - (shell-quote-argument command))) - (when (evil-ex-p) - (message "[Tmux] %s" command))) + :type inclusive + :repeat t + (interactive "") + (if (not command) + (os-switch-to-term) + (when (use-region-p) + (setq command (concat command (buffer-substring-no-properties beg end)))) + (tmux command bang) + (when (evil-ex-p) + (message "[Tmux] %s" command)))) + +;;;###autoload +(defun narf/tmux-new-window () + (interactive) + (tmux "tmux new-window" t)) + +;;;###autoload +(defun narf/tmux-split-window (&optional vertical) + (interactive) + (tmux (concat "tmux split-window" (if vertical " -h")))) + +;;;###autoload +(defun narf/tmux-cd-to-here (&optional dir) + (interactive) + (tmux (format "cd '%s'" (or dir default-directory)))) + +;;;###autoload +(defun narf/tmux-cd-to-project () + (interactive) + (narf/tmux-cd-to-here (narf/project-root))) (provide 'defuns-tmux) ;;; defuns-tmux.el ends here diff --git a/private/my-commands.el b/private/my-commands.el index 3150bb4e3..38cff5106 100644 --- a/private/my-commands.el +++ b/private/my-commands.el @@ -47,7 +47,10 @@ (exmap "@" 'narf/evil-macro-on-all-lines) (exmap "t[mux]" 'narf:send-to-tmux) -(exmap "tcd" (λ (narf:send-to-tmux (format "cd '%s'" default-directory)))) +(exmap "t[mux]w" 'narf/tmux-new-window) +(exmap "t[mux]s" 'narf/tmux-split-window) +(exmap "t[mux]v" (λ (narf/tmux-split-window t))) +(exmap "tcd" 'narf:tmux-cd) (exmap "cont[act]" 'narf:org-crm-contact) (exmap "proj[ect]" 'narf:org-crm-project)