(vc-git-dir-extra-headers): Add keymap and mouse-face
authorDan Nicolaescu <dann@ics.uci.edu>
Sun, 20 Sep 2009 19:51:35 +0000 (19:51 +0000)
committerDan Nicolaescu <dann@ics.uci.edu>
Sun, 20 Sep 2009 19:51:35 +0000 (19:51 +0000)
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.

lisp/ChangeLog
lisp/vc-git.el

index 9efe3f3..2cbd183 100644 (file)
@@ -1,6 +1,13 @@
 2009-09-20  Dan Nicolaescu  <dann@ics.uci.edu>
 
-       * register.el (ctl-x-r-map): Define the keys here instead of using autoload. 
+       * vc-git.el (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.
+
+       * register.el (ctl-x-r-map): Define the keys here instead of using autoload.
 
 2009-09-20  Thierry Volpiatto  <thierry.volpiatto@gmail.com>
 
index 8d7b1e8..fe7b95c 100644 (file)
@@ -408,7 +408,6 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
     (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
        (progn
          (setq branch (match-string 2 str))
-         (message "branch (%s)" branch)
          (setq remote
                (with-output-to-string
                  (with-current-buffer standard-output
@@ -424,7 +423,6 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
            (setq remote-url (match-string 1 remote-url))))
       "not (detached HEAD)")
     ;; FIXME: maybe use a different face when nothing is stashed.
-    (when (string= stash "") (setq stash "Nothing stashed"))
     (concat
      (propertize "Branch     : " 'face 'font-lock-type-face)
      (propertize branch
@@ -436,10 +434,20 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
        (propertize remote-url
                    'face 'font-lock-variable-name-face)))
      "\n"
-     (propertize "Stash      : " 'face 'font-lock-type-face)
-     (propertize
-      stash
-       'face 'font-lock-variable-name-face))))
+     (if stash
+       (concat
+       (propertize "Stash      :\n" 'face 'font-lock-type-face)
+       (mapconcat
+        (lambda (x)
+          (propertize x
+                      'face 'font-lock-variable-name-face
+                      'mouse-face 'highlight
+                      'keymap vc-git-stash-map))
+        stash "\n"))
+       (concat
+       (propertize "Stash      : " 'face 'font-lock-type-face)
+       (propertize "Nothing stashed"
+                   'face 'font-lock-variable-name-face))))))
 
 ;;; STATE-CHANGING FUNCTIONS
 
@@ -797,10 +805,38 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
   (pop-to-buffer (current-buffer)))
 
 (defun vc-git-stash-list ()
-  (replace-regexp-in-string
-   "\n" "\n             "
-   (replace-regexp-in-string
-    "^stash@" "" (vc-git--run-command-string nil "stash" "list"))))
+  (delete
+   ""
+   (split-string
+    (replace-regexp-in-string
+     "^stash@" "             " (vc-git--run-command-string nil "stash" "list"))
+    "\n")))
+
+(defun vc-git-stash-get-at-point (point)
+  (save-excursion
+    (goto-char point)
+    (beginning-of-line)
+    (if (looking-at "^ +\\({[0-9]+}\\):")
+       (match-string 1)
+      (error "Cannot find stash at point"))))
+
+(defun vc-git-stash-delete-at-point ()
+  (interactive)
+  (let ((stash (vc-git-stash-get-at-point (point))))
+    (when (y-or-n-p (format "Remove stash %s ?" stash))
+      (vc-git--run-command-string nil "stash" "drop" (format "stash@%s" stash))
+      (vc-dir-refresh))))
+
+(defun vc-git-stash-show-at-point ()
+  (interactive)
+  (vc-git-stash-show (format "stash@%s" (vc-git-stash-get-at-point (point)))))
+
+(defvar vc-git-stash-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-k" 'vc-git-stash-delete-at-point)
+    (define-key map "=" 'vc-git-stash-show-at-point)
+    (define-key map "\C-m" 'vc-git-stash-show-at-point)
+    map))
 
 \f
 ;;; Internal commands