(define-derived-mode shoe-mode
fundamental-mode "Shoe"
"Auto-paging shell mode..
\\{shoe-mode-map}"
(linum-mode -1))
(defconst shoe-dir "~/.shoe")
(defvar shoe-shell-program "/bin/bash")
(define-key shoe-mode-map (kbd "RET") 'shoe-run-at-point)
(define-key shoe-mode-map (kbd "C-c C-k") 'shoe-clear)
(defun shoe-clear ()
(interactive))
(defun shoe-run-at-point ()
"Run whatever is there at the point."
(interactive)
(let* ((timestamp (shoe-timestamp))
(run (let ((dir (concat shoe-dir "/" timestamp)))
(progn (make-directory dir t)
dir)))
(process-name (concat "shoe:" timestamp))
(script-file-name (concat run "/script.sh"))
(stdout-file-name (concat run "/stdout"))
(stderr-file-name (concat run "/stderr"))
(process-buffer (current-buffer)))
(write-region (line-beginning-position) (line-end-position) script-file-name nil :do-nothing)
(let* ((process (make-process
:name process-name
:buffer process-buffer
:filter 'shoe-filter
:sentinel 'shoe-sentinel
:connection-type 'pty
:command (list shoe-shell-program
"-c"
(concat shoe-shell-program
" " script-file-name
" 1>" stdout-file-name
" 2>" stderr-file-name))))
(timer (run-with-idle-timer 1 t 'shoe-refresh process))
(start-marker (make-marker))
(end-marker (make-marker)))
(set-marker-insertion-type start-marker nil)
(set-marker-insertion-type end-marker t)
(save-excursion
(insert "\n")
(set-marker start-marker (point))
(set-marker end-marker (point))
(insert "\n"))
(process-put process 'run run)
(process-put process 'start-marker start-marker)
(process-put process 'end-marker end-marker)
(process-put process 'timer timer)
(goto-char (point-max)))))
(defun shoe-refresh (process &optional extra)
(let* ((run (process-get process 'run))
(stdout-file-name (concat run "/stdout"))
(stderr-file-name (concat run "/stderr"))
(stdout-output (shell-command-to-string (concat "tail -n 5 " stdout-file-name)))
(stderr-output (shell-command-to-string (concat "tail -n 5 " stderr-file-name))))
(shoe-page-output process stdout-output stderr-output extra)))
(defun shoe-filter (&rest args))
(defun shoe-sentinel (process status)
(cancel-timer (process-get process 'timer))
(shoe-refresh process status))
(defun shoe-page-output (process stdout stderr &optional extra)
(with-current-buffer (process-buffer process)
(save-excursion
(let* ((start (marker-position (process-get process 'start-marker)))
(end (1- (marker-position (process-get process 'end-marker)))))
(delete-region start end)
(goto-char start)
(insert (concat
(propertize stdout 'face 'zenburn-blue)
(propertize stderr 'face 'zenburn-red)
(propertize (or extra "")
'face 'zenburn-green)))))))
(defun shoe ()
"Open a shoe-mode buffer."
(interactive)
(with-current-buffer (get-buffer-create "*shoe*")
(shoe-mode)
(switch-to-buffer-other-window (current-buffer))
nil))
(defun shoe-timestamp ()
"Get the current timestamp."
(format-time-string "%Y%0m%0d/%0H%0M%0S-%0N"))
(provide 'shoe)
shoe.el
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.