0

I'm using, OS X, and mainly terminal and emacsclient.

When I do shell stuff, I background my emacsclient with Control-Z

Someties I forget whether i've done that, and end up spawning additional emacsclient sessions, which I don;t want to do.

It would be cool if the bash prompt can tell me whether emacsclient jobs up in the jobs output

american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80
  • emacs.stackexchange.com would probably be a better place for a question like this. – Barmar Jan 21 '16 at 18:08
  • the question applies to any terminal application, its just that in this case i was using emacsclient as an example – american-ninja-warrior Jan 21 '16 at 18:09
  • OK, then unix.stackexchange.com or superuser.com would be better places to ask. – Barmar Jan 21 '16 at 18:19
  • Why don't you use `emacsclient -n` so it just exits immediately instead of waiting? – Barmar Jan 21 '16 at 18:20
  • i don't see how emacsclient -n can help. perhaps you're misunderstanding @Barmar. – american-ninja-warrior Jan 21 '16 at 18:22
  • let me clarify a bit further: on any os, when you minimize an application, you get an indication of it in the task bar (windows) or in the dock icon (OS X) . So I'm trying to achieve something similar in the terminal. My bash prompt should say something like (foo)$ when bash detects there's backgrounded applications backgrounded with Ctl-z – american-ninja-warrior Jan 21 '16 at 18:25
  • That tells it not to wait for you to do `server-exit` in Emacs, so you don't have any emacsclient sessions hanging around. – Barmar Jan 21 '16 at 18:25
  • @Barmar, `-n` makes sense if you're launching a GUI emacsclient from the terminal, but not if you're using the terminal UI. – jpkotta Jan 21 '16 at 21:18

2 Answers2

1

Minimal example for bash, using sleep instead of emacsclient.

PS1="\`if jobs | grep -q sleep; then echo 'sleep jobs' ; else echo 'no sleep jobs' ; fi\`\\\$ "

You might want to filter on stopped jobs (jobs -s).

You can get fancier by echoing escape sequences instead of just strings to colorize it.

jpkotta
  • 9,237
  • 3
  • 29
  • 34
0

While I think @jpkota provides a workable answer, I wonder if maybe your worrying too much. Provided emacsclient is working OK, there is no problem with having multiple emacsclient sessions running at once - in fact, it is sort of designed to do that. The emacsclient connections are light-weight and if there is a chance you might need to use the same file/buffer again, you may as well keep them around and just open new ones when needed and get rid of the ones you don't think you will need. The whole benefit of emacscleint is that opening new windows/buffers is really fast and if you use the GUI verison, they just pop up in their own window.

There is also a package in elpa which may be useful called osx-pseudo-daemon, which addresses a problem that can occur if you close all emacsclient windows which prevents the main emacs from responding (this is when yu run emacs from launchctl.

What I tend to do is run emacsclient in GUI mode rather than inside a terminal. When I run emacsclient I put it in the background so that it doesn't block my terminal and use the -c flag.(I actually have a shell script which makes this easy - see http://emacsformacosx.com/tips for some ideas. I leave the emacsclient window open and just switch to it if I need to do some emacs editing etc.

Tim X
  • 4,158
  • 1
  • 20
  • 26