41fd8c7b11bf9986e56b5d552db6d23713861cf9
[zsh.git] / .zsh / 65_Editor.zsh
1 # -*- mode: sh;-*-
2 # Setup EDITOR
3 mkdir -p $ZDOTDIR/run/
4
5 __ () {
6 local -a editors
7 local editor
8 editors=(
9 "emacs-snapshot -Q -D -nw" # Fast emacs
10 "emacs24 -Q -D -nw" # Fast emacs
11 "emacs23 -Q -D -nw" # Fast emacs
12 "emacs22 -Q -D -nw" # Fast emacs
13 "mcedit" #
14 "vim" "vi" # vi
15 "editor") # fallback
16 for editor in $editors; do
17 (( $+commands[$editor[(w)1]] )) && {
18 # Some programs may not like to have arguments
19 if [[ $editor == *\ * ]]; then
20 export EDITOR=$ZDOTDIR/run/editor-$HOST-$UID
21 cat <<EOF >| $EDITOR
22 #!/bin/sh
23 exec $editor "\$@"
24 EOF
25 chmod +x $EDITOR
26 else
27 export EDITOR=$editor
28 fi
29 break
30 }
31 done
32 } && __
33
34 [[ -z $EDITOR ]] || {
35 alias e=$EDITOR
36 # Maybe use emacsclient?
37 (( $+commands[emacsclient] )) && {
38 export ALTERNATE_EDITOR=$EDITOR
39 export EDITOR=$ZDOTDIR/run/eeditor-$HOST-$UID
40 cat <<EOF >| $EDITOR
41 #!/bin/sh
42 exec emacsclient -t "\$@"
43 EOF
44 chmod +x $EDITOR
45 # Maybe with -n
46 alias e="emacsclient -t"
47 }
48 }
49
50 unset VISUAL