all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs client doesn't run by root
Date: Sun, 28 Feb 2021 21:09:04 +0100	[thread overview]
Message-ID: <87r1l0c5mn.fsf@gnu.org> (raw)
In-Reply-To: <72ea7a4c-c9e8-3a93-0ed7-aad5b18ee422@akwebsoft.com>

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	other threads:[~2021-02-28 20:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 19:10 Emacs client doesn't run by root Tim Johnson
2021-02-28 20:09 ` Tassilo Horn [this message]
2021-02-28 21:54   ` Tim Johnson
2021-03-01  6:00 ` Teemu Likonen
2021-03-01 18:39   ` Tim Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1l0c5mn.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.