WorkWithEmacsclient

CosmonauT edited this page Mar 4, 2015 · 3 revisions

If Emacs is invoked by emacslient from a command line, raise the emacs window. After press C-x #, the window turn auto back.


First: Add follow code to your .stumpwmrc

    (defvar *es-win* nil
      "to hold the windo called emacsclient")
    (defun save-es-called-win ()
      (setf *es-win* (current-window)))

    (defun return-es-called-win (win)
      (let* ((group (window-group win))
             (frame (window-frame win))
            (old-frame (tile-group-current-frame group)))
        (frame-raise-window group frame win)
        (focus-all win)
        (unless (eq frame old-frame)
          (show-frame-indicator group))))

Second: In you .emacs you have to include

    (add-hook 'after-init-hook 'server-start)
    (setq server-raise-frame t)

    (if window-system
        (add-hook 'server-done-hook
                  (lambda () (shell-command "stumpish 'eval (stumpwm::return-es-called-win stumpwm::*es-win*)'"))))

Third:

    cat > ~/bin/es << EOF
    #!/bin/sh

    stumpish 'eval (stumpwm::save-es-called-win)' > /dev/null
    emacsclient --alternate-editor=$ALTERNATE_EDITOR "$@"
    EOF

For example: You edit or view a file with command $: es xxxx, the emacs will raise up and after you finish with `C-x #' the window will turn back.

And you may set default editor to es.


    export EDITOR=es
    export ALTERNATE_EDITOR=vi
    export VISUAL=es

Note from Ejlflop (that's me!):

You may need to edit the es command (~/bin/es) and remove the backslash in "$@" Also, if you want to open a new emacs frame rather than reuse an existing one (which may involve a bit of tedious application switching, change "emacsclient" to "emacsclient -c".

If you are using the Firefox extension "ItsAllText", you may also want to set its editor to the "es" command -- it seemed to work fine when I did it.

Note: also, there is stumpmacs stumpwm module: https://gitorious.org/dss-project/stumpmacs/