if the buffer is modified. If the buffer is not modified, then
the file should not be locked, so this function does nothing. It also
does nothing if the current buffer is not visiting a file, or is not locked.
+This function handles file system errors by calling @code{display-warning}
+and otherwise ignores the error.
@end defun
@defopt create-lockfiles
\f
* Lisp Changes in Emacs 28.1
++++
+** 'unlock-buffer' displays warnings instead of signaling.
+Instead of signaling 'file-error' conditions for file system level
+errors, the function now calls 'display-warning' and continues as if
+the error did not occur.
+
+++
** New function 'always'.
This is identical to 'ignore', but returns t instead.
revert-buffer-binding))
(help-mode)))))
+;;;###autoload
+(defun userlock--handle-unlock-error (error)
+ "Report an ERROR that occurred while unlocking a file."
+ (display-warning
+ '(unlock-file)
+ ;; There is no need to explain that this is an unlock error because
+ ;; ERR is a `file-error' condition, which explains this.
+ (message "%s, ignored" (error-message-string error))
+ :warning))
+
;;; userlock.el ends here
}
}
-void
-unlock_file (Lisp_Object fn)
+static Lisp_Object
+unlock_file_body (Lisp_Object fn)
{
char *lfname;
USE_SAFE_ALLOCA;
report_file_errno ("Unlocking file", filename, err);
SAFE_FREE ();
+ return Qnil;
+}
+
+static Lisp_Object
+unlock_file_handle_error (Lisp_Object err)
+{
+ call1 (intern ("userlock--handle-unlock-error"), err);
+ return Qnil;
+}
+
+void
+unlock_file (Lisp_Object fn)
+{
+ internal_condition_case_1 (unlock_file_body,
+ fn,
+ list1(Qfile_error),
+ unlock_file_handle_error);
}
#else /* MSDOS */
0, 0, 0,
doc: /* Unlock the file visited in the current buffer.
If the buffer is not modified, this does nothing because the file
-should not be locked in that case. */)
+should not be locked in that case. It also does nothing if the
+current buffer is not visiting a file, or is not locked. Handles file
+system errors by calling `display-warning' and continuing as if the
+error did not occur. */)
(void)
{
if (SAVE_MODIFF < MODIFF
(should-not (file-locked-p buffer-file-truename))
(filelock-tests--spoil-lock-file buffer-file-truename)
- ;; FIXME: Unlocking buffers should not signal errors related to
- ;; their lock files (bug#46397).
- (let ((err (should-error (unlock-buffer))))
- (should (equal (cl-subseq err 0 2)
- '(file-error "Unlocking file")))))))
+ ;; Errors from `unlock-buffer' should call
+ ;; `userlock--handle-unlock-error' (bug#46397).
+ (let (errors)
+ (cl-letf (((symbol-function 'userlock--handle-unlock-error)
+ (lambda (err) (push err errors))))
+ (unlock-buffer))
+ (should (consp errors))
+ (should (equal '(file-error "Unlocking file")
+ (seq-subseq (car errors) 0 2)))
+ (should (equal (length errors) 1))))))
(ert-deftest filelock-tests-kill-buffer-spoiled ()
"Check that `kill-buffer' fails if a lockfile is \"spoiled\"."
;; a function that fakes a "yes" answer for the "Buffer modified;
;; kill anyway?" prompt.
;;
- ;; FIXME: Killing buffers should not signal errors related to
- ;; their lock files (bug#46397).
- (let* ((err (cl-letf (((symbol-function 'yes-or-no-p)
- (lambda (&rest _) t)))
- (should-error (kill-buffer)))))
- (should (equal (seq-subseq err 0 2)
- '(file-error "Unlocking file")))))))
+ ;; File errors from unlocking files should call
+ ;; `userlock--handle-unlock-error' (bug#46397).
+ (let (errors)
+ (cl-letf (((symbol-function 'yes-or-no-p)
+ (lambda (&rest _) t))
+ ((symbol-function 'userlock--handle-unlock-error)
+ (lambda (err) (push err errors))))
+ (kill-buffer))
+ (should (consp errors))
+ (should (equal '(file-error "Unlocking file")
+ (seq-subseq (car errors) 0 2)))
+ (should (equal (length errors) 1))))))
(provide 'filelock-tests)
;;; filelock-tests.el ends here