sudo-edit icon indicating copy to clipboard operation
sudo-edit copied to clipboard

Emacslient closes whenever i call sudo-edit

Open rien333 opened this issue 6 years ago • 9 comments

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.

rien333 avatar Sep 08 '18 19:09 rien333

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

nflath avatar Sep 10 '18 18:09 nflath

~~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 avatar Sep 17 '18 18:09 rien333

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?

rien333 avatar Oct 16 '18 11:10 rien333

Possibly something in your .emacs?

On Tue, Oct 16, 2018 at 4:19 AM Rijnder Wever [email protected] wrote:

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 problematic behavior when invoking M-x sudo-edit. @nflath https://github.com/nflath any ideas?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nflath/sudo-edit/issues/21#issuecomment-430199397, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC2817pmrcPAWUrZMIKC8dldbzQcLaTks5ulcCqgaJpZM4WgAVD .

nflath avatar Oct 16 '18 14:10 nflath

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?

someonewithpc avatar Jun 04 '19 09:06 someonewithpc

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)

rien333 avatar Jun 04 '19 10:06 rien333

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.

andersk avatar Sep 01 '20 03:09 andersk

Related: https://emacs.stackexchange.com/questions/59541/prevent-dired-find-alternate-file-from-killing-emacsclient

andersk avatar Sep 01 '20 03:09 andersk

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))

marcelino-m avatar Feb 27 '21 06:02 marcelino-m