emacs.plugin.zsh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # Write to standard output the path to the file
  23. # opened in the current buffer.
  24. function efile {
  25. local cmd="(buffer-file-name (window-buffer))"
  26. "$EMACS_PLUGIN_LAUNCHER" --eval "$cmd" | tr -d \"
  27. }
  28. # Write to standard output the directory of the file
  29. # opened in the the current buffer
  30. function ecd {
  31. local cmd="(let ((buf-name (buffer-file-name (window-buffer))))
  32. (if buf-name (file-name-directory buf-name)))"
  33. local dir="$($EMACS_PLUGIN_LAUNCHER --eval $cmd | tr -d \")"
  34. if [ -n "$dir" ] ;then
  35. echo "$dir"
  36. else
  37. echo "can not deduce current buffer filename." >/dev/stderr
  38. return 1
  39. fi
  40. }
  41. fi
  42. ## Local Variables:
  43. ## mode: sh
  44. ## End: