Adds QuickEdit mode for git commit messages within ansi-term
This commit is contained in:
parent
146e2cc3a1
commit
d9a05b322e
2 changed files with 42 additions and 54 deletions
7
bins/bin/edit-file-in-emacs.sh
Executable file
7
bins/bin/edit-file-in-emacs.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#/usr/bin/env zsh
|
||||||
|
|
||||||
|
file=$(mktemp -t "$USER-"XXXXXXXX.emacs-pager) || exit 127
|
||||||
|
trap 'rm -f "$file"' EXIT
|
||||||
|
trap 'exit 255' HUP INT QUIT TERM
|
||||||
|
cat "$@" >"$file"
|
||||||
|
emacsclient -e "(wc/edit-file-in-emacs \"$file\")"
|
|
@ -1,8 +1,43 @@
|
||||||
|
(defun wc/edit-file-in-emacs (file)
|
||||||
|
"Edits a file in a buffer in Emacs. On :wq, the buffer is deleted and the previous term session restored."
|
||||||
|
(find-file file)
|
||||||
|
(quick-edit-file-mode))
|
||||||
|
|
||||||
|
|
||||||
(defun wc/open-in-pager (file)
|
(defun wc/open-in-pager (file)
|
||||||
|
"Opens a file in a simulated pager in emacs."
|
||||||
(find-file file)
|
(find-file file)
|
||||||
(emacs-pager-mode))
|
(emacs-pager-mode))
|
||||||
|
|
||||||
|
|
||||||
|
(defun wc/write-quit-kill-buffer ()
|
||||||
|
"Writes, quits, kills a buffer."
|
||||||
|
(interactive)
|
||||||
|
(save-buffer)
|
||||||
|
(kill-this-buffer))
|
||||||
|
|
||||||
|
|
||||||
|
(defvar quick-edit-file-mode-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(define-key map (kbd "q") 'wc/write-quit-kill-buffer)
|
||||||
|
map)
|
||||||
|
"Keymap for emacs quick-edit file mode.")
|
||||||
|
|
||||||
|
|
||||||
|
(define-derived-mode quick-edit-file-mode fundamental-mode "QuickEdit"
|
||||||
|
"Mode quickly editing files."
|
||||||
|
(setq-local make-backup-files nil)
|
||||||
|
(setq buffer-name "*quick-edit*"))
|
||||||
|
|
||||||
|
|
||||||
|
(defun wc/quick-edit-evil-quit (old-fun &rest args)
|
||||||
|
(if (eq major-mode 'quick-edit-file-mode)
|
||||||
|
(wc/write-quit-kill-buffer)
|
||||||
|
(apply old-fun args)))
|
||||||
|
|
||||||
|
(advice-add #'evil-quit :around #'wc/quick-edit-evil-quit)
|
||||||
|
|
||||||
|
|
||||||
(defvar emacs-pager-mode-map
|
(defvar emacs-pager-mode-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(define-key map (kbd "q") 'kill-this-buffer)
|
(define-key map (kbd "q") 'kill-this-buffer)
|
||||||
|
@ -53,24 +88,6 @@
|
||||||
(remove-if-not #'wc/ansi-term-project-p buffer-names)))
|
(remove-if-not #'wc/ansi-term-project-p buffer-names)))
|
||||||
|
|
||||||
|
|
||||||
(defun wc/open-terminals ()
|
|
||||||
"Lists active terminal buffers."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources (helm-build-in-buffer-source "test1"
|
|
||||||
:data (wc/list-project-terminals)
|
|
||||||
:action 'switch-to-buffer)
|
|
||||||
: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 ()
|
(defun wc/shell-history ()
|
||||||
(setq history (shell-command-to-string "history"))
|
(setq history (shell-command-to-string "history"))
|
||||||
(split-string history "\n"))
|
(split-string history "\n"))
|
||||||
|
@ -81,52 +98,16 @@
|
||||||
(split-string branches "\n"))
|
(split-string branches "\n"))
|
||||||
|
|
||||||
|
|
||||||
(defun wc/helm-git-branches ()
|
|
||||||
"Reverse-I search using Helm."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources (helm-build-in-buffer-source "test1"
|
|
||||||
:data (wc/git-branches)
|
|
||||||
:action 'wc/handle-branch)
|
|
||||||
:buffer "*helm git branches*"))
|
|
||||||
|
|
||||||
|
|
||||||
(defun wc/autojump-directories ()
|
(defun wc/autojump-directories ()
|
||||||
(setq directories (shell-command-to-string "j -s | awk '{ if($2 ~ /^\\// && $1 != \"data:\") print;}' | sort -rn | head -n 100 | awk '{print $2}'"))
|
(setq directories (shell-command-to-string "j -s | awk '{ if($2 ~ /^\\// && $1 != \"data:\") print;}' | sort -rn | head -n 100 | awk '{print $2}'"))
|
||||||
(split-string directories "\n"))
|
(split-string directories "\n"))
|
||||||
|
|
||||||
|
|
||||||
(defun wc/helm-autojump ()
|
|
||||||
"Helm interface to autojump."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources (helm-build-in-buffer-source "test1"
|
|
||||||
:data (wc/autojump-directories)
|
|
||||||
:action (lambda (path) (wc/exec-cmd (format "cd %s" path))))
|
|
||||||
:buffer "*helm git branches*"))
|
|
||||||
|
|
||||||
|
|
||||||
(defun wc/handle-branch (branch)
|
(defun wc/handle-branch (branch)
|
||||||
(setq action "git diff")
|
(setq action "git diff")
|
||||||
(term-send-raw-string (format "%s %s" action branch)))
|
(term-send-raw-string (format "%s %s" action branch)))
|
||||||
|
|
||||||
|
|
||||||
(defun wc/helm-shell-history ()
|
|
||||||
"Reverse-I search using Helm."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources (helm-build-in-buffer-source "test1"
|
|
||||||
:data (wc/shell-history)
|
|
||||||
:action 'wc/exec-cmd)
|
|
||||||
:buffer "*helm shell history*"))
|
|
||||||
|
|
||||||
|
|
||||||
(defun wc/helm-ctrl-t-find-files ()
|
|
||||||
"Fuzzily searches files within a directory."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources (helm-build-in-buffer-source "test1"
|
|
||||||
:data (shell-command-to-string "ag --hidden --ignore .git -l -g \"\"")
|
|
||||||
:action 'term-send-raw-string)
|
|
||||||
:buffer "*helm CTRL_T find files *"))
|
|
||||||
|
|
||||||
|
|
||||||
(defun wc/exec-cmd (cmd)
|
(defun wc/exec-cmd (cmd)
|
||||||
(term-send-raw-string (format "%s\n" cmd)))
|
(term-send-raw-string (format "%s\n" cmd)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue