Browse Source

emacs.el: Add function term-shell-command

pull/1/head
10sr 10 years ago
parent
commit
cea1dfee18
1 changed files with 53 additions and 0 deletions
  1. +53
    -0
      emacs.el

+ 53
- 0
emacs.el View File

@@ -2212,6 +2212,59 @@ ARG is ignored."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; x open ;; x open


(defvar term-shell-command-history nil
"History for term-shell-command.")
(defun my-term-shell-command (command &optional buffer-or-name)
"Run COMMAND in terminal emulator.
If BUFFER-OR-NAME is given, use this buffer. In this case, old process in the
buffer is destroyed. Otherwise, new buffer is generated automatically from
COMMAND."
(interactive (list (read-shell-command "Run program: "
nil
'term-shell-command-history)))
(let* ((name (car (split-string command
" ")))
(buf (if buffer-or-name
(get-buffer-create buffer-or-name)
(generate-new-buffer (concat "*"
name
"*"))))
(proc (get-buffer-process buf))
(dir default-directory))
(and proc
(delete-process proc))
(display-buffer buf)
(with-current-buffer buf
(cd dir)
(set (make-local-variable 'term-scroll-to-bottom-on-output)
t)
(let ((inhibit-read-only t))
(goto-char (point-max))
(insert "\n")
(insert "Start executing "
command)
(add-text-properties (point-at-bol)
(point-at-eol)
'(face bold))
(insert "\n\n"))
(require 'term)
(term-mode)
(term-exec buf
(concat "term-" name)
shell-file-name
nil
(list shell-command-switch
command))
(term-char-mode)
(if (ignore-errors (get-buffer-process buf))
(set-process-sentinel (get-buffer-process buf)
(lambda (proc change)
(with-current-buffer (process-buffer proc)
(term-sentinel proc change)
(goto-char (point-max)))))
;; (goto-char (point-max))
))))

(defvar my-filer nil) (defvar my-filer nil)
(setq my-filer (or (executable-find "pcmanfm") (setq my-filer (or (executable-find "pcmanfm")
(executable-find "nautilus"))) (executable-find "nautilus")))


Loading…
Cancel
Save