diff -r 2495ee9cf84c -r bda24877724a .emacs-my --- a/.emacs-my Mon Jul 25 11:38:25 2022 +0300 +++ b/.emacs-my Wed Oct 12 00:14:04 2022 +0300 @@ -703,6 +703,26 @@ (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *") +(defun my-term-send-smart () + "Sends a selection or a paragraph to `term-mode'." + (interactive) + (let (beg end cmd term) + (if (use-region-p) + (setq cmd (buffer-substring (region-beginning) (region-end))) + (save-excursion + (forward-paragraph -1) + (setq beg (point)) + (forward-paragraph 1) + (setq end (point)) + (setq cmd (string-trim (buffer-substring beg end))))) + (save-window-excursion ; term command switches buffers. + (term (or explicit-shell-file-name "bash")) + (setq term (current-buffer))) + (display-buffer term 'display-buffer-use-some-window) + (term-simple-send (get-buffer-process term) cmd))) + +(global-set-key (kbd "s-t") 'my-term-send-smart) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (message "proced")