Add modules/tools/{dired,eshell}

This commit is contained in:
Henrik Lissner 2017-02-19 18:53:38 -05:00
parent b2c8c432ba
commit 8c173b0a1a
5 changed files with 272 additions and 0 deletions

View file

@ -0,0 +1,119 @@
;;; emacs/eshell/autoload/eshell.el
(require 'eshell)
;;;###autoload
(defun +eshell/run ()
"Open eshell in the current buffer."
(interactive)
(let ((buf (generate-new-buffer eshell-buffer-name)))
(with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
(pop-to-buffer-same-window buf)))
;;;###autoload
(defun +eshell/popup ()
"Open eshell in a popup window."
(interactive)
(let ((buf (get-buffer-create "*eshell:popup*")))
(with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
(doom-popup-buffer buf)))
;;;###autoload
(defun +eshell/tab ()
"Open eshell in a separate workspace. Requires the (:feature workspaces)
module to be loaded."
(interactive)
(unless (@featurep :feature workspaces)
(user-error ":feature workspaces is required, but disabled"))
(unless (+workspace-get "eshell" t)
(+workspace/new "eshell"))
(if-let (buf (cl-find-if (lambda (it) (string-match-p "^\\*eshell" (buffer-name (window-buffer it))))
(doom-visible-windows)))
(select-window (get-buffer-window buf))
(+eshell/run))
(doom/workspace-display))
(defun +eshell--outside-prompt-p (&optional offset)
(< (point) eshell-last-output-end))
(defun +eshell--current-git-branch ()
(let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
when (string-match "^\*" match)
collect match))))
(if (not (eq branch nil))
(concat " [" (substring branch 2) "]")
"")))
;;;###autoload
(defun +eshell/split ()
(interactive)
(select-window (split-window-vertically))
(+eshell:run))
;;;###autoload
(defun +eshell/vsplit ()
(interactive)
(select-window (split-window-horizontally))
(+eshell:run))
;;;###autoload
(defun +eshell/prompt ()
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
(propertize (+eshell--current-git-branch) 'face 'font-lock-function-name-face)
(propertize " λ " 'face 'font-lock-constant-face)))
;;;###autoload
(defun +eshell/evil-append ()
(interactive)
(goto-char eshell-last-output-end)
(call-interactively 'evil-append-line))
;;;###autoload
(defun +eshell/evil-append-maybe ()
(interactive)
(if (+eshell--outside-prompt-p)
(+eshell/evil-append)
(call-interactively 'evil-append)))
;;;###autoload
(defun +eshell/evil-prepend ()
(interactive)
(goto-char eshell-last-output-end)
(call-interactively 'evil-insert))
;;;###autoload
(defun +eshell/evil-prepend-maybe ()
(interactive)
(if (+eshell--outside-prompt-p)
(+eshell/evil-prepend)
(call-interactively 'evil-insert)))
;;;###autoload
(defun +eshell/evil-replace-maybe ()
(interactive)
(if (+eshell--outside-prompt-p)
(user-error "Cannot edit read-only region")
(call-interactively 'evil-replace)))
;;;###autoload
(defun +eshell/evil-replace-state-maybe ()
(interactive)
(if (+eshell--outside-prompt-p)
(user-error "Cannot edit read-only region")
(call-interactively 'evil-replace-state)))
;;;###autoload
(defun +eshell/evil-change ()
(interactive)
(when (+eshell--outside-prompt-p)
(goto-char eshell-last-output-end))
(call-interactively 'evil-change))
;;;###autoload
(defun +eshell/evil-change-line ()
(interactive)
(when (+eshell--outside-prompt-p)
(goto-char eshell-last-output-end))
(call-interactively 'evil-change-line))

View file

@ -0,0 +1,9 @@
;;; emacs/eshell/autoload/evil.el
;;;###autoload (autoload '+eshell:run "emacs/eshell/autoload/evil" nil t)
(evil-define-command +eshell:run (command bang)
(interactive "<fsh><!>")
(if bang
(+eshell/run)
(+eshell/popup)))