From 5e1873b417fd5bc79a05339cb9d1e1aacb57164a Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Wed, 14 Dec 2011 10:00:38 +0200 Subject: [PATCH] Add user variable to control asking to a write-protected file. Organization: Private Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit files.el (basic-save-buffer-2): Add `save-buffer-read-only-confirm-flag' (save-buffer-read-only-confirm-flag): New user variable (bug#10257). Signed-off-by: Jari Aalto --- lisp/files.el | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 40b6e7d..52c11b7 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4445,9 +4445,17 @@ Before and after saving the buffer, this function runs (setq buffer-file-coding-system-explicit (cons last-coding-system-used nil))))) +;; See 2011-12-09 Emacs Bug#10257 for details +(defvar save-buffer-read-only-confirm-flag t + "*If non-nil, do not ask writable confiramtion in `basic-save-buffer-2'. +Useful e.g. under Cygwin where the returned read-only status of +a file may not be accurate over Windows mapped network drives.") + ;; This returns a value (MODES SELINUXCONTEXT BACKUPNAME), like backup-buffer. (defun basic-save-buffer-2 () (let (tempsetmodes setmodes) + ;; Note: the file-writable-p checks + ;; UID, GID which are not necessarily correct e.g. under Cygwin. (if (not (file-writable-p buffer-file-name)) (let ((dir (file-name-directory buffer-file-name))) (if (not (file-directory-p dir)) @@ -4456,13 +4464,14 @@ Before and after saving the buffer, this function runs (error "%s: no such directory" dir)) (if (not (file-exists-p buffer-file-name)) (error "Directory %s write-protected" dir) - (if (yes-or-no-p - (format - "File %s is write-protected; try to save anyway? " - (file-name-nondirectory - buffer-file-name))) - (setq tempsetmodes t) - (error "Attempt to save to a file which you aren't allowed to write")))))) + (if save-buffer-read-only-confirm-flag + (if (yes-or-no-p + (format + "File %s is write-protected; try to save anyway? " + (file-name-nondirectory + buffer-file-name))) + (setq tempsetmodes t) + (error "Attempt to save to a file which you aren't allowed to write"))))))) (or buffer-backed-up (setq setmodes (backup-buffer))) (let* ((dir (file-name-directory buffer-file-name)) -- 1.7.7.3