From 264f9ec487cd805610028ce46372e833fe377d8c Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 3 Dec 2015 10:44:00 +0100 Subject: [PATCH] Improve buffer list cleanup by excluding inaccessible files. Fixes #213 --- p4.el | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/p4.el b/p4.el index 39a3716..286e193 100644 --- a/p4.el +++ b/p4.el @@ -1334,13 +1334,26 @@ update (oldest first)." (sort (loop for pending in p4-update-status-pending-alist do (setf (third pending) (loop for b in (third pending) - if (and (buffer-live-p b) - (buffer-file-name b)) + if (p4--buffer-accessible-file-p b) collect b)) if (third pending) collect pending) (lambda (a b) (time-less-p (second a) (second b)))))) +(defun p4--buffer-accessible-file-p (buffer) + "Return t if the BUFFER is visiting an accessible file. +BUFFER is a buffer in `p4-update-status-pending-alist'. Return t +only if BUFFER exists, is visiting a readable file, and has an +accessible `default-directory'; then +`p4-update-status-pending-sort' should keep it in the list of +pending buffers." + (and (buffer-live-p buffer) + (with-current-buffer buffer + (file-accessible-directory-p default-directory)) + (let ((file (buffer-file-name buffer))) + (and file + (file-readable-p file))))) + (defun p4-update-mode (buffer status revision) "Turn p4-mode on or off in BUFFER according to Perforce status. Argument STATUS is a symbol (see `p4-vc-status' for the possible