Skip to content

Instantly share code, notes, and snippets.

@tasmo
Forked from alexmurray/ec
Created April 25, 2017 15:25
Show Gist options
  • Select an option

  • Save tasmo/aeca8eaaf6e82f02215e65909403f3f5 to your computer and use it in GitHub Desktop.

Select an option

Save tasmo/aeca8eaaf6e82f02215e65909403f3f5 to your computer and use it in GitHub Desktop.

Revisions

  1. tasmo revised this gist Apr 25, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ec
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash
    #!/usr/bin/env bash

    # Shamelessly taken from http://mjwall.com/blog/2013/10/04/how-i-use-emacs/

  2. @alexmurray alexmurray revised this gist Feb 8, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ec
    Original file line number Diff line number Diff line change
    @@ -47,4 +47,4 @@ else # there is already a visible frame besides the daemon, so
    change_focus
    # -n $@ errors if there are no args
    test "$#" -ne "0" && emacsclient -n "$@"
    fi
    fi
  3. @alexmurray alexmurray revised this gist Feb 8, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ec
    Original file line number Diff line number Diff line change
    @@ -42,8 +42,9 @@ test "$(visible_frames)" -eq "1" && change_focus
    if [ "$(visible_frames)" -lt "2" ]; then # need to create a frame
    # -c $@ with no args just opens the scratch buffer
    emacsclient -n -c "$@" && change_focus
    emacsclient -n -e "(apm-graphic-frame-init)" > /dev/null
    else # there is already a visible frame besides the daemon, so
    change_focus
    # -n $@ errors if there are no args
    test "$#" -ne "0" && emacsclient -n "$@"
    fi
    fi
  4. Alex Murray created this gist Dec 8, 2014.
    49 changes: 49 additions & 0 deletions ec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/bin/bash

    # Shamelessly taken from http://mjwall.com/blog/2013/10/04/how-i-use-emacs/

    # This script starts emacs daemon if it is not running, opens whatever file
    # you pass in and changes the focus to emacs. Without any arguments, it just
    # opens the current buffer or *scratch* if nothing else is open. The following
    # example will open ~/.bashrc

    # ec ~/.bashrc

    # You can also pass it multiple files, it will open them all. Unbury-buffer
    # will cycle through those files in order

    # The compliment to the script is et, which opens emacs in the terminal
    # attached to a daemon

    # If you want to execute elisp, pass in -e whatever.
    # You may also want to stop the output from returning to the terminal, like
    # ec -e "(message \"Hello\")" > /dev/null

    # emacsclient options for reference
    # -a "" starts emacs daemon and reattaches
    # -c creates a new frame
    # -n returns control back to the terminal
    # -e eval the script

    # Number of current visible frames,
    # Emacs daemon always has a visible frame called F1
    visible_frames() {
    emacsclient -a "" -e '(length (visible-frame-list))'
    }

    change_focus() {
    emacsclient -n -e "(select-frame-set-input-focus (selected-frame))" > /dev/null
    }

    # try switching to the frame incase it is just minimized
    # will start a server if not running
    test "$(visible_frames)" -eq "1" && change_focus

    if [ "$(visible_frames)" -lt "2" ]; then # need to create a frame
    # -c $@ with no args just opens the scratch buffer
    emacsclient -n -c "$@" && change_focus
    else # there is already a visible frame besides the daemon, so
    change_focus
    # -n $@ errors if there are no args
    test "$#" -ne "0" && emacsclient -n "$@"
    fi