Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. (setq shell:output-pretify-function
  2. (lambda (s)
  3. (let* ((s (replace-regexp-in-string ansi-color-regexp "" s))
  4. (s (replace-regexp-in-string shell-prompt-pattern "" s))
  5. (s (substring-no-properties s 0 (- (length s) 1))))
  6. (replace-regexp-in-string ".* \n" "" s))))
  7.  
  8. (defmacro shell:with-recv-output-sync (&rest body)
  9. (declare (indent 1))
  10. (with-gensyms (r reading-p s)
  11. `(lexical-let* ((,r nil)
  12. (,reading-p t))
  13. (let ((comint-preoutput-filter-functions
  14. (list (lambda (,s)
  15. (cond ((string-match shell-prompt-pattern ,s)
  16. (push (funcall shell:output-pretify-function ,s) ,r)
  17. (setq ,reading-p nil))
  18. (t (push ,s ,r)))
  19. ,s))))
  20. ,@body
  21. (while ,reading-p
  22. (sleep-for 0 100))
  23. (mapconcat 'identity (nreverse ,r) "")))))
  24.  
  25. (defun shell:find-file () (interactive)
  26. (let* ((r (shell:with-recv-output-sync
  27. (let1 p (get-buffer-process (current-buffer))
  28. (comint-simple-send p "pwd"))))
  29. (default-directory (format "%s/" r)))
  30. (call-interactively 'find-file)))
  31.  
  32. (defun shell:find-file/elscreen() (interactive)
  33. (let* ((r (shell:with-recv-output-sync
  34. (let1 p (get-buffer-process (current-buffer))
  35. (comint-simple-send p "pwd"))))
  36. (default-directory (format "%s/" r)))
  37. (call-interactively 'elscreen-find-file)))
  38.  
  39. (add-hook 'shell-mode-hook
  40. (named-lambda shell:find-file-setup
  41. (define-key shell-mode-map "\C-x\C-f" 'shell:find-file)
  42. (when (fboundp 'elscreen-find-file)
  43. (define-key shell-mode-map "\C-c\C-f" 'shell:find-file/elscreen))))
Add Comment
Please, Sign In to add comment