emacs.plugin.zsh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Emacs 23 daemon capability is a killing feature.
  2. # One emacs process handles all your frames whether
  3. # you use a frame opened in a terminal via a ssh connection or X frames
  4. # opened on the same host.
  5. # Benefits are multiple
  6. # - You don't have the cost of starting Emacs all the time anymore
  7. # - Opening a file is as fast as Emacs does not have anything else to do.
  8. # - You can share opened buffered across opened frames.
  9. # - Configuration changes made at runtime are applied to all frames.
  10. if "$ZSH/tools/require_tool.sh" emacsclient 24 2>/dev/null ; then
  11. export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh"
  12. # set EDITOR if not already defined.
  13. export EDITOR="${EDITOR:-${EMACS_PLUGIN_LAUNCHER}}"
  14. alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
  15. alias e=emacs
  16. # open terminal emacsclient
  17. alias te="$EMACS_PLUGIN_LAUNCHER -nw"
  18. # same than M-x eval but from outside Emacs.
  19. alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
  20. # create a new X frame
  21. alias eframe='emacsclient --alternate-editor "" --create-frame'
  22. # Emacs ANSI Term tracking
  23. if [[ -n "$INSIDE_EMACS" ]]; then
  24. chpwd_emacs() { print -P "\033AnSiTc %d"; }
  25. print -P "\033AnSiTc %d" # Track current working directory
  26. print -P "\033AnSiTu %n" # Track username
  27. # add chpwd hook
  28. autoload -Uz add-zsh-hook
  29. add-zsh-hook chpwd chpwd_emacs
  30. fi
  31. # Write to standard output the path to the file
  32. # opened in the current buffer.
  33. function efile {
  34. local cmd="(buffer-file-name (window-buffer))"
  35. "$EMACS_PLUGIN_LAUNCHER" --eval "$cmd" | tr -d \"
  36. }
  37. # Write to standard output the directory of the file
  38. # opened in the the current buffer
  39. function ecd {
  40. local cmd="(let ((buf-name (buffer-file-name (window-buffer))))
  41. (if buf-name (file-name-directory buf-name)))"
  42. local dir="$($EMACS_PLUGIN_LAUNCHER --eval $cmd | tr -d \")"
  43. if [ -n "$dir" ] ;then
  44. echo "$dir"
  45. else
  46. echo "can not deduce current buffer filename." >/dev/stderr
  47. return 1
  48. fi
  49. }
  50. fi
  51. ## Local Variables:
  52. ## mode: sh
  53. ## End: