Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setq shell:output-pretify-function
- (lambda (s)
- (let* ((s (replace-regexp-in-string ansi-color-regexp "" s))
- (s (replace-regexp-in-string shell-prompt-pattern "" s))
- (s (substring-no-properties s 0 (- (length s) 1))))
- (replace-regexp-in-string ".* \n" "" s))))
- (defmacro shell:with-recv-output-sync (&rest body)
- (declare (indent 1))
- (with-gensyms (r reading-p s)
- `(lexical-let* ((,r nil)
- (,reading-p t))
- (let ((comint-preoutput-filter-functions
- (list (lambda (,s)
- (cond ((string-match shell-prompt-pattern ,s)
- (push (funcall shell:output-pretify-function ,s) ,r)
- (setq ,reading-p nil))
- (t (push ,s ,r)))
- ,s))))
- ,@body
- (while ,reading-p
- (sleep-for 0 100))
- (mapconcat 'identity (nreverse ,r) "")))))
- (defun shell:find-file () (interactive)
- (let* ((r (shell:with-recv-output-sync
- (let1 p (get-buffer-process (current-buffer))
- (comint-simple-send p "pwd"))))
- (default-directory (format "%s/" r)))
- (call-interactively 'find-file)))
- (defun shell:find-file/elscreen() (interactive)
- (let* ((r (shell:with-recv-output-sync
- (let1 p (get-buffer-process (current-buffer))
- (comint-simple-send p "pwd"))))
- (default-directory (format "%s/" r)))
- (call-interactively 'elscreen-find-file)))
- (add-hook 'shell-mode-hook
- (named-lambda shell:find-file-setup
- (define-key shell-mode-map "\C-x\C-f" 'shell:find-file)
- (when (fboundp 'elscreen-find-file)
- (define-key shell-mode-map "\C-c\C-f" 'shell:find-file/elscreen))))
Add Comment
Please, Sign In to add comment