diff options
author | Aaron LI <aaronly.me@gmail.com> | 2016-02-21 14:18:57 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@gmail.com> | 2016-02-21 14:18:57 +0800 |
commit | 0357d0421ed361bf71aea7e18bc383809cba0495 (patch) | |
tree | fe91449da218575bdb2ab8ce62be9ef93d7858de | |
parent | 1428ae9601af08b58f9c25e9763b6af2bb899eae (diff) | |
download | dotfiles-0357d0421ed361bf71aea7e18bc383809cba0495.tar.bz2 |
zsh: add zsh/emacs.zsh
-rw-r--r-- | _zsh/emacs.zsh | 37 | ||||
-rw-r--r-- | _zshrc | 5 |
2 files changed, 40 insertions, 2 deletions
diff --git a/_zsh/emacs.zsh b/_zsh/emacs.zsh new file mode 100644 index 0000000..501ddb2 --- /dev/null +++ b/_zsh/emacs.zsh @@ -0,0 +1,37 @@ +# +# zsh/emacs.zsh +# +# Credits: +# https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/emacs +# +# 2016-02-21 +# + +function _emacsclient() { + # Get list of available X windows. + X=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null` + + if [ -z "$X" ] || [ "$X" = "nil" ]; then + # Create one if there is no X window yet. + command emacsclient --alternate-editor "" --create-frame "$@" + else + # Prevent creating another X frame if there is at least one present. + command emacsclient --alternate-editor "" "$@" + fi +} + +alias emacs='_emacsclient -t' +alias e=emacs +# Same as 'M-x eval' but outside of Emacs +alias eeval='_emacsclient --eval' +# Create a new X frame +alias eframe='_emacsclient --create-frame --no-wait' + +# Write to stdout the path to the file opened in the current buffer +function efile() { + local cmd="(buffer-file-name (window-buffer))" + _emacsclient --eval "$cmd" | tr -d '"' +} + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # @@ -19,7 +19,7 @@ ## ## Aaron LI ## Created: 2014-05-31 -## Updated: 2016-01-30 +## Updated: 2016-02-21 ## @@ -31,10 +31,11 @@ source ~/.zsh/prompt.zsh source ~/.zsh/completion.zsh source ~/.zsh/aliases.zsh source ~/.zsh/bindkeys.zsh -source ~/.zsh/vi-mode.zsh source ~/.zsh/functions.zsh source ~/.zsh/history.zsh source ~/.zsh/hooks.zsh +source ~/.zsh/vi-mode.zsh +source ~/.zsh/emacs.zsh ## Local configurations [ -r ~/.zshrc.local ] && source ~/.zshrc.local |