How do I change read/write mode for a file using Emacs?

前端 未结 9 1181
悲&欢浪女
悲&欢浪女 2021-01-29 21:11

If a file is set to read only mode, how do I change it to write mode and vice versa from within Emacs?

9条回答
  •  轮回少年
    2021-01-29 22:01

    C-x C-q is useless. Because your also need the permission to save a file.

    I use Spacemacs. It gives me a convenient function to solve this question. The code is following.

    (defun spacemacs/sudo-edit (&optional arg)
      (interactive "p")
      (if (or arg (not buffer-file-name))
          (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
        (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
    

    I call spacemacs/sudo-edit to open a file in emacs and input my password, I can change the file without read-only mode.

    You can write a new function like spacemacs/sudo-edit.

提交回复
热议问题