(defun userlock--check-content-unchanged (filename)
(with-demoted-errors "Unchanged content check: %S"
- ;; Even tho we receive `filename', we know that `filename' refers to the current
- ;; buffer's file.
- (cl-assert (equal (expand-file-name filename)
- (expand-file-name buffer-file-truename)))
+ ;; Even tho we receive `filename', we know that `filename' refers
+ ;; to the current buffer's file.
+ (cl-assert (or (null buffer-file-truename) ; temporary buffer
+ (equal (expand-file-name 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).
(compare-buffer-substrings
buf start end
(current-buffer) (point-min) (point-max))))))
- (set-visited-file-modtime)
+ ;; We know that some buffer visits FILENAME, because our
+ ;; caller (see lock_file) verified that. Thus, we set the
+ ;; modtime in that buffer, to cater to use case where the
+ ;; file is about to be written to from some buffer that
+ ;; doesn't visit any file, like a temporary buffer.
+ (with-current-buffer (get-file-buffer (file-truename filename))
+ (set-visited-file-modtime))
'unchanged)))))
;;;###autoload