Script for one-Emacs-frame editing of files

September 2, 2010

This script allows you to edit files in one, and only one, Emacs frame (window). Save this as an executable somewhere in your path (i.e. as ~/bin/e).

#!/bin/bash
export GDK_NATIVE_WINDOWS=1
if [ "$(pgrep emacs)" ]
then
  exec emacsclient -n "$@" 2>/dev/null
else
  exec emacs "$@" & disown
fi

In addition, you have to call (server-start) in your .emacs file.

You can call this script as an executable (don’t forget to run chmod 755 ~/bin/e) from anywhere you like (e.g. e ~/myfile.txt), and it will open the file for editing in a new or existing Emacs frame. If you call this in a terminal, it won’t wait for the Emacs server, but will immediately return to your terminal session.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.