(defun my-quote-function (s) "quote special chars in string" (shell-quote-argument s)) (defun my-input-sender (proc command) "specialized comint-input-sender function with extra quoting" (let ((quoting-regex "my-quote(\\(.*\\))")) (string-match quoting-regex command) (let ((string-to-quote (match-string 1 command))) (if (null string-to-quote) (comint-simple-send proc command) (let ((quoted-string (my-quote-function string-to-quote))) (string-match quoting-regex command) (comint-simple-send proc (replace-match quoted-string t t command))))))) (setq comint-input-sender 'my-input-sender) #### --> echo $foo --> echo my-quote($foo) $foo --> echo "This is not quoted but" my-quote("this") is This is not quoted but "this" is -->