Show More
@@ -502,6 +502,43 b' directory names from the file system. W' | |||
|
502 | 502 | (or default "tip"))) |
|
503 | 503 | rev)))) |
|
504 | 504 | |
|
505 | (defun hg-parents-for-mode-line (root) | |
|
506 | "Format the parents of the working directory for the mode line." | |
|
507 | (let ((parents (split-string (hg-chomp | |
|
508 | (hg-run0 "--cwd" root "parents" "--template" | |
|
509 | "{rev}\n")) "\n"))) | |
|
510 | (mapconcat 'identity parents "+"))) | |
|
511 | ||
|
512 | (defun hg-buffers-visiting-repo (&optional path) | |
|
513 | "Return a list of buffers visiting the repository containing PATH." | |
|
514 | (let ((root-name (hg-root (or path (buffer-file-name)))) | |
|
515 | bufs) | |
|
516 | (save-excursion | |
|
517 | (dolist (buf (buffer-list) bufs) | |
|
518 | (set-buffer buf) | |
|
519 | (let ((name (buffer-file-name))) | |
|
520 | (when (and hg-status name (equal (hg-root name) root-name)) | |
|
521 | (setq bufs (cons buf bufs)))))))) | |
|
522 | ||
|
523 | (defun hg-update-mode-lines (path) | |
|
524 | "Update the mode lines of all buffers visiting the same repository as PATH." | |
|
525 | (let* ((root (hg-root path)) | |
|
526 | (parents (hg-parents-for-mode-line root))) | |
|
527 | (save-excursion | |
|
528 | (dolist (info (hg-path-status | |
|
529 | root | |
|
530 | (mapcar | |
|
531 | (function | |
|
532 | (lambda (buf) | |
|
533 | (substring (buffer-file-name buf) (length root)))) | |
|
534 | (hg-buffers-visiting-repo root)))) | |
|
535 | (let* ((name (car info)) | |
|
536 | (status (cdr info)) | |
|
537 | (buf (find-buffer-visiting (concat root name)))) | |
|
538 | (when buf | |
|
539 | (set-buffer buf) | |
|
540 | (hg-mode-line-internal status parents))))))) | |
|
541 | ||
|
505 | 542 | (defmacro hg-do-across-repo (path &rest body) |
|
506 | 543 | (let ((root-name (gensym "root-")) |
|
507 | 544 | (buf-name (gensym "buf-"))) |
@@ -554,10 +591,10 b' current frame."' | |||
|
554 | 591 | (cdr state) |
|
555 | 592 | 'normal))))) |
|
556 | 593 | |
|
557 |
(defun hg-status ( |
|
|
558 | "Return status of PATHS as an alist. | |
|
594 | (defun hg-path-status (root paths) | |
|
595 | "Return status of PATHS in repo ROOT as an alist. | |
|
559 | 596 | Each entry is a pair (FILE-NAME . STATUS)." |
|
560 | (let ((s (apply 'hg-run "status" "-marduc" paths)) | |
|
597 | (let ((s (apply 'hg-run "--cwd" root "status" "-marduc" paths)) | |
|
561 | 598 | result) |
|
562 | 599 | (dolist (entry (split-string (hg-chomp (cdr s)) "\n") (nreverse result)) |
|
563 | 600 | (let ((state (cdr (assoc (substring entry 0 2) |
@@ -569,7 +606,7 b' Each entry is a pair (FILE-NAME . STATUS' | |||
|
569 | 606 | ("I " . ignored) |
|
570 | 607 | ("? " . nil))))) |
|
571 | 608 | (name (substring entry 2))) |
|
572 |
(setq result (cons (cons name state) result)))))) |
|
|
609 | (setq result (cons (cons name state) result)))))) | |
|
573 | 610 | |
|
574 | 611 | (defmacro hg-view-output (args &rest body) |
|
575 | 612 | "Execute BODY in a clean buffer, then quickly display that buffer. |
@@ -646,25 +683,28 b' Always returns a valid, hopefully sane, ' | |||
|
646 | 683 | |
|
647 | 684 | ;;; Hooks. |
|
648 | 685 | |
|
686 | (defun hg-mode-line-internal (status parents) | |
|
687 | (setq hg-status status | |
|
688 | hg-mode (and status (concat " Hg:" | |
|
689 | parents | |
|
690 | (cdr (assq status | |
|
691 | '((normal . "") | |
|
692 | (removed . "r") | |
|
693 | (added . "a") | |
|
694 | (deleted . "!") | |
|
695 | (modified . "m")))))))) | |
|
696 | ||
|
649 | 697 | (defun hg-mode-line (&optional force) |
|
650 | 698 | "Update the modeline with the current status of a file. |
|
651 | 699 | An update occurs if optional argument FORCE is non-nil, |
|
652 | 700 | hg-update-modeline is non-nil, or we have not yet checked the state of |
|
653 | 701 | the file." |
|
654 | (when (and (hg-root) (or force hg-update-modeline (not hg-mode))) | |
|
655 | (let ((status (hg-file-status buffer-file-name)) | |
|
656 | (parents | |
|
657 | (split-string (hg-chomp | |
|
658 | (hg-run0 "parents" "--template" "{rev}\n")) "\n"))) | |
|
659 | (setq hg-status status | |
|
660 | hg-mode (and status (concat " Hg:" | |
|
661 | (mapconcat 'identity parents "+") | |
|
662 | (cdr (assq status | |
|
663 | '((normal . "") | |
|
664 | (removed . "r") | |
|
665 | (added . "a") | |
|
666 | (modified . "m"))))))) | |
|
667 | status))) | |
|
702 | (let ((root (hg-root))) | |
|
703 | (when (and root (or force hg-update-modeline (not hg-mode))) | |
|
704 | (let ((status (hg-file-status buffer-file-name)) | |
|
705 | (parents (hg-parents-for-mode-line root))) | |
|
706 | (hg-mode-line-internal status parents) | |
|
707 | status)))) | |
|
668 | 708 | |
|
669 | 709 | (defun hg-mode (&optional toggle) |
|
670 | 710 | "Minor mode for Mercurial distributed SCM integration. |
@@ -844,8 +884,7 b' hg-commit-allow-empty-file-list is nil, ' | |||
|
844 | 884 | (let ((buf hg-prev-buffer)) |
|
845 | 885 | (kill-buffer nil) |
|
846 | 886 | (switch-to-buffer buf)) |
|
847 | (hg-do-across-repo root | |
|
848 | (hg-mode-line))))) | |
|
887 | (hg-update-mode-lines root)))) | |
|
849 | 888 | |
|
850 | 889 | (defun hg-commit-mode () |
|
851 | 890 | "Mode for describing a commit of changes to a Mercurial repository. |
General Comments 0
You need to be logged in to leave comments.
Login now