comparison lisp/vc-git.el @ 105129:5fc493595567

(vc-git-dir-extra-headers): Add keymap and mouse-face properties to the stash strings. (vc-git-stash-list): Return a list of strings. (vc-git-stash-get-at-point, vc-git-stash-delete-at-point) (vc-git-stash-show-at-point): New functions. (vc-git-stash-map): New keymap.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 20 Sep 2009 19:51:35 +0000
parents f43dfae3e132
children 1987d1800365
comparison
equal deleted inserted replaced
105128:c4c3db18d05c 105129:5fc493595567
406 (stash (vc-git-stash-list)) 406 (stash (vc-git-stash-list))
407 branch remote remote-url) 407 branch remote remote-url)
408 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) 408 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
409 (progn 409 (progn
410 (setq branch (match-string 2 str)) 410 (setq branch (match-string 2 str))
411 (message "branch (%s)" branch)
412 (setq remote 411 (setq remote
413 (with-output-to-string 412 (with-output-to-string
414 (with-current-buffer standard-output 413 (with-current-buffer standard-output
415 (vc-git--out-ok "config" (concat "branch." branch ".remote"))))) 414 (vc-git--out-ok "config" (concat "branch." branch ".remote")))))
416 (when (string-match "\\([^\n]+\\)" remote) 415 (when (string-match "\\([^\n]+\\)" remote)
422 (vc-git--out-ok "config" (concat "remote." remote ".url")))))) 421 (vc-git--out-ok "config" (concat "remote." remote ".url"))))))
423 (when (string-match "\\([^\n]+\\)" remote-url) 422 (when (string-match "\\([^\n]+\\)" remote-url)
424 (setq remote-url (match-string 1 remote-url)))) 423 (setq remote-url (match-string 1 remote-url))))
425 "not (detached HEAD)") 424 "not (detached HEAD)")
426 ;; FIXME: maybe use a different face when nothing is stashed. 425 ;; FIXME: maybe use a different face when nothing is stashed.
427 (when (string= stash "") (setq stash "Nothing stashed"))
428 (concat 426 (concat
429 (propertize "Branch : " 'face 'font-lock-type-face) 427 (propertize "Branch : " 'face 'font-lock-type-face)
430 (propertize branch 428 (propertize branch
431 'face 'font-lock-variable-name-face) 429 'face 'font-lock-variable-name-face)
432 (when remote 430 (when remote
434 "\n" 432 "\n"
435 (propertize "Remote : " 'face 'font-lock-type-face) 433 (propertize "Remote : " 'face 'font-lock-type-face)
436 (propertize remote-url 434 (propertize remote-url
437 'face 'font-lock-variable-name-face))) 435 'face 'font-lock-variable-name-face)))
438 "\n" 436 "\n"
439 (propertize "Stash : " 'face 'font-lock-type-face) 437 (if stash
440 (propertize 438 (concat
441 stash 439 (propertize "Stash :\n" 'face 'font-lock-type-face)
442 'face 'font-lock-variable-name-face)))) 440 (mapconcat
441 (lambda (x)
442 (propertize x
443 'face 'font-lock-variable-name-face
444 'mouse-face 'highlight
445 'keymap vc-git-stash-map))
446 stash "\n"))
447 (concat
448 (propertize "Stash : " 'face 'font-lock-type-face)
449 (propertize "Nothing stashed"
450 'face 'font-lock-variable-name-face))))))
443 451
444 ;;; STATE-CHANGING FUNCTIONS 452 ;;; STATE-CHANGING FUNCTIONS
445 453
446 (defun vc-git-create-repo () 454 (defun vc-git-create-repo ()
447 "Create a new Git repository." 455 "Create a new Git repository."
795 (diff-mode) 803 (diff-mode)
796 (setq buffer-read-only t) 804 (setq buffer-read-only t)
797 (pop-to-buffer (current-buffer))) 805 (pop-to-buffer (current-buffer)))
798 806
799 (defun vc-git-stash-list () 807 (defun vc-git-stash-list ()
800 (replace-regexp-in-string 808 (delete
801 "\n" "\n " 809 ""
802 (replace-regexp-in-string 810 (split-string
803 "^stash@" "" (vc-git--run-command-string nil "stash" "list")))) 811 (replace-regexp-in-string
812 "^stash@" " " (vc-git--run-command-string nil "stash" "list"))
813 "\n")))
814
815 (defun vc-git-stash-get-at-point (point)
816 (save-excursion
817 (goto-char point)
818 (beginning-of-line)
819 (if (looking-at "^ +\\({[0-9]+}\\):")
820 (match-string 1)
821 (error "Cannot find stash at point"))))
822
823 (defun vc-git-stash-delete-at-point ()
824 (interactive)
825 (let ((stash (vc-git-stash-get-at-point (point))))
826 (when (y-or-n-p (format "Remove stash %s ?" stash))
827 (vc-git--run-command-string nil "stash" "drop" (format "stash@%s" stash))
828 (vc-dir-refresh))))
829
830 (defun vc-git-stash-show-at-point ()
831 (interactive)
832 (vc-git-stash-show (format "stash@%s" (vc-git-stash-get-at-point (point)))))
833
834 (defvar vc-git-stash-map
835 (let ((map (make-sparse-keymap)))
836 (define-key map "\C-k" 'vc-git-stash-delete-at-point)
837 (define-key map "=" 'vc-git-stash-show-at-point)
838 (define-key map "\C-m" 'vc-git-stash-show-at-point)
839 map))
804 840
805 841
806 ;;; Internal commands 842 ;;; Internal commands
807 843
808 (defun vc-git-command (buffer okstatus file-or-list &rest flags) 844 (defun vc-git-command (buffer okstatus file-or-list &rest flags)