Emacs - add shell-command-output mode
authorPeng Li <seudut@gmail.com>
Fri, 15 Sep 2017 14:55:49 +0000 (22:55 +0800)
committerPeng Li <seudut@gmail.com>
Fri, 15 Sep 2017 14:55:49 +0000 (22:55 +0800)
emacs.d/config.org
emacs.d/elisp/shell-command-output-mode.el [new file with mode: 0644]

index 10d8c9a..1347079 100644 (file)
@@ -3142,6 +3142,19 @@ Kill the help window and buffer when quit.
 
   ;; (advice-add 'man :after (lambda (man-args) (other-window 1)))
   (advice-add 'man :after (apply-partially 'other-window 1))
+
+
+  (require 'shell-command-output-mode)
+
+  (defun my/shell-command-after (command &optional output-buffer error-buffer)
+    (let* ((buffer (get-buffer "*Shell Command Output*"))
+           (window (get-buffer-window buffer)))
+      (if buffer (with-current-buffer buffer
+                   (shell-command-output-mode)))
+      (if window
+          (select-window window))))
+
+  (advice-add 'shell-command :after 'my/shell-command-after)
 #+END_SRC
 
 ** Motion
diff --git a/emacs.d/elisp/shell-command-output-mode.el b/emacs.d/elisp/shell-command-output-mode.el
new file mode 100644 (file)
index 0000000..451e121
--- /dev/null
@@ -0,0 +1,53 @@
+;; ;;; shell-command-output-mode.el --- A major mode for shell command output buffer  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017  Peng Li
+
+;; Author: Peng Li <seudut@gmail.com>
+;; Keywords: 
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Nothing
+
+;;; Code:
+
+;; (defun haha/delet-window ()
+;;   (interactive)
+;;   (quit-window t))
+
+(defvar shell-command-output-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "q") (lambda () (interactive) (quit-window t)))
+    map)
+  "Keymap used in shell-command-output-mode mode")
+
+(defcustom shell-command-output-mode-hook nil
+  "Hook run when shell command output mode is enabled"
+  :type 'hook
+  :group 'shell-command-outut)
+
+;;;###autoload
+(define-derived-mode shell-command-output-mode fundamental-mode "shell-command-output" ""
+  (use-local-map shell-command-output-mode-map)
+  (setq buffer-read-only t)
+  ;; enable evil motion state for this mode
+  (if (and (boundp evil-mode) (fboundp 'evil-motion-state))
+      (progn (add-to-list 'evil-motion-state-modes 'shell-command-output-mode)
+            (evil-motion-state)))
+  )
+
+(provide 'shell-command-output-mode)
+;;; shell-command-output-mode.el ends here