Mercurial > emacs
comparison lisp/emacs-lisp/shadow.el @ 110797:2343b29e1e8d
Add a shadow-mode for load-path shadows.
* lisp/emacs-lisp/shadow.el (shadow-font-lock-keywords): New variable.
(shadow-mode): New mode.
(shadow-find-file): New button.
(list-load-path-shadows): Use shadow-mode and buttons.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 06 Oct 2010 19:37:39 -0700 |
parents | 1d1d5d9bd884 |
children | 62865a8e7f58 |
comparison
equal
deleted
inserted
replaced
110796:4901ee6d9e5a | 110797:2343b29e1e8d |
---|---|
149 ;; As a quick test, avoiding spawning a process, compare file | 149 ;; As a quick test, avoiding spawning a process, compare file |
150 ;; sizes. | 150 ;; sizes. |
151 (and (= (nth 7 (file-attributes f1)) | 151 (and (= (nth 7 (file-attributes f1)) |
152 (nth 7 (file-attributes f2))) | 152 (nth 7 (file-attributes f2))) |
153 (eq 0 (call-process "cmp" nil nil nil "-s" f1 f2)))))))) | 153 (eq 0 (call-process "cmp" nil nil nil "-s" f1 f2)))))))) |
154 | |
155 (defvar shadow-font-lock-keywords | |
156 `((,(format "hides \\(%s.*\\)" | |
157 (file-name-directory (locate-library "simple.el"))) | |
158 . (1 font-lock-warning-face))) | |
159 "Keywords to highlight in `shadow-mode'.") | |
160 | |
161 (define-derived-mode shadow-mode fundamental-mode "Shadow" | |
162 "Major mode for load-path shadows buffer." | |
163 (set (make-local-variable 'font-lock-defaults) | |
164 '((shadow-font-lock-keywords))) | |
165 (setq buffer-undo-list t | |
166 buffer-read-only t)) | |
167 | |
168 ;; TODO use text-properties instead, a la dired. | |
169 (require 'button) | |
170 (define-button-type 'shadow-find-file | |
171 'follow-link t | |
172 ;; 'face 'default | |
173 'action (lambda (button) | |
174 (let ((file (concat (button-get button 'shadow-file) ".el"))) | |
175 (or (file-exists-p file) | |
176 (setq file (concat file ".gz"))) | |
177 (if (file-readable-p file) | |
178 (pop-to-buffer (find-file-noselect file)) | |
179 (error "Cannot read file")))) | |
180 'help-echo "mouse-2, RET: find this file") | |
181 | |
154 | 182 |
155 ;;;###autoload | 183 ;;;###autoload |
156 (defun list-load-path-shadows (&optional stringp) | 184 (defun list-load-path-shadows (&optional stringp) |
157 "Display a list of Emacs Lisp files that shadow other files. | 185 "Display a list of Emacs Lisp files that shadow other files. |
158 | 186 |
232 (if (called-interactively-p 'interactive) | 260 (if (called-interactively-p 'interactive) |
233 ;; We are interactive. | 261 ;; We are interactive. |
234 ;; Create the *Shadows* buffer and display shadowings there. | 262 ;; Create the *Shadows* buffer and display shadowings there. |
235 (let ((string (buffer-string))) | 263 (let ((string (buffer-string))) |
236 (with-current-buffer (get-buffer-create "*Shadows*") | 264 (with-current-buffer (get-buffer-create "*Shadows*") |
237 (fundamental-mode) ;run after-change-major-mode-hook. | |
238 (display-buffer (current-buffer)) | 265 (display-buffer (current-buffer)) |
239 (setq buffer-undo-list t | 266 (shadow-mode) ; run after-change-major-mode-hook |
240 buffer-read-only nil) | 267 (let ((inhibit-read-only t)) |
241 (erase-buffer) | 268 (erase-buffer) |
242 (insert string) | 269 (insert string) |
243 (insert msg "\n") | 270 (insert msg "\n") |
244 (setq buffer-read-only t))) | 271 (while (re-search-backward "\\(^.*\\) hides \\(.*$\\)" |
272 nil t) | |
273 (dotimes (i 2) | |
274 (make-button (match-beginning (1+ i)) | |
275 (match-end (1+ i)) | |
276 'type 'shadow-find-file 'shadow-file | |
277 (match-string (1+ i))))) | |
278 (goto-char (point-max))))) | |
245 ;; We are non-interactive, print shadows via message. | 279 ;; We are non-interactive, print shadows via message. |
246 (unless (zerop n) | 280 (unless (zerop n) |
247 (message "This site has duplicate Lisp libraries with the same name. | 281 (message "This site has duplicate Lisp libraries with the same name. |
248 If a locally-installed Lisp library overrides a library in the Emacs release, | 282 If a locally-installed Lisp library overrides a library in the Emacs release, |
249 that can cause trouble, and you should probably remove the locally-installed | 283 that can cause trouble, and you should probably remove the locally-installed |
257 (forward-line 1)) | 291 (forward-line 1)) |
258 (message "%s" msg)))))))) | 292 (message "%s" msg)))))))) |
259 | 293 |
260 (provide 'shadow) | 294 (provide 'shadow) |
261 | 295 |
262 ;; arch-tag: 0480e8a7-62ed-4a12-a9f6-f44ded9b0830 | |
263 ;;; shadow.el ends here | 296 ;;; shadow.el ends here |