Hi, Cool, just when I commented in gitorious that it would be nice to have precisely this feature :) A few comments below.
Moritz Bunkus <[email protected]> writes: > +(define-derived-mode magit-show-branches-mode text-mode "Magit Branches" > + (use-local-map magit-show-branches-map)) define-derived-mode already sets up magit-show-branches-mode-map and automatically uses it. Just rename and move your map definition above the mode definition so that your data will be used. > +(defvar magit-show-branches-map > + (let ((map (make-sparse-keymap))) > + (define-key map (kbd "b") 'magit-branches-window-checkout) > + (define-key map (kbd "k") 'magit-remove-branch) > + (define-key map (kbd "m") 'magit-branches-window-manual-merge) > + (define-key map (kbd "M") 'magit-branches-window-automatic-merge) > + (define-key map (kbd "$") 'magit-display-process) > + (define-key map (kbd "q") 'magit-quit-branches-window) > + (define-key map (kbd "V") 'magit-show-branches) > + map)) > + > +(defun magit-quit-branches-window () > + "Bury the branches buffer and delete its window." This doesn't sound right, you talk about burying but you pass kill argument to quit-view. > + (interactive) > + (quit-window t) > + (delete-window)) > + > +(defun magit--branch-name-at-point () > + "Get the branch name in the line at point." > + (save-excursion > + (save-match-data > + (beginning-of-line) > + (if (not (looking-at "^\s*\\*?\s*\\([^\s]+\\)")) Did you perhaps mean: (looking-at "^\\s *\\*?\\s *\\([^\\s ]+\\)") ? > + (error "No branch found in current line") > + (match-string 1))))) > + > +(defun magit-branches-window-checkout () > + "Checks out the branch in the line at point." > + (interactive) > + (magit-run-git "checkout" (magit--branch-name-at-point)) > + (save-excursion > + (magit-show-branches))) > + > +(defun magit-remove-branch (&optional force) > + "Removes the branch in the line at point. With prefix force the > +removal even it it hasn't been merged." Emacs Lisp convention would be to use imperative form (Remove the branch...) and have just the first sentence on the first line and start the second sentence on the second line (works better with apropos, for example). > + (interactive "P") > + (let ((args (list "branch" > + (if force "-D" "-d") > + (magit--branch-name-at-point)))) > + (save-excursion > + (apply 'magit-run-git args) > + (magit-show-branches)))) magit-show-branches lists remote branches too but I think this fails to remove them because for them you'd need to specify -r (and strip (or maybe rather make magit--branch-name-at-point strip) "remotes/" prefix). > +(defun magit-branches-window-manual-merge () > + "Merges the branch at point manually." > + (interactive) > + (magit-manual-merge (magit--branch-name-at-point)) > + (magit-show-branches)) > + > +(defun magit-branches-window-automatic-merge () > + "Merges the branch at point automatically." > + (interactive) > + (magit-automatic-merge (magit--branch-name-at-point)) > + (magit-show-branches)) > + > +(defvar magit-branches-buffer-name "*magit-branches*") > + > (defun magit-show-branches () > "Show all of the current branches in other-window." Did you perhaps mean "Show all branches..."? > (interactive) > (save-selected-window > - (switch-to-buffer-other-window "*magit-branches*") > - (erase-buffer) > - (insert (magit-git-string "branch" "-va")) > - (insert "\n"))) > + (if (not (string= (buffer-name) magit-branches-buffer-name)) > + (switch-to-buffer-other-window magit-branches-buffer-name)) Just to let you know, there's `unless' for such (if (not ...) ...) cases without an else branch. > + (let ((inhibit-read-only t)) > + (erase-buffer) > + (insert (magit-git-string "branch" "-va")) > + (insert "\n")) > + (magit-show-branches-mode) > + (setq buffer-read-only t))) > > (defvar magit-ediff-file) > (defvar magit-ediff-windows) -- Hannu To unsubscribe from this group, send email to magit+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
