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: Tim Johnson
Subject: Re: Emacs client doesn't run by root
Date: Sun, 28 Feb 2021 12:54:26 -0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0


On 2/28/21 11:09 AM, Tassilo Horn wrote:
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---
Thanks. It is solved. Cheers

--
Tim
tj49.com




reply via email to

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