|
271 | 271 | 'git-gutter-on-change) |
272 | 272 | ;; Add directory-mode support |
273 | 273 | (add-directory-mode-inserter) |
274 | | - (update-all-directory-buffers)) |
| 274 | + (update-all-directory-buffers) |
| 275 | + ;; Add filer support |
| 276 | + (add-filer-inserter) |
| 277 | + (update-filer-buffer)) |
275 | 278 |
|
276 | 279 | (defun disable-hook () |
277 | 280 | "Called when git-gutter-mode is disabled." |
|
284 | 287 | (clear-all-buffers) |
285 | 288 | ;; Remove directory-mode support and clear cache |
286 | 289 | (remove-directory-mode-inserter) |
| 290 | + ;; Remove filer support |
| 291 | + (remove-filer-inserter) |
| 292 | + (update-filer-buffer) |
287 | 293 | (clear-directory-status-cache)) |
288 | 294 |
|
289 | 295 | (define-minor-mode git-gutter-mode |
|
503 | 509 | "Clear the directory git status cache." |
504 | 510 | (clrhash *directory-git-status-cache*)) |
505 | 511 |
|
| 512 | +;;; Filer Git Status Support |
| 513 | + |
| 514 | +(defun insert-filer-git-status (point item root-directory) |
| 515 | + "Inserter function for filer to show git status." |
| 516 | + (let* ((pathname (lem/filer:item-pathname item)) |
| 517 | + (status (when (and pathname root-directory) |
| 518 | + (get-file-git-status pathname root-directory)))) |
| 519 | + (multiple-value-bind (char attr) |
| 520 | + (status-to-display status) |
| 521 | + (if attr |
| 522 | + (insert-string point (format nil "~A " char) :attribute attr) |
| 523 | + (insert-string point " "))))) |
| 524 | + |
| 525 | +(defun add-filer-inserter () |
| 526 | + "Add git status inserter to filer." |
| 527 | + (when (find-package :lem/filer) |
| 528 | + (let ((inserters (find-symbol "*FILER-ITEM-INSERTERS*" :lem/filer))) |
| 529 | + (when (and inserters (boundp inserters)) |
| 530 | + (unless (member #'insert-filer-git-status (symbol-value inserters)) |
| 531 | + (push #'insert-filer-git-status (symbol-value inserters))))))) |
| 532 | + |
| 533 | +(defun remove-filer-inserter () |
| 534 | + "Remove git status inserter from filer." |
| 535 | + (when (find-package :lem/filer) |
| 536 | + (let ((inserters (find-symbol "*FILER-ITEM-INSERTERS*" :lem/filer))) |
| 537 | + (when (and inserters (boundp inserters)) |
| 538 | + (setf (symbol-value inserters) |
| 539 | + (remove #'insert-filer-git-status (symbol-value inserters))))))) |
| 540 | + |
| 541 | +(defun update-filer-buffer () |
| 542 | + "Update filer buffer to reflect git status changes." |
| 543 | + (when (find-package :lem/filer) |
| 544 | + (let ((filer-buffer-fn (find-symbol "FILER-BUFFER" :lem/filer)) |
| 545 | + (root-item-fn (find-symbol "ROOT-ITEM" :lem/filer)) |
| 546 | + (render-fn (find-symbol "RENDER" :lem/filer))) |
| 547 | + (when (and filer-buffer-fn (fboundp filer-buffer-fn) |
| 548 | + root-item-fn (fboundp root-item-fn) |
| 549 | + render-fn (fboundp render-fn)) |
| 550 | + (alexandria:when-let ((buffer (funcall filer-buffer-fn))) |
| 551 | + (alexandria:when-let ((root (funcall root-item-fn buffer))) |
| 552 | + (funcall render-fn buffer root))))))) |
| 553 | + |
506 | 554 | (define-command git-gutter-refresh-directory-status () () |
507 | | - "Refresh git status cache for current directory buffer." |
| 555 | + "Refresh git status cache for current directory buffer and filer." |
508 | 556 | (let ((directory (buffer-directory (current-buffer)))) |
509 | 557 | (when directory |
510 | 558 | (remhash (namestring directory) *directory-git-status-cache*) |
511 | 559 | ;; Force redisplay of directory buffer if in directory-mode |
512 | 560 | (when (eq (buffer-major-mode (current-buffer)) 'lem/directory-mode:directory-mode) |
513 | 561 | (update-buffer (current-buffer))) |
| 562 | + ;; Also update filer buffer |
| 563 | + (update-filer-buffer) |
514 | 564 | (message "Git status refreshed")))) |
0 commit comments