From d96e4e29c7acb07551bf6369482d8eb8ec2a6b40 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sun, 29 Jun 2025 10:29:45 +0200 Subject: [PATCH] elisp-mode.el: Fix handling of deleted files --- lisp/progmodes/elisp-mode.el | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 7dbbfae2abe..2c7cc6bc96c 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1239,11 +1239,7 @@ confidence." (symbol-type '(symbol-type symbol-type-definition)) (function '(defun function macro special-form major-mode))))) (require 'project) - (dolist-with-progress-reporter - (file - (seq-filter - (lambda (file) (string= (file-name-extension file) "el")) - (project-files (project-current)))) + (dolist-with-progress-reporter (file (elisp-project-files)) "Scanning for references" (let (all lla) (pcase-dolist (`(,type ,beg ,len . ,_) (gethash identifier (elisp-sym-name-index file))) @@ -1304,12 +1300,7 @@ confidence." (symbol-type '(symbol-type symbol-type-definition)) (function '(defun function macro special-form major-mode))))) (require 'project) - (dolist-with-progress-reporter - (file - (seq-filter - (lambda (file) (string= (file-name-extension file) "el")) - (project-files (project-current)))) - "Scanning for references" + (dolist-with-progress-reporter (file (elisp-project-files)) "Scanning for references" (let (hits) (pcase-dolist (`(,type ,beg ,len . ,_) (gethash str (elisp-sym-name-index file))) (when (or (null types) (memq type types)) @@ -1318,6 +1309,13 @@ confidence." (when hits (push (cons file hits) res)))) (nreverse res))) +(defun elisp-project-files () + (seq-filter + (lambda (file) + (and (string= (file-name-extension file) "el") + (not (string-prefix-p ".#" (file-name-base file))))) + (project-files (project-current)))) + (defun elisp-make-xref (beg len) (let* ((beg-end (save-excursion (goto-char beg) @@ -2885,21 +2883,26 @@ of TARGET." (defvar elisp-sym-name-index-cache (make-hash-table :test #'equal)) +(defconst elisp--dummy-hash-table (make-hash-table :test #'equal)) + (defun elisp-sym-name-index (file) (if-let ((buf (get-file-buffer file)) ((buffer-modified-p buf))) (with-current-buffer buf (elisp-sym-name-index-1 file)) (let ((cached (gethash file elisp-sym-name-index-cache)) (modtime (file-attribute-modification-time (file-attributes file)))) - (cdr - (if (time-less-p (or (car cached) 0) modtime) - (puthash file (cons modtime - (with-work-buffer - (setq lexical-binding t) - (insert-file-contents file) - (elisp-sym-name-index-1 file))) - elisp-sym-name-index-cache) - cached))))) + (if modtime + (cdr + (if (time-less-p (or (car cached) 0) modtime) + (puthash file (cons modtime + (with-work-buffer + (setq lexical-binding t) + (insert-file-contents file) + (elisp-sym-name-index-1 file))) + elisp-sym-name-index-cache) + cached)) + ;; File does not exists. + elisp--dummy-hash-table)))) (defun elisp-sym-name-index-1 (source) (let ((all (make-hash-table :test #'equal)) -- 2.39.5