Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacslient closes whenever i call sudo-edit #21

Open
rien333 opened this issue Sep 8, 2018 · 9 comments
Open

Emacslient closes whenever i call sudo-edit #21

rien333 opened this issue Sep 8, 2018 · 9 comments

Comments

@rien333
Copy link

rien333 commented Sep 8, 2018

I run emacs as a server, and running sudo-edit closes emacs whenever I run it. It doesn't crash or alter emacs in anyway, it's only that I'm back at my shell and have to rerun my emacs command. I can then edit the files as a sudo user like normal.

@nflath
Copy link
Owner

nflath commented Sep 10, 2018

I can't reproduce this; can you give full instructions on how to reproduce starting from a clean (-q) emacs server?

@rien333
Copy link
Author

rien333 commented Sep 17, 2018

Can't reproduce with a clean server either, I'll try and see what the problem is.
Oddly enough running

emacs-26.1 --daemon -q 

does now trigger the undesired behavior described in my first post. The same goes for emacs with my whole init.el file commented out. (I'm running the stable emacs from the Arch Linux repos btw, I don't remember whether I had this problem on macOS as well, but I could check)

@rien333
Copy link
Author

rien333 commented Oct 16, 2018

Disregard my previous comment, running emacs-26.1 --daemon -q and then manually loading sudo-edit.el seems to work now. Nevertheless, commenting my whole init.el still displays the problematic behavior outlined above when invoking M-x sudo-edit. @nflath any ideas?

@nflath
Copy link
Owner

nflath commented Oct 16, 2018 via email

@someonewithpc
Copy link

someonewithpc commented Jun 4, 2019

Same problem here. It seems to close if opening in a terminal, but just hangs if on a separate frame. All instances hang, but C-g brings it back. Any thoughts?

@rien333
Copy link
Author

rien333 commented Jun 4, 2019

I also still experience this. If I find the time, I'll try nflaths suggestion and see if something in my global .emacs folder is causing the problem, as I already established that the problem seems to persist when commenting out all of my init.el (probably not, given that it is not super populated). @someonewithpc does the problem still persist when you comment out all of your init.el and then load sudo-edit manually?

As a work around, I now generally use this function/alias E (which pairs nicely with aliasing emacs to e) to do my sudo edits:

function E
    env SUDO_EDITOR="emacsclient -t -a emacs" sudoedit $argv
end

(fish syntax, but conversion to bash should be trivial)

@andersk
Copy link

andersk commented Sep 1, 2020

I can reproduce this with no .emacs or .emacs.d at all. I’m using Emacs 27.1. For reproduction, it’s important that I specify the file on the emacsclient command line.

  1. emacs --daemon
  2. emacsclient -c /etc/fstab
  3. M-x load-library /path/to/sudo-edit.el
  4. M-x sudo-edit causes emacsclient to close.

Some variants that might help shed light on what’s going on:

  • If I open two emacsclients to different files in step 2, then step 4 closes the current emacsclient, prompts for the sudo password in the other one, and opens the current file there.
  • If I open two emacsclients to the same file in step 2, then step 4 closes them both.
  • If I visit a different file with C-x C-f before invoking sudo-edit, it doesn’t close anything and works as expected.

@marcelino-m
Copy link

I think the problem is with the function find-alternate-file, but I don't know why:

  1. emacs --daemon -q
  2. emacsclient -c /etc/fstab
  3. And M-x eval-expression this (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants