【发布时间】:2016-01-21 10:08:57
【问题描述】:
阅读Open file via SSH and Sudo with Emacs 之后,我可以通过 sudo 编辑远程文件
/ssh:username@hostname|sudo:username@hostname:/the-file
但是我不能sudo编辑本地文件,Emacs的tramp提示密码root@hostname,因为在Ubuntu上没有root的密码存在(见RootSudo)。
那么有办法在 Ubuntu 上用 sudo 编辑本地文件吗?
总结: 如果你想用 Emacs 编辑远程/本地文件,@phils 有一个很好的答案 Open file via SSH and Sudo with Emacs; 如果您使用了弹丸(版本Tamp: sending password 或挂起),您可以尝试以下代码来解决我的问题:
(when (package-installed-p 'projectile)
(defun projectile-project-root ()
"Retrieves the root directory of a project if available.
The current directory is assumed to be the project's root otherwise."
(let ((dir default-directory))
(or (--reduce-from
(or acc
(let* ((cache-key (format "%s-%s" it dir))
(cache-value (gethash cache-key projectile-project-root-cache)))
(if cache-value
(if (eq cache-value 'no-project-root)
nil
cache-value)
(let ((value (funcall it (file-truename dir))))
(puthash cache-key (or value 'no-project-root) projectile-project-root-cache)
value))))
nil
projectile-project-root-files-functions)
(if projectile-require-project-root
(error "You're not in a project")
default-directory))))
(projectile-global-mode))
查看Simple tramp with sudo hangs on 'Sending password' 和projectile-global-mode prevents new processes from working over TRAMP #523 了解更多信息。
【问题讨论】: