Mercurial > emacs
comparison lisp/vc-git.el @ 106384:8272f561b710
Support applying stashes. Improve UI.
* vc-git.el (vc-git-dir-extra-headers): Add tooltips.
(vc-git-stash-apply, vc-git-stash-pop)
(vc-git-stash-apply-at-point, vc-git-stash-pop-at-point)
(vc-git-stash-menu): New functions.
(vc-git-stash-menu-map): New variable.
(vc-git-stash-map): Add bindings to popup a menu and to apply stashes.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Thu, 03 Dec 2009 04:08:08 +0000 |
parents | 1c9648ddfd5e |
children | 783bd2552dd4 |
comparison
equal
deleted
inserted
replaced
106383:09d0cce6cdd3 | 106384:8272f561b710 |
---|---|
403 "Return a list of (FILE STATE EXTRA) entries for FILES in DIR." | 403 "Return a list of (FILE STATE EXTRA) entries for FILES in DIR." |
404 (vc-git-dir-status-goto-stage 'update-index files update-function)) | 404 (vc-git-dir-status-goto-stage 'update-index files update-function)) |
405 | 405 |
406 (defvar vc-git-stash-map | 406 (defvar vc-git-stash-map |
407 (let ((map (make-sparse-keymap))) | 407 (let ((map (make-sparse-keymap))) |
408 ;; Turn off vc-dir marking | |
409 (define-key map [mouse-2] 'ignore) | |
410 | |
411 (define-key map [down-mouse-3] 'vc-git-stash-menu) | |
408 (define-key map "\C-k" 'vc-git-stash-delete-at-point) | 412 (define-key map "\C-k" 'vc-git-stash-delete-at-point) |
409 (define-key map "=" 'vc-git-stash-show-at-point) | 413 (define-key map "=" 'vc-git-stash-show-at-point) |
410 (define-key map "\C-m" 'vc-git-stash-show-at-point) | 414 (define-key map "\C-m" 'vc-git-stash-show-at-point) |
415 (define-key map "A" 'vc-git-stash-apply-at-point) | |
416 (define-key map "P" 'vc-git-stash-pop-at-point) | |
417 map)) | |
418 | |
419 (defvar vc-git-stash-menu-map | |
420 (let ((map (make-sparse-keymap "Git Stash"))) | |
421 (define-key map [de] | |
422 '(menu-item "Delete stash" vc-git-stash-delete-at-point | |
423 :help "Delete the current stash")) | |
424 (define-key map [ap] | |
425 '(menu-item "Apply stash" vc-git-stash-apply-at-point | |
426 :help "Apply the current stash and keep it in the stash list")) | |
427 (define-key map [po] | |
428 '(menu-item "Apply and remove stash (pop)" vc-git-stash-pop-at-point | |
429 :help "Apply the current stash and remove it")) | |
430 (define-key map [sh] | |
431 '(menu-item "Show stash" vc-git-stash-show-at-point | |
432 :help "Show the contents of the current stash")) | |
411 map)) | 433 map)) |
412 | 434 |
413 (defun vc-git-dir-extra-headers (dir) | 435 (defun vc-git-dir-extra-headers (dir) |
414 (let ((str (with-output-to-string | 436 (let ((str (with-output-to-string |
415 (with-current-buffer standard-output | 437 (with-current-buffer standard-output |
416 (vc-git--out-ok "symbolic-ref" "HEAD")))) | 438 (vc-git--out-ok "symbolic-ref" "HEAD")))) |
417 (stash (vc-git-stash-list)) | 439 (stash (vc-git-stash-list)) |
440 (stash-help-echo "Use M-x vc-git-stash to create stashes.") | |
418 branch remote remote-url) | 441 branch remote remote-url) |
419 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) | 442 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) |
420 (progn | 443 (progn |
421 (setq branch (match-string 2 str)) | 444 (setq branch (match-string 2 str)) |
422 (setq remote | 445 (setq remote |
445 (propertize remote-url | 468 (propertize remote-url |
446 'face 'font-lock-variable-name-face))) | 469 'face 'font-lock-variable-name-face))) |
447 "\n" | 470 "\n" |
448 (if stash | 471 (if stash |
449 (concat | 472 (concat |
450 (propertize "Stash :\n" 'face 'font-lock-type-face) | 473 (propertize "Stash :\n" 'face 'font-lock-type-face |
474 'help-echo stash-help-echo) | |
451 (mapconcat | 475 (mapconcat |
452 (lambda (x) | 476 (lambda (x) |
453 (propertize x | 477 (propertize x |
454 'face 'font-lock-variable-name-face | 478 'face 'font-lock-variable-name-face |
455 'mouse-face 'highlight | 479 'mouse-face 'highlight |
480 'help-echo "mouse-3: Show stash menu\nRET: Show stash\nA: Apply stash\nP: Apply and remove stash (pop)\nC-k: Delete stash" | |
456 'keymap vc-git-stash-map)) | 481 'keymap vc-git-stash-map)) |
457 stash "\n")) | 482 stash "\n")) |
458 (concat | 483 (concat |
459 (propertize "Stash : " 'face 'font-lock-type-face) | 484 (propertize "Stash : " 'face 'font-lock-type-face |
485 'help-echo stash-help-echo) | |
460 (propertize "Nothing stashed" | 486 (propertize "Nothing stashed" |
487 'help-echo stash-help-echo | |
461 'face 'font-lock-variable-name-face)))))) | 488 'face 'font-lock-variable-name-face)))))) |
462 | 489 |
463 ;;; STATE-CHANGING FUNCTIONS | 490 ;;; STATE-CHANGING FUNCTIONS |
464 | 491 |
465 (defun vc-git-create-repo () | 492 (defun vc-git-create-repo () |
814 (set-buffer "*vc-git-stash*") | 841 (set-buffer "*vc-git-stash*") |
815 (diff-mode) | 842 (diff-mode) |
816 (setq buffer-read-only t) | 843 (setq buffer-read-only t) |
817 (pop-to-buffer (current-buffer))) | 844 (pop-to-buffer (current-buffer))) |
818 | 845 |
846 (defun vc-git-stash-apply (name) | |
847 "Apply stash NAME." | |
848 (interactive "sApply stash: ") | |
849 (vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" name) | |
850 (vc-resynch-buffer (vc-git-root default-directory) t t)) | |
851 | |
852 (defun vc-git-stash-pop (name) | |
853 "Pop stash NAME." | |
854 (interactive "sPop stash: ") | |
855 (vc-git-command "*vc-git-stash*" 0 nil "stash" "pop" "-q" name) | |
856 (vc-resynch-buffer (vc-git-root default-directory) t t)) | |
857 | |
819 (defun vc-git-stash-list () | 858 (defun vc-git-stash-list () |
820 (delete | 859 (delete |
821 "" | 860 "" |
822 (split-string | 861 (split-string |
823 (replace-regexp-in-string | 862 (replace-regexp-in-string |
840 (vc-dir-refresh)))) | 879 (vc-dir-refresh)))) |
841 | 880 |
842 (defun vc-git-stash-show-at-point () | 881 (defun vc-git-stash-show-at-point () |
843 (interactive) | 882 (interactive) |
844 (vc-git-stash-show (format "stash@%s" (vc-git-stash-get-at-point (point))))) | 883 (vc-git-stash-show (format "stash@%s" (vc-git-stash-get-at-point (point))))) |
884 | |
885 (defun vc-git-stash-apply-at-point () | |
886 (interactive) | |
887 (vc-git-stash-apply (format "stash@%s" (vc-git-stash-get-at-point (point))))) | |
888 | |
889 (defun vc-git-stash-pop-at-point () | |
890 (interactive) | |
891 (vc-git-stash-pop (format "stash@%s" (vc-git-stash-get-at-point (point))))) | |
892 | |
893 (defun vc-git-stash-menu (e) | |
894 (interactive "e") | |
895 (vc-dir-at-event e (popup-menu vc-git-stash-menu-map e))) | |
845 | 896 |
846 | 897 |
847 ;;; Internal commands | 898 ;;; Internal commands |
848 | 899 |
849 (defun vc-git-command (buffer okstatus file-or-list &rest flags) | 900 (defun vc-git-command (buffer okstatus file-or-list &rest flags) |