<div dir="ltr"><div><div><div><div>Hi everyone,<br><br></div>I would love to get some feedback on this snippet. What it does is, whenever you try to type in a read-only buffer, it will ask if you want to re-open the file with sudo. I think it's pretty cool, and it turned out to be relatively easy to set up.<br><br>(defadvice self-insert-command (around automagic-sudo activate)<br> (condition-case nil<br> ad-do-it<br> (buffer-read-only <br> (let ((path (buffer-file-name))<br> (buff (current-buffer)))<br> (when (and path (y-or-n-p "File is read-only, reopen with sudo?"))<br> (find-file (concat "/sudo:root@localhost:" path))<br> (kill-buffer buff))))))<br><br></div>The only downside I've noticed so far is that e.g. pressing enter does not work, because that issues the command "newline" instead of "self-insert-command". You could of course repeat this snippet for newline, and indent-for-tab-command, etc. Does anyone have a better idea?<br><br></div>Cheers,<br></div>Arne<br clear="all"><div><div><div><div><div><br>-- <br><div class="gmail_signature"><div dir="ltr"><div>| <a href="https://twitter.com/plexus" target="_blank">@plexus</a> | <a href="http://arnebrasseur.net" target="_blank">arnebrasseur.net</a> | <a href="https://leanpub.com/happylambda" target="_blank">The Happy Lambda</a> |<br></div></div></div>
</div></div></div></div></div></div>