help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs client doesn't run by root


From: Tassilo Horn
Subject: Re: Emacs client doesn't run by root
Date: Sun, 28 Feb 2021 21:09:04 +0100
User-agent: mu4e 1.5.8; emacs 28.0.50

Tim Johnson <tim@akwebsoft.com> writes:

> I have been using the emacs daemon as my system editor.
> Starting with the following script
> ;; code
> emacs -q -nw --no-splash --daemon -l ~/.emacs.d/init_term.el
> ;; end code
>
> Works fine as user tim, but if I try it as root, I get the following error
> message:
> ;; quote
> /usr/local/bin/emacsclient: can't find socket; have you started the server?

The reason is that this will try to connect to the emacs demon run for
the user root which you would need to start as well.

I just find files as normal user and use the below snippet to be queried
if I want to open a file I have no write permission for using TRAMP's
sudo method:

--8<---------------cut here---------------start------------->8---
  (defun th/find-file-sudo (file)
    "Opens FILE with root privileges."
    (interactive "F")
    (set-buffer (find-file (concat "/sudo::" file))))

  (define-advice find-file (:around (ff file &rest more) 
th/find-file-maybe-sudo)
    (if (and (file-exists-p file)
             (not (file-directory-p file))
             (not (file-writable-p file))
             (not (file-remote-p file))
             (y-or-n-p (concat "File "
                               file
                               " is read-only.  Sudo? ")))
        (th/find-file-sudo file)
      (funcall ff file more)))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]