ch11ng / exwm

Emacs X Window Manager
2.85k stars 134 forks source link

I am unable to launch emacsclient in the current workspace #539

Closed prosoitos closed 5 years ago

prosoitos commented 5 years ago

I would like to have 10 workspaces at all time, never more than that. But I don't know how to prevent the creation of new ones.

I have:

(setq exwm-workspace-number 10)
(setq exwm-workspace-switch-create-limit 10)

But many things I do keep creating new ones. For instance, I use Rofi to look for and open files or directory. And those files/directory always open in a new workspace. So if I do this 10 times, I end up with 20 workspaces.

Is there a way to block the creation of new workspaces so that files/directory opened through Rofi would open in the current workspace instead?

Rofi is not the only thing that creates new workspaces. I can't remember right now what else does though. Either way, I always end up with a crazy number of workspaces.

I would love a way to have whatever I do to launch things in the current workspace.

Thank you!!

ch11ng commented 5 years ago

Not sure how you are using rofi but I could not reproduce this issue after playing with this program for a while. So basically after invoking rofi -show run and select an application to run, the window is created right in the current workspace.

prosoitos commented 5 years ago

I do use rofi -show run for applications and indeed, I have no issue with that.

My problem is when I use rofi to open files or directories.

I use a script with the following content:

emacsclient "$(locate home media usr etc run dev var sys proc opt srv | rofi -theme-str '#listview { lines: 17; }' -threads 0 -width 65 -dmenu -i -p "all: ")"

And that opens the file or directory in a new workspace.

prosoitos commented 5 years ago

Notes:

prosoitos commented 5 years ago

I think that I narrowed the problem down a bit: this has nothing to do with rofi. The problem is with emacsclient.

If I replace emacsclient with mimeo in the above script and open, say, a .xlsx file, libreoffice calc will open in the current workspace. But if I open a text file or a directory, which have emacsclient as the default application, they will open in a new workspace (even though my default application for text files and for directories is emacsclient, not emacsclient -c).

Interestingly, if I run emacsclient file in urxvt, this freezes my machine with "waiting for Emacs..." and I have to do a force shutdown. If however I run emacsclient -c file, the file opens without problem in emacsclient, and of course, in a new workspace.

So it seems that my problem is that I cannot launch emacsclient in the current workspace. It has to be launched in a new workspace (which rofi, somehow, does automatically and which I have to explicitly ask for with -c in the command line). I don't know if this is a bad setting of mine or a window issue with EXWM.

My apologies for mis-identifying the root of the problem and sending you on the wrong path with rofi.

ch11ng commented 5 years ago

Once correctly set, emacsclient can reuse the current workspace to open files. Actually such setting is recommended. Please note (server-start) is required to start a server. Setting VISUAL and EDITOR environment variables is a convenient way to automatically tell other applications to use emacsclient as the editor.

prosoitos commented 5 years ago

I can't see what in my settings is different from your example installation and why I cannot use emacsclient in the current workspace...

I have (server-start) in my init file of course and I can use emacsclient without any problem, but only in a new workspace...

ch11ng commented 5 years ago

Please stop the server with server-force-delete first. If it doesn't help, please try with a minimal configuration.

prosoitos commented 5 years ago

Stopping, then restarting the server does not help.

It seems that it is something in my settings since you cannot reproduce it. So I will try to trouble-shoot on my end. So feel free to close this issue since it is apparently not a bug.

In the meantime, I will bind an easy key to the killing of workspaces.

ch11ng commented 5 years ago

Fine.

prosoitos commented 5 years ago

(of course, if you ever have any thought about what it might be, I will happily take any advice/suggestion you may have which might help me narrow it down).

prosoitos commented 5 years ago

I found it.

The problem was not in my init file.

I had

export VISUAL=emacsclient
export EDITOR="$VISUAL"

in my .xinitrc file

and

if [[ -n $SSH_CONNECTION ]]; then
    export EDITOR='emacsclient'
else
    export EDITOR='emacs'
fi

in my .zshrc file and that was creating havoc.

I removed the entry in my .zshrc file and emacsclient works flawlessly now. And it does indeed open in the current workspace without problem. So that is finally the end of my bazillion workspaces created by rofi :slightly_smiling_face:

prosoitos commented 5 years ago

Running emacsclient directly in the command line still freezes my machine with Waiting for Emacs...

and I have to force shut down.

So there is still something funny going on... But at least, I can use my rofi script to open files now.

prosoitos commented 5 years ago

@ch11ng Actually, I still cannot launch emacsclient if I am not in an Emacs buffer:

Running emacsclient <file> in the cli leaves me with Waiting for Emacs... and I have to force reboot. It did work once, so the behaviour is not totally consistant. But most of the time, it fails.

So there is still something in my settings messing up with emacsclient. Emacs does not seem to be able to take over a non-Emacs window.

ch11ng commented 5 years ago

It's unnecessary to force reboot every time Emacs freezes. Usually do pkill -12 emacs in console would bring Emacs back (and it can tell why Emacs stuck). In worst case pkill -9 emacs can be used to start over.

I'm not sure what does 'command line' / 'cli' refer to here. I've tried terminal emulator / Linux console and in both cases there seems to be no such problem with emacsclient. I'd suggest to narrow down the search by starting with a clean Emacs configuration.

prosoitos commented 5 years ago

It's unnecessary to force reboot every time Emacs freezes. Usually do pkill -12 emacs in console would bring Emacs back (and it can tell why Emacs stuck). In worst case pkill -9 emacs can be used to start over.

When Emacs freezes, I can't do anything on my machine anymore (so I have no access to the console). Not sure if it is because of my settings or because there is some trick I don't know, but I without being able to launch htop or to send any command from the console, the only way out I have found is to force poweroff my machine by a long press on the power button...

Maybe it is because I start Emacs with exec emacs in my .xinitrc file instead of exec dbus-launch --exit-with-session emacs as you suggest in your example configuration? (trying this now and I'll see if it helps).

I'm not sure what does 'command line' / 'cli' refer to here.

I meant a terminal emulator. I use urxvt.

ch11ng commented 5 years ago

Ctrl+Alt+F1...F12 are the default keybindings for switching to virtual terminals 1...12, as documented in the manual page of Xorg(1).

prosoitos commented 5 years ago

Oh, I see. Thank you for this very useful information (I am still a noob with a lot to learn). I will certainly try this next time Emacs crashes!

Having to force a shutdown each time Emacs freezes was the one thing that was making me a little unhappy about having Xorg rely on Emacs with EXWM. So this solves it :slightly_smiling_face: