Commit 8d68025b authored by Juri Linkov's avatar Juri Linkov

Use the minibuffer to read answer in userlock.el (bug#38076)

* lisp/userlock.el: Rename 'fn' to 'filename'.
(ask-user-about-supersession-threat): Use read-char-from-minibuffer
instead of read-char-choice.
parent d370c6a6
Pipeline #3994 failed with stage
in 90 minutes and 4 seconds
......@@ -103,11 +103,11 @@ You can <q>uit; don't modify this file.")
(define-error 'file-supersession nil 'file-error)
(defun userlock--check-content-unchanged (fn)
(defun userlock--check-content-unchanged (filename)
(with-demoted-errors "Unchanged content check: %S"
;; Even tho we receive `fn', we know that `fn' refers to the current
;; Even tho we receive `filename', we know that `filename' refers to the current
;; buffer's file.
(cl-assert (equal fn (expand-file-name buffer-file-truename)))
(cl-assert (equal filename (expand-file-name buffer-file-truename)))
;; Note: rather than read the file and compare to the buffer, we could save
;; the buffer and compare to the file, but for encrypted data this
;; wouldn't work well (and would risk exposing the data).
......@@ -123,7 +123,7 @@ You can <q>uit; don't modify this file.")
(when (with-temp-buffer
(let ((coding-system-for-read cs)
(non-essential t))
(insert-file-contents fn))
(insert-file-contents filename))
(when (= (buffer-size) (- end start)) ;Minor optimization.
(= 0 (let ((case-fold-search nil))
......@@ -133,13 +133,13 @@ You can <q>uit; don't modify this file.")
(defun userlock--ask-user-about-supersession-threat (fn)
(defun userlock--ask-user-about-supersession-threat (filename)
;; Called from filelock.c.
(unless (userlock--check-content-unchanged fn)
(ask-user-about-supersession-threat fn)))
(unless (userlock--check-content-unchanged filename)
(ask-user-about-supersession-threat filename)))
(defun ask-user-about-supersession-threat (fn)
(defun ask-user-about-supersession-threat (filename)
"Ask a user who is about to modify an obsolete buffer what to do.
This function has two choices: it can return, in which case the modification
of the buffer will proceed, or it can (signal \\='file-supersession (file)),
......@@ -152,14 +152,14 @@ The buffer in question is current when this function is called."
(let ((prompt
(format "%s changed on disk; \
really edit the buffer? (y, n, r or C-h) "
(file-name-nondirectory fn)))
(file-name-nondirectory filename)))
(choices '(?y ?n ?r ?? ?\C-h))
(when noninteractive
(message "%s" prompt)
(error "Cannot resolve conflict in batch mode"))
(while (null answer)
(setq answer (read-char-choice prompt choices))
(setq answer (read-char-from-minibuffer prompt choices))
(cond ((memq answer '(?? ?\C-h))
(setq answer nil))
......@@ -167,10 +167,10 @@ really edit the buffer? (y, n, r or C-h) "
;; Ask for confirmation if buffer modified
(revert-buffer nil (not (buffer-modified-p)))
(signal 'file-supersession
(list "File reverted" fn)))
(list "File reverted" filename)))
((eq answer ?n)
(signal 'file-supersession
(list "File changed on disk" fn)))))
(list "File changed on disk" filename)))))
"File on disk now will become a backup file if you save these changes.")
(setq buffer-backed-up nil))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment