Skip to content

Commit 134ce48

Browse files
committed
Ignore hidden and editor temporary files in livereload file watcher
Filter out files that match common editor temporary/backup file patterns in the livereload file watcher callback: - Files starting with '.' (dotfiles, vim swap files like .foo.md.swp) - Files ending with '~' (backup files) - Files matching '#*#' (Emacs auto-save files) This prevents live reload from being triggered repeatedly by editor temporary files, which was especially problematic for vim users where editing .md files creates .foo.md.swp files. Fixes #2519
1 parent 2caeffe commit 134ce48

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

mkdocs/livereload/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ def watch(self, path: str, func: None = None, *, recursive: bool = True) -> None
162162
def callback(event):
163163
if event.is_directory:
164164
return
165+
# Ignore hidden files and editor temporary/backup files:
166+
# - .dotfiles (vim swap .foo.md.swp, .foo.md.swo, .foo.md.swn, etc.)
167+
# - files ending with ~ (editor backup)
168+
# - #files# matching Emacs auto-save pattern
169+
name = os.path.basename(event.src_path)
170+
if (
171+
name.startswith(".")
172+
or name.endswith("~")
173+
or (name.startswith("#") and name.endswith("#"))
174+
):
175+
return
165176
log.debug(str(event))
166177
with self._rebuild_cond:
167178
self._want_rebuild = True

0 commit comments

Comments
 (0)