3

I am an emacs user and have written a few emacs configuration files.

I wanted to run the client-server feature of emacs using a single bash script that would take care of the emacs server and client. The script runs the server (if not already running) and then follows it up by running the client in the desired frame (terminal or graphic).

I have soft-linked the executable script to /usr/bin/emacs (overriding the default) so that running the emacs command does the job for me. The command emacs now fires up the script from the terminal as well as via Alt+F2. The problem is, binding a keyboard shortcut to the same command (or the script) doesn't work.

I am attaching the screenshot of my shortcut here. enter image description here

The shell script can be found here.

P.S.: The keyboard shortcut runs fine when /usr/bin/emacs is linked to the default emacs executable (at /etc/alternatives/emacs in my case).

2
  • 1
    Have you tried emacsclient -c -a “” it automatically spawns a daemon if it's not found. If it founds a running daemon it doesn't get past the -c and connects to it
    – Umar Ahmad
    Oct 10, 2015 at 3:14
  • It sure works! Not sure how I missed it out on the man page. Will integrate this command in my script. :) Oct 10, 2015 at 6:18

1 Answer 1

2

I tried recreating your issue and I guess I got close.

The problem I figured out that you're facing is with the if [[ -t 1 ]] condition.

According to tldp

This test option may be used to check whether the stdin [ -t 0 ] or stdout [ -t 1 ] in a given script is a terminal.

So, the script will not be able to detect the program that invoked it via this conditional. Hence, this is not the accurate solution to your problem.

Now, internally, the keybindings in Ubuntu are executed via a fake terminal. In fact, the TERM variable is set to dumb, when a command via the keybindings is run.

So, to solve your problem, you could use the following code.

if [ $TERM == "dumb" ]
then
        TERMINAL=false
        CREATE="-c"
else
        TERMINAL=true
        CREATE="-nw"
fi

I can not guarantee that it will work in all the cases, but it works for the usage you described.
Hope it helps. :)

1
  • Though now I am facing a different issue, but it doesn't belong in the askubuntu network. Will post the link in the comments when I post it in the emacs network. Oct 13, 2015 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .