From: Peng Li Date: Fri, 15 Sep 2017 14:55:49 +0000 (+0800) Subject: Emacs - add shell-command-output mode X-Git-Url: http://47.100.26.94:8080/?a=commitdiff_plain;h=67504d8dfe08cb4c204decc202b4b07b02ad37f7;p=dotfiles.git Emacs - add shell-command-output mode --- diff --git a/emacs.d/config.org b/emacs.d/config.org index 10d8c9a..1347079 100644 --- a/emacs.d/config.org +++ b/emacs.d/config.org @@ -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 index 0000000..451e121 --- /dev/null +++ b/emacs.d/elisp/shell-command-output-mode.el @@ -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 +;; 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 . + +;;; 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