new layer: shell

This commit is contained in:
syl20bnr 2015-05-20 22:39:14 -04:00
parent 2f69991510
commit d681234a71
9 changed files with 269 additions and 90 deletions

97
contrib/shell/README.md Normal file
View File

@ -0,0 +1,97 @@
# Shell contribution layer for Spacemacs
![logo](img/shell.png)
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**
- [Shell contribution layer for Spacemacs](#shell-contribution-layer-for-spacemacs)
- [Description](#description)
- [Install](#install)
- [Layer](#layer)
- [Default shell](#default-shell)
- [Default shell position and height](#default-shell-position-and-height)
- [Set shell for term and ansi-term](#set-shell-for-term-and-ansi-term)
- [Key bindings](#key-bindings)
<!-- markdown-toc end -->
## Description
This layer configures the various shells available in Emacs.
## Install
### Layer
To use this contribution add it to your `~/.spacemacs`
```elisp
(setq-default dotspacemacs-configuration-layers '(shell))
```
### Default shell
Emacs supports three types of shell:
- the Emacs shell
- the inferior shell
- the terminal emulator
- the ANSI terminal emulator
You can find a quick introductions to them [here][mastering-emacs]
To define the default shell you can set the layer variable `shell-default-shell`
to the following variables:
- `eshell`
- `shell`
- `term`
- `ansi-term`
```elisp
(setq-default dotspacemacs-configuration-layers
'(shell :variables shell-default-shell eshell))
```
The default shell is quickly accessible via a the default shortcut key
<kbd>SPC ;</kbd>.
### Default shell position and height
It is possible to choose where the shell should pop by setting the variable
`shell-default-position` to either `top`, `bottom` or `full`. It is not
possible to show it on the side for now.
Default value is `bottom`.
It is also possible to set the default height in percents with the variable
`shell-default-height`. Default value is `30`.
```elisp
(setq-default dotspacemacs-configuration-layers
'(shell :variables
shell-default-position bottom
shell-default-height 30))
```
### Set shell for term and ansi-term
The default shell can be set by setting the variable `shell-default-term-shell`.
Default value is `/bin/bash`.
```elisp
(setq-default dotspacemacs-configuration-layers
'(shell :variables shell-default-term-shell "/bin/bash"))
```
## Key bindings
Key Binding | Description
---------------------|------------------------------------------------------------
<kbd>SPC ;</kbd> | Open, close or go to the default shell
<kbd>SPC a s e</kbd> | Open, close or go to an `eshell`
<kbd>SPC a s i</kbd> | Open, close or go to a `shell`
<kbd>SPC a s t</kbd> | Open, close or go to a `term`
**Note** You can open multiple shells using a numerical prefix argument,
for instance pressing <kbd>2 SPC ;</kbd> will a second default shell, the
number of shell is indicated on the mode-line.
[mastering-emacs]: https://www.masteringemacs.org/article/running-shells-in-emacs-overview

26
contrib/shell/config.el Normal file
View File

@ -0,0 +1,26 @@
;;; config.el --- shell configuration File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Variables
(defvar shell-default-shell 'eshell
"Default shell to use in Spacemacs. Possible values are `eshell', `shell',
`term' and `ansi-term'.")
(defvar shell-default-position 'bottom
"Position of the shell. Possible values are `top', `bottom' and `full'.")
(defvar shell-default-height 30
"Height in percents for the shell window.")
(defvar shell-default-term-shell "/bin/bash"
"Default shell to use in `term' and `ansi-term' shells.")

BIN
contrib/shell/img/shell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

122
contrib/shell/packages.el Normal file
View File

@ -0,0 +1,122 @@
;;; packages.el --- shell packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq shell-packages
'(
helm
shell
shell-pop
term
))
(defun shell/post-init-helm ()
(spacemacs|use-package-add-hook helm
:post-config
(progn
(defun spacemacs//shell-helm-post-:config ()
"Configuration to append to helm package `:config' block."
;; eshell
(defun spacemacs/helm-eshell-history ()
"Correctly revert to insert state after selection."
(interactive)
(helm-eshell-history)
(evil-insert-state))
(defun spacemacs/helm-shell-history ()
"Correctly revert to insert state after selection."
(interactive)
(helm-comint-input-ring)
(evil-insert-state))
(defun spacemacs/init-helm-eshell ()
"Initialize helm-eshell."
;; this is buggy for now
;; (define-key eshell-mode-map (kbd "<tab>") 'helm-esh-pcomplete)
(evil-leader/set-key-for-mode 'eshell-mode
"mH" 'spacemacs/helm-eshell-history))
(add-hook 'eshell-mode-hook 'spacemacs/init-helm-eshell)
;;shell
(evil-leader/set-key-for-mode 'shell-mode
"mH" 'spacemacs/helm-shell-history))))
)
(defun spacemacs/init-shell ()
(defun shell-comint-input-sender-hook ()
"Check certain shell commands.
Executes the appropriate behavior for certain commands."
(setq comint-input-sender
(lambda (proc command)
(cond
;; Check for clear command and execute it.
((string-match "^[ \t]*clear[ \t]*$" command)
(comint-send-string proc "\n")
(erase-buffer))
;; Check for man command and execute it.
((string-match "^[ \t]*man[ \t]*" command)
(comint-send-string proc "\n")
(setq command (replace-regexp-in-string "^[ \t]*man[ \t]*" "" command))
(setq command (replace-regexp-in-string "[ \t]+$" "" command))
(funcall 'man command))
;; Send other commands to the default handler.
(t (comint-simple-send proc command))))))
(defun eshell/clear ()
"Clear contents in eshell."
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)))
(add-hook 'shell-mode-hook 'shell-comint-input-sender-hook)
(add-hook 'eshell-mode-hook (lambda ()
(setq pcomplete-cycle-completions nil))))
(defun shell/init-shell-pop ()
(use-package shell-pop
:defer t
:init
(progn
(setq shell-pop-window-position shell-default-position
shell-pop-window-height shell-default-height
shell-pop-term-shell shell-default-term-shell)
(defmacro make-shell-pop-command (type &optional shell)
(let* ((name (symbol-name type)))
`(defun ,(intern (concat "shell-pop-" name)) (index)
(interactive "P")
(require 'shell-pop)
(shell-pop--set-shell-type
'shell-pop-shell-type
(backquote (,name
,(concat "*" name "*")
(lambda nil (funcall ',type ,shell)))))
(shell-pop index))))
(make-shell-pop-command eshell)
(make-shell-pop-command shell)
(make-shell-pop-command term shell-pop-term-shell)
(make-shell-pop-command ansi-term shell-pop-term-shell)
(defun spacemacs/default-pop-shell ()
"Open the default shell in a popup."
(interactive)
(call-interactively (intern (format "shell-pop-%S" shell-default-shell))))
(evil-leader/set-key
";" 'spacemacs/default-pop-shell
"ase" 'shell-pop-eshell
"asi" 'shell-pop-shell
"ast" 'shell-pop-term
"asT" 'shell-pop-ansi-term))))
(defun shell/init-term ()
(defun term-send-tab ()
"Send tab in term mode."
(interactive)
(term-send-raw-string "\t"))
;; hack to fix pasting issue, the paste micro-state won't
;; work in term
(evil-define-key 'normal term-raw-map "p" 'term-paste)
(evil-define-key 'insert term-raw-map (kbd "C-c C-d") 'term-send-eof)
(evil-define-key 'insert term-raw-map (kbd "<tab>") 'term-send-tab))

View File

@ -124,8 +124,7 @@ initialization."
(spacemacs/load-or-install-package 'use-package t)
;; inject use-package hooks for easy customization of
;; stock package configuration
;; waiting for the fix to be merged upstream
;; (setq use-package-inject-hooks t)
(setq use-package-inject-hooks t)
;; evil and evil-leader must be installed at the beginning of the
;; boot sequence.
;; Use C-u as scroll-up (must be set before actually loading evil)

View File

@ -48,4 +48,26 @@ override lazy-loaded settings."
(push `(add-hook ',hook (lambda nil ,@body)) expanded-forms)))))
`(progn ,@expanded-forms)))
;; Temporary fix until #213 is merged upstream
(eval-after-load 'use-package
'(defun use-package-hook-injector (name-string keyword body)
"Wrap pre/post hook injections around a given keyword form.
ARGS is a list of forms, so `((foo))' if only `foo' is being called."
(if (not use-package-inject-hooks)
(use-package-expand name-string (format "%s" keyword) body)
(let ((keyword-name (substring (format "%s" keyword) 1)))
(when body
`((when ,(macroexp-progn
(use-package-expand name-string (format "pre-%s hook" keyword)
`((run-hook-with-args-until-failure
',(intern (concat "use-package--" name-string
"--pre-" keyword-name "-hook"))))))
,(macroexp-progn
(use-package-expand name-string (format "%s" keyword) body))
,(macroexp-progn
(use-package-expand name-string (format "post-%s hook" keyword)
`((run-hooks
',(intern (concat "use-package--" name-string
"--post-" keyword-name "-hook")))))))))))))
(provide 'core-use-package-ext)

View File

@ -24,6 +24,7 @@
;; git-gutter-use-fringe t)
;; markdown
;; org
;; shell
;; syntax-checking
)
;; List of additional packages that will be installed wihout being

View File

@ -48,8 +48,6 @@
"ac" 'calc-dispatch
"ad" 'dired
"ap" 'proced
"ase" 'shell-pop-eshell
"asi" 'shell-pop-shell
"au" 'undo-tree-visualize)
;; buffers --------------------------------------------------------------------
(evil-leader/set-key

View File

@ -79,7 +79,6 @@
leuven-theme
linum-relative
move-text
multi-term
neotree
page-break-lines
popup
@ -89,8 +88,6 @@
rainbow-delimiters
recentf
rfringe
shell
shell-pop
smartparens
smooth-scrolling
subword
@ -1468,26 +1465,6 @@ ARG non nil means that the editing style is `vim'."
(define-key helm-map (kbd "C-l") 'helm-recenter-top-bottom-other-window))))
(spacemacs//helm-hjkl-navigation (eq 'vim dotspacemacs-editing-style))
;; eshell
(defun spacemacs/helm-eshell-history ()
"Correctly revert to insert state after selection."
(interactive)
(helm-eshell-history)
(evil-insert-state))
(defun spacemacs/helm-shell-history ()
"Correctly revert to insert state after selection."
(interactive)
(helm-comint-input-ring)
(evil-insert-state))
(defun spacemacs/init-helm-eshell ()
"Initialize helm-eshell."
;; this is buggy for now
;; (define-key eshell-mode-map (kbd "<tab>") 'helm-esh-pcomplete)
(evil-leader/set-key-for-mode 'eshell-mode "mH" 'spacemacs/helm-eshell-history))
(add-hook 'eshell-mode-hook 'spacemacs/init-helm-eshell)
;;shell
(evil-leader/set-key-for-mode 'shell-mode "mH" 'spacemacs/helm-shell-history)
(defun spacemacs/helm-edit ()
"Switch in edit mode depending on the current helm buffer."
(interactive)
@ -1981,24 +1958,6 @@ Put (global-hungry-delete-mode) in dotspacemacs/config to enable by default."
("J" move-text-down)
("K" move-text-up))))
(defun spacemacs/init-multi-term ()
(use-package multi-term
:defer t
:init
(evil-leader/set-key "ast" 'multi-term)
:config
(progn
(defun term-send-tab ()
"Send tab in term mode."
(interactive)
(term-send-raw-string "\t"))
;; hack to fix pasting issue, the paste micro-state won't
;; work in multi-term
(evil-define-key 'normal term-raw-map "p" 'term-paste)
(evil-define-key 'insert term-raw-map (kbd "C-c C-d") 'term-send-eof)
(evil-define-key 'insert term-raw-map (kbd "<tab>") 'term-send-tab))))
(defun spacemacs/init-neotree ()
(use-package neotree
:defer t
@ -2576,51 +2535,6 @@ It is a string holding:
(use-package rfringe
:defer t))
(defun spacemacs/init-shell ()
(defun shell-comint-input-sender-hook ()
"Check certain shell commands.
Executes the appropriate behavior for certain commands."
(setq comint-input-sender
(lambda (proc command)
(cond
;; Check for clear command and execute it.
((string-match "^[ \t]*clear[ \t]*$" command)
(comint-send-string proc "\n")
(erase-buffer))
;; Check for man command and execute it.
((string-match "^[ \t]*man[ \t]*" command)
(comint-send-string proc "\n")
(setq command (replace-regexp-in-string "^[ \t]*man[ \t]*" "" command))
(setq command (replace-regexp-in-string "[ \t]+$" "" command))
(funcall 'man command))
;; Send other commands to the default handler.
(t (comint-simple-send proc command))))))
(defun eshell/clear ()
"Clear contents in eshell."
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)))
(add-hook 'shell-mode-hook 'shell-comint-input-sender-hook)
(add-hook 'eshell-mode-hook (lambda ()
(setq pcomplete-cycle-completions nil))))
(defun spacemacs/init-shell-pop ()
(use-package shell-pop
:defer t
:init
(defmacro make-shell-pop-command (type &optional shell)
(let* ((name (symbol-name type)))
`(defun ,(intern (concat "shell-pop-" name)) (index)
(interactive "P")
(require 'shell-pop)
(shell-pop--set-shell-type 'shell-pop-shell-type (backquote (,name
,(concat "*" name "*")
(lambda nil (funcall ',type ,shell)))))
(shell-pop index))))
(make-shell-pop-command eshell)
(make-shell-pop-command shell)
(make-shell-pop-command term shell-pop-term-shell)))
(defun spacemacs/init-smartparens ()
(use-package smartparens
:defer t