about summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2017-06-13T15·33-0400
committerWilliam Carroll <wpcarro@gmail.com>2017-06-13T15·33-0400
commit8fff1ba8905256ba8d24c0ae47b5da0eb4efc066 (patch)
treef0828dd229d92d33aba07655f1f2a4fe27c03da7 /emacs
parent6b3d011491bf03033f5e008792d82bc32b1976ea (diff)
Better integrates CLI and Emacsclient
Diffstat (limited to 'emacs')
-rw-r--r--emacs/index.sh24
-rw-r--r--emacs/wc-helper-functions.lisp42
2 files changed, 66 insertions, 0 deletions
diff --git a/emacs/index.sh b/emacs/index.sh
new file mode 100644
index 000000000000..b7bfd6962011
--- /dev/null
+++ b/emacs/index.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env zsh
+
+
+if [ -n "$INSIDE_EMACS" ]; then
+    export PAGER="create-shell-pager.sh"
+else
+    export PAGER="less"
+fi
+
+
+if [ -n "$INSIDE_EMACS" ]; then
+    export EDITOR="emacsclient"
+else
+    export EDITOR=$(which vim)
+fi
+
+
+man () {
+    if [ -n "$INSIDE_EMACS" ]; then
+        emacsclient -e  "(man \"$1\")"
+    else
+        command man "$1"
+    fi
+}
diff --git a/emacs/wc-helper-functions.lisp b/emacs/wc-helper-functions.lisp
index 1d81115e3905..18c7a67e39bd 100644
--- a/emacs/wc-helper-functions.lisp
+++ b/emacs/wc-helper-functions.lisp
@@ -1,3 +1,36 @@
+(defun wc/open-in-pager (file)
+  (find-file file)
+  (emacs-pager-mode))
+
+
+(defvar emacs-pager-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "q") 'kill-this-buffer)
+    map)
+  "Keymap for emacs pager mode.")
+
+
+(defcustom emacs-pager-max-line-coloring 500
+  "Maximum number of lines to ansi-color. If performance is bad when
+   loading data, reduce this number"
+  :group 'emacs-pager)
+
+
+(define-derived-mode emacs-pager-mode fundamental-mode "Pager"
+  "Mode for viewing data paged by emacs-pager"
+  (setq-local make-backup-files nil)
+  (ansi-color-apply-on-region (goto-char (point-min))
+                              (save-excursion
+                                (forward-line emacs-pager-max-line-coloring)
+                                (point)))
+  (setq buffer-name "*pager*")
+  (set-buffer-modified-p nil)
+  (read-only-mode)
+  (evil-define-key 'normal emacs-pager-mode-map
+    (kbd "q") 'kill-this-buffer
+    (kbd "ESC") 'kill-this-buffer))
+
+
 (defun wc/projectile-shell-pop ()
   "Opens `ansi-term' at the project root according to Projectile."
   (interactive)
@@ -29,6 +62,15 @@
       :buffer "*helm projectile terminals*"))
 
 
+(defun wc/git-changed-files ()
+  "Lists active terminal buffers."
+  (interactive)
+  (helm :sources (helm-build-in-buffer-source "test1"
+                 :data ((lambda () (shell-command-to-string "wc-git-changed-files")))
+                 :action 'term-send-raw-string)
+      :buffer "*helm git changed file*"))
+
+
 (defun wc/shell-history ()
   (setq history (shell-command-to-string "history"))
   (split-string history "\n"))