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.") ...@@ -103,11 +103,11 @@ You can <q>uit; don't modify this file.")
(define-error 'file-supersession nil 'file-error) (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" (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. ;; 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 ;; 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 ;; the buffer and compare to the file, but for encrypted data this
;; wouldn't work well (and would risk exposing the data). ;; wouldn't work well (and would risk exposing the data).
...@@ -123,7 +123,7 @@ You can <q>uit; don't modify this file.") ...@@ -123,7 +123,7 @@ You can <q>uit; don't modify this file.")
(when (with-temp-buffer (when (with-temp-buffer
(let ((coding-system-for-read cs) (let ((coding-system-for-read cs)
(non-essential t)) (non-essential t))
(insert-file-contents fn)) (insert-file-contents filename))
(when (= (buffer-size) (- end start)) ;Minor optimization. (when (= (buffer-size) (- end start)) ;Minor optimization.
(= 0 (let ((case-fold-search nil)) (= 0 (let ((case-fold-search nil))
(compare-buffer-substrings (compare-buffer-substrings
...@@ -133,13 +133,13 @@ You can <q>uit; don't modify this file.") ...@@ -133,13 +133,13 @@ You can <q>uit; don't modify this file.")
'unchanged))))) 'unchanged)))))
;;;###autoload ;;;###autoload
(defun userlock--ask-user-about-supersession-threat (fn) (defun userlock--ask-user-about-supersession-threat (filename)
;; Called from filelock.c. ;; Called from filelock.c.
(unless (userlock--check-content-unchanged fn) (unless (userlock--check-content-unchanged filename)
(ask-user-about-supersession-threat fn))) (ask-user-about-supersession-threat filename)))
;;;###autoload ;;;###autoload
(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. "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 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)), 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." ...@@ -152,14 +152,14 @@ The buffer in question is current when this function is called."
(let ((prompt (let ((prompt
(format "%s changed on disk; \ (format "%s changed on disk; \
really edit the buffer? (y, n, r or C-h) " really edit the buffer? (y, n, r or C-h) "
(file-name-nondirectory fn))) (file-name-nondirectory filename)))
(choices '(?y ?n ?r ?? ?\C-h)) (choices '(?y ?n ?r ?? ?\C-h))
answer) answer)
(when noninteractive (when noninteractive
(message "%s" prompt) (message "%s" prompt)
(error "Cannot resolve conflict in batch mode")) (error "Cannot resolve conflict in batch mode"))
(while (null answer) (while (null answer)
(setq answer (read-char-choice prompt choices)) (setq answer (read-char-from-minibuffer prompt choices))
(cond ((memq answer '(?? ?\C-h)) (cond ((memq answer '(?? ?\C-h))
(ask-user-about-supersession-help) (ask-user-about-supersession-help)
(setq answer nil)) (setq answer nil))
...@@ -167,10 +167,10 @@ really edit the buffer? (y, n, r or C-h) " ...@@ -167,10 +167,10 @@ really edit the buffer? (y, n, r or C-h) "
;; Ask for confirmation if buffer modified ;; Ask for confirmation if buffer modified
(revert-buffer nil (not (buffer-modified-p))) (revert-buffer nil (not (buffer-modified-p)))
(signal 'file-supersession (signal 'file-supersession
(list "File reverted" fn))) (list "File reverted" filename)))
((eq answer ?n) ((eq answer ?n)
(signal 'file-supersession (signal 'file-supersession
(list "File changed on disk" fn))))) (list "File changed on disk" filename)))))
(message (message
"File on disk now will become a backup file if you save these changes.") "File on disk now will become a backup file if you save these changes.")
(setq buffer-backed-up nil)))) (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