How to modify write permission on current buffer in emacs?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
14
down vote

favorite
6












Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer?



Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file.



Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!










share|improve this question

























    up vote
    14
    down vote

    favorite
    6












    Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer?



    Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file.



    Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!










    share|improve this question























      up vote
      14
      down vote

      favorite
      6









      up vote
      14
      down vote

      favorite
      6






      6





      Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer?



      Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file.



      Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!










      share|improve this question













      Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer?



      Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file.



      Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!







      permissions emacs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 10 '12 at 16:04









      rahmu

      10.1k1968110




      10.1k1968110




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          13
          down vote



          accepted










          After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.



          Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.






          share|improve this answer






















          • While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
            – Paul Rubel
            Nov 20 at 16:13

















          up vote
          8
          down vote













          To change the read-only status of a buffer, use C-xC-q (toggle read-only-mode). To change file permissions, you can run dired on the file's directory (C-xd), search for the file by C-s and use M to change its mode.






          share|improve this answer


















          • 2




            Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
            – cjm
            Sep 10 '12 at 16:33







          • 2




            @cjm: It does not work for me unless I load dired-x.
            – choroba
            Sep 10 '12 at 16:47










          • Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
            – cjm
            Sep 10 '12 at 17:04










          • Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
            – Charlie Martin
            Jul 19 at 21:47

















          up vote
          0
          down vote













          If the workflow requires to change the file permission of the buffer repeatedly, then having a custom function would help like the following.



          This works only on unix machines(executes system command "chmod"



          (defun chmod-plus-w ()
          (interactive)
          (shell-command-to-string (concat "chmod +w " (buffer-file-name (current-buffer))))
          (revert-buffer))





          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f47724%2fhow-to-modify-write-permission-on-current-buffer-in-emacs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            13
            down vote



            accepted










            After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.



            Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.






            share|improve this answer






















            • While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
              – Paul Rubel
              Nov 20 at 16:13














            up vote
            13
            down vote



            accepted










            After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.



            Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.






            share|improve this answer






















            • While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
              – Paul Rubel
              Nov 20 at 16:13












            up vote
            13
            down vote



            accepted







            up vote
            13
            down vote



            accepted






            After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.



            Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.






            share|improve this answer














            After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.



            Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 at 16:37

























            answered Sep 10 '12 at 22:45









            Gilles

            522k12610401570




            522k12610401570











            • While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
              – Paul Rubel
              Nov 20 at 16:13
















            • While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
              – Paul Rubel
              Nov 20 at 16:13















            While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
            – Paul Rubel
            Nov 20 at 16:13




            While C-x C-q still works, as of emacs 24.3 it now calls read-only-mode rather than toggle-read-only and toggle-read-only has been disabled.
            – Paul Rubel
            Nov 20 at 16:13












            up vote
            8
            down vote













            To change the read-only status of a buffer, use C-xC-q (toggle read-only-mode). To change file permissions, you can run dired on the file's directory (C-xd), search for the file by C-s and use M to change its mode.






            share|improve this answer


















            • 2




              Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
              – cjm
              Sep 10 '12 at 16:33







            • 2




              @cjm: It does not work for me unless I load dired-x.
              – choroba
              Sep 10 '12 at 16:47










            • Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
              – cjm
              Sep 10 '12 at 17:04










            • Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
              – Charlie Martin
              Jul 19 at 21:47














            up vote
            8
            down vote













            To change the read-only status of a buffer, use C-xC-q (toggle read-only-mode). To change file permissions, you can run dired on the file's directory (C-xd), search for the file by C-s and use M to change its mode.






            share|improve this answer


















            • 2




              Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
              – cjm
              Sep 10 '12 at 16:33







            • 2




              @cjm: It does not work for me unless I load dired-x.
              – choroba
              Sep 10 '12 at 16:47










            • Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
              – cjm
              Sep 10 '12 at 17:04










            • Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
              – Charlie Martin
              Jul 19 at 21:47












            up vote
            8
            down vote










            up vote
            8
            down vote









            To change the read-only status of a buffer, use C-xC-q (toggle read-only-mode). To change file permissions, you can run dired on the file's directory (C-xd), search for the file by C-s and use M to change its mode.






            share|improve this answer














            To change the read-only status of a buffer, use C-xC-q (toggle read-only-mode). To change file permissions, you can run dired on the file's directory (C-xd), search for the file by C-s and use M to change its mode.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 20 at 0:17









            Jeff Schaller

            36.4k952120




            36.4k952120










            answered Sep 10 '12 at 16:23









            choroba

            25.8k44470




            25.8k44470







            • 2




              Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
              – cjm
              Sep 10 '12 at 16:33







            • 2




              @cjm: It does not work for me unless I load dired-x.
              – choroba
              Sep 10 '12 at 16:47










            • Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
              – cjm
              Sep 10 '12 at 17:04










            • Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
              – Charlie Martin
              Jul 19 at 21:47












            • 2




              Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
              – cjm
              Sep 10 '12 at 16:33







            • 2




              @cjm: It does not work for me unless I load dired-x.
              – choroba
              Sep 10 '12 at 16:47










            • Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
              – cjm
              Sep 10 '12 at 17:04










            • Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
              – Charlie Martin
              Jul 19 at 21:47







            2




            2




            Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
            – cjm
            Sep 10 '12 at 16:33





            Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing.
            – cjm
            Sep 10 '12 at 16:33





            2




            2




            @cjm: It does not work for me unless I load dired-x.
            – choroba
            Sep 10 '12 at 16:47




            @cjm: It does not work for me unless I load dired-x.
            – choroba
            Sep 10 '12 at 16:47












            Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
            – cjm
            Sep 10 '12 at 17:04




            Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it.
            – cjm
            Sep 10 '12 at 17:04












            Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
            – Charlie Martin
            Jul 19 at 21:47




            Annoyingly toggle-read-only has been replaced with read-only-mode, although the binding is the same.
            – Charlie Martin
            Jul 19 at 21:47










            up vote
            0
            down vote













            If the workflow requires to change the file permission of the buffer repeatedly, then having a custom function would help like the following.



            This works only on unix machines(executes system command "chmod"



            (defun chmod-plus-w ()
            (interactive)
            (shell-command-to-string (concat "chmod +w " (buffer-file-name (current-buffer))))
            (revert-buffer))





            share|improve this answer
























              up vote
              0
              down vote













              If the workflow requires to change the file permission of the buffer repeatedly, then having a custom function would help like the following.



              This works only on unix machines(executes system command "chmod"



              (defun chmod-plus-w ()
              (interactive)
              (shell-command-to-string (concat "chmod +w " (buffer-file-name (current-buffer))))
              (revert-buffer))





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                If the workflow requires to change the file permission of the buffer repeatedly, then having a custom function would help like the following.



                This works only on unix machines(executes system command "chmod"



                (defun chmod-plus-w ()
                (interactive)
                (shell-command-to-string (concat "chmod +w " (buffer-file-name (current-buffer))))
                (revert-buffer))





                share|improve this answer












                If the workflow requires to change the file permission of the buffer repeatedly, then having a custom function would help like the following.



                This works only on unix machines(executes system command "chmod"



                (defun chmod-plus-w ()
                (interactive)
                (shell-command-to-string (concat "chmod +w " (buffer-file-name (current-buffer))))
                (revert-buffer))






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 27 at 9:07









                Talespin_Kit

                16517




                16517



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f47724%2fhow-to-modify-write-permission-on-current-buffer-in-emacs%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay