emacs.plugin.zsh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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" emacs 23 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. # same than M-x eval but from outside Emacs.
  17. alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
  18. # create a new X frame
  19. alias eframe='emacsclient --alternate-editor "" --create-frame'
  20. # to code all night long
  21. alias emasc=emacs
  22. alias emcas=emacs
  23. # Write to standard output the path to the file
  24. # opened in the current buffer.
  25. function efile {
  26. local cmd="(buffer-file-name (window-buffer))"
  27. "$EMACS_PLUGIN_LAUNCHER" --eval "$cmd" | tr -d \"
  28. }
  29. # Write to standard output the directory of the file
  30. # opened in the the current buffer
  31. function ecd {
  32. local cmd="(let ((buf-name (buffer-file-name (window-buffer))))
  33. (if buf-name (file-name-directory buf-name)))"
  34. local dir="$($EMACS_PLUGIN_LAUNCHER --eval $cmd | tr -d \")"
  35. if [ -n "$dir" ] ;then
  36. echo "$dir"
  37. else
  38. echo "can not deduce current buffer filename." >/dev/stderr
  39. return 1
  40. fi
  41. }
  42. fi
  43. ## Local Variables:
  44. ## mode: sh
  45. ## End: