Open a file with su/sudo inside Emacs

前端 未结 9 933
我寻月下人不归
我寻月下人不归 2020-12-12 08:32

Suppose I want to open a file in an existing Emacs session using su or sudo, without dropping down to a shell and doing sudoedit or

9条回答
  •  鱼传尺愫
    2020-12-12 09:18

    I recommend you to use advising commands. Put this function in your ~/.emacs

    (defadvice ido-find-file (after find-file-sudo activate)
      "Find file as root if necessary."
      (unless (and buffer-file-name
                   (file-writable-p buffer-file-name))
        (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
    

提交回复
热议问题