From cea1dfee1865fd13086e27f733e1e7d1c87e5916 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Tue, 9 Dec 2014 15:02:53 +0900 Subject: [PATCH 1/3] emacs.el: Add function term-shell-command --- emacs.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/emacs.el b/emacs.el index 1d5f8a9..3b69712 100644 --- a/emacs.el +++ b/emacs.el @@ -2212,6 +2212,59 @@ ARG is ignored." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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) (setq my-filer (or (executable-find "pcmanfm") (executable-find "nautilus"))) From 9d05fd578d2fdb871388a1684b4685a9dfd7eb31 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Tue, 9 Dec 2014 17:04:38 +0900 Subject: [PATCH 2/3] Add help to view command --- emacs.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/emacs.el b/emacs.el index 3b69712..49ea6e7 100644 --- a/emacs.el +++ b/emacs.el @@ -953,7 +953,9 @@ found, otherwise returns nil." ;; for git-command new version (when (boundp 'git-command-view-command-list) (add-to-list 'git-command-view-command-list - "graph")) + "graph") + (add-to-list 'git-command-view-command-list + "help")) (when (boundp 'git-command-aliases-alist) ;; (message "new version of git-command!") (add-to-list 'git-command-aliases-alist From 5abe5befb97eac279209e40f6f5177bd690f7956 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Tue, 9 Dec 2014 18:10:14 +0900 Subject: [PATCH 3/3] Add function my-git-apply-index-from-buffer --- emacs.el | 66 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/emacs.el b/emacs.el index 49ea6e7..fb0df93 100644 --- a/emacs.el +++ b/emacs.el @@ -2214,6 +2214,48 @@ ARG is ignored." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; x open +(defvar my-filer nil) +(setq my-filer (or (executable-find "pcmanfm") + (executable-find "nautilus"))) +(defun my-x-open (file) + "open FILE." + (interactive "FOpen File: ") + (setq file (expand-file-name file)) + (message "Opening %s..." file) + (cond ((eq system-type 'windows-nt) + (call-process "cmd.exe" nil 0 nil + "/c" "start" "" (convert-standard-filename file))) + ((eq system-type 'darwin) + (call-process "open" nil 0 nil file)) + ((getenv "DISPLAY") + (call-process (or my-filer "xdg-open") nil 0 nil file)) + (t + (find-file file)) + ) + ;; (recentf-add-file file) + (message "Opening %s...done" file)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; misc funcs + +(defun my-git-apply-index-from-buffer (&optional buf) + "Git apply buffer. BUF is buffer to apply. nil to use current buffer." + (interactive) + (let ((buf (or buf + (current-buffer))) + (file (make-temp-file "git-apply-diff.emacs"))) + (with-current-buffer buf + (write-region (point-min) + (point-max) + file) + (call-process "git" + nil + nil + nil + "apply" + "--cached" + file)))) + (defvar term-shell-command-history nil "History for term-shell-command.") (defun my-term-shell-command (command &optional buffer-or-name) @@ -2267,30 +2309,6 @@ COMMAND." ;; (goto-char (point-max)) )))) -(defvar my-filer nil) -(setq my-filer (or (executable-find "pcmanfm") - (executable-find "nautilus"))) -(defun my-x-open (file) - "open FILE." - (interactive "FOpen File: ") - (setq file (expand-file-name file)) - (message "Opening %s..." file) - (cond ((eq system-type 'windows-nt) - (call-process "cmd.exe" nil 0 nil - "/c" "start" "" (convert-standard-filename file))) - ((eq system-type 'darwin) - (call-process "open" nil 0 nil file)) - ((getenv "DISPLAY") - (call-process (or my-filer "xdg-open") nil 0 nil file)) - (t - (find-file file)) - ) - ;; (recentf-add-file file) - (message "Opening %s...done" file)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; misc funcs - (defun memo (&optional dir) "Open memo.txt in DIR." (interactive)