From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: How to change and save a read-only file? Date: Sat, 29 Jun 2013 13:04:19 +0200 Message-ID: <874nchi3f0.fsf@gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1372503890 28382 80.91.229.3 (29 Jun 2013 11:04:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 29 Jun 2013 11:04:50 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 29 13:04:50 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UssxU-0002ku-Kk for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Jun 2013 13:04:48 +0200 Original-Received: from localhost ([::1]:44229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UssxU-0005Ar-8R for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Jun 2013 07:04:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UssxJ-00058u-6F for help-gnu-emacs@gnu.org; Sat, 29 Jun 2013 07:04:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UssxI-0005S9-2V for help-gnu-emacs@gnu.org; Sat, 29 Jun 2013 07:04:37 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:58666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UssxH-0005S0-ON for help-gnu-emacs@gnu.org; Sat, 29 Jun 2013 07:04:36 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UssxD-0002VO-LY for help-gnu-emacs@gnu.org; Sat, 29 Jun 2013 13:04:31 +0200 Original-Received: from g231235013.adsl.alicedsl.de ([92.231.235.13]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 29 Jun 2013 13:04:31 +0200 Original-Received: from tjolitz by g231235013.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 29 Jun 2013 13:04:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 284 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231235013.adsl.alicedsl.de User-Agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:Pli2gU4tPsvqfbGZQu0DKIqLxb0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91846 Archived-At: --=-=-= Content-Type: text/plain Marius Hofert writes: Hi, > What's the 'correct' approach to easily edit (change + save) such files? not sure whats the 'correct' approach, but there is tramp which allows you to do something like: 1. find-file as root ,--------------- | C-x C-f /sudo: `--------------- and then asks for a password ,----------------------------------- | Password for /sudo:root@localhost: `----------------------------------- to let you subsequently edit the file as root 2. or reopen dired buffer with sudo and thus open end edit files from that buffer as root ,------------------------------------------------------------------------------- | C-c C-s runs the command dired-toggle-sudo, which is an interactive autoloaded | compiled Lisp function in `dired-toggle-sudo.el'. | | It is bound to C-c C-s. | | (dired-toggle-sudo &optional SUDO-USER) | | Reopen current file or dired buffer with sudo. | | If SUDO-USER is nil assume root. | | If called with `universal-argument' (C-u), ask for username. `------------------------------------------------------------------------------- But I finally ended up to write a separate minimal init.el file and a small batch script that allow me to quickly open a root instance of emacs when I need it that warns me about being root while editing that I exit when I'm done with editing: ,--------------------------------------------- | -rwxr-xr-x 1 me users 125 26. Apr 09:44 esu `--------------------------------------------- with content: ,------------------------------------------------------ | #!/bin/sh | # start emacs as root | | exec sudo emacs -Q -bg black -fg wheat --no-splash -l | /home/me/.emacs.d/emacs-ESU-script.el `------------------------------------------------------ emacs-ESU-script.el: (it starts up pretty fast, but makes editing convenient, and has a nice red warning at the top of the buffer about editing as root) --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=emacs-ESU-script.el Content-Transfer-Encoding: quoted-printable Content-Description: Script for Emacs as root ;; * Emacs Q Script (message "ENTERING emacs-ESU-script ...") ;; ** Coding system (message "emacs-ESU-script coding system ...") (setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8) ;; ** Screen Colors ;; window type dependend screen colors (defun tj/set-window-type-dependend-emacsclient-colors () "Sets emacsclient colors for X. Background-color is set to black and foreground-color to wheat for emacsclient on X" (if (display-graphic-p) (progn (set-background-color "black") (set-foreground-color "wheat")))) (add-hook 'server-visit-hook 'tj/set-window-type-dependend-emacsclient-colors) (add-hook 'emacs-startup-hook 'tj/set-window-type-dependend-emacsclient-colors) ;; ** Helper functions (message "emacs-ESU-script helper functions ...") ;; *** Improved require (defvar missing-packages-list nil "List of packages that `try-require' can't find.") ;; attempt to load a feature/library, failing silently (defun try-require (feature) "Attempt to load a library or module. Return true if the library given as argument is successfully loaded. If not, instead of an error, just add the package to a list of missing packages." (condition-case err ;; protected form (progn (message "Checking for library `%s'..." feature) (if (stringp feature) (load-library feature) (require feature)) (message "Checking for library `%s'... Found" feature)) ;; error handler (file-error ; condition (progn (message "Checking for library `%s'... Missing" feature) (add-to-list 'missing-packages-list feature 'append)) nil))) ;; *** Fast temporary buffers (defun tj/switch-to-tmp-buffer () "Opens a temporary buffer" (interactive) (switch-to-buffer (generate-new-buffer-name "tmp"))) ;; define shortcut for switching to temp-buffer (global-set-key (kbd "C-x t") 'tj/switch-to-tmp-buffer) ;; ** General settings (message "emacs-ESU-script general settings ...") ;; To disable the menubar, use the following line: (menu-bar-mode -1) ;; To disable the scrollbar, use the following line: (scroll-bar-mode -1) ;; To disable the toolbar, use the following line: (tool-bar-mode -1) ;; syntax highlighting (global-font-lock-mode t) ;; sane select (mark) mode ;; (transient-mark-mode t) ;; entry deletes marked text (delete-selection-mode t) ;; match parentheses (show-paren-mode t) ;; wrap long lines in text mode (add-hook 'text-mode-hook 'turn-on-auto-fill) ;; enable "dired on steroids" (ido-mode t) ;; ;; Enable versioning with default values. ;; (setq version-control t) ;; Save all backup file into the designated directory. (setq backup-directory-alist (quote ( (".*" . "/home/tj/.emacs.d/backups/")= ))) ;; move between windows (shift-key + arrows) (windmove-default-keybindings) ;; "y or n" instead of "yes or no" (fset 'yes-or-no-p 'y-or-n-p) ;; ** Warning about being 'root' (message "emacs-ESU-script root warning ...") (defface find-file-root-header-face '((t (:foreground "white" :background "red3"))) "*Face use to display header-lines for files opened as root.") (defun find-file-root-header-warning () "*Display a warning in header line of the current buffer. This function is suitable to add to `find-file-root-hook'." (let* ((warning "WARNING: EDITING FILE WITH ROOT PRIVILEGES!") (space (+ 6 (- (frame-width) (length warning)))) (bracket (make-string (/ space 2) ?-)) (warning (concat bracket warning bracket))) (setq header-line-format (propertize warning 'face 'find-file-root-header-face)))) (add-hook 'find-file-hook 'find-file-root-header-warning) (add-hook 'dired-mode-hook 'find-file-root-header-warning) ;; ** Load libraries (message "emacs-ESU-script load libraries ...") ;; *** Smex (add-to-list 'load-path "/home/tj/.emacs.d/elpa/smex-2.0") (when (try-require 'smex) (smex-initialize) (global-set-key (kbd "M-x") 'smex) (global-set-key (kbd "C-x x") 'smex) (global-set-key (kbd "M-X") 'smex-major-mode-commands)) ;; *** Switch windos (add-to-list 'load-path "/home/tj/.emacs.d/elpa/switch-window-0.9/") (try-require 'switch-window) ;; *** Window numbering (add-to-list 'load-path "/home/tj/.emacs.d/src/") (when (try-require 'window-numbering) (window-numbering-mode 1)) ;; *** Winner mode ;; (add-to-list 'load-path "/usr/share/emacs/24.2/lisp/") (when (try-require 'winner) (when (fboundp 'winner-mode) (winner-mode 1)) (global-set-key (kbd "") 'winner-undo) (global-set-key (kbd "") 'winner-redo)) ;; *** Missing packages ;; warn that some packages were missing (if missing-packages-list (progn (message "Packages not found: %S" missing-packages-list))) ;; ** Visit dired buffers (message "emacs-ESU-script visit dired buffer ...") (dired "/usr/share/") (split-window-sensibly (get-buffer-window (current-buffer))) (dired "/usr/share/emacs/24.3/lisp/") (message "Loading emacs-ESU-script (almost) DONE") ;; ** Custom Set Variables/Fonts (message "FINALLY Custom vars/fonts ...") (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(default ((t (:family "DejaVu Sans Mono" :foundry "unknown" :slant normal= :weight normal :height 120 :width normal)))) '(org-mode-line-clock ((t (:background "grey75" :foreground "red" :box (:l= ine-width -1 :style released-button)))) t)) --=-=-= Content-Type: text/plain -- cheers, Thorsten --=-=-=--