summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-06-08 20:55:27 -0400
committerKyle Meyer <kyle@kyleam.com>2015-06-08 20:55:27 -0400
commit7c480c975550a3e91d3c408435f26ab006843206 (patch)
treec3402571df722174604fb33e085c175cbf13ce05 /lisp
parentac2b6e4585a2b9a32d0908d0092af3b005f40e65 (diff)
downloademacs.d-7c480c975550a3e91d3c408435f26ab006843206.tar.gz
Merge show-commit-under-point commands
Use a prefix argument instead of having separate commands for switching projects.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-git.el33
1 files changed, 17 insertions, 16 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 2cfee16..62b6513 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -42,20 +42,22 @@ a proper commit."
(interactive)
(magit-run-git "commit" "--all" "--message=auto"))
-(defun km/magit-show-commit-under-point ()
- "Pass text at point as commit to `magit-show-commit'.
-This is useful for commit IDs in files and log messages."
- (interactive)
- (--when-let (thing-at-point 'word)
- (magit-show-commit it)))
-
-(defun km/magit-show-project-commit-under-point ()
- "Show commit under point for a selected project."
- (interactive)
- (--when-let (thing-at-point 'word)
- (let ((projectile-switch-project-action
- (lambda () (magit-show-commit it))))
- (projectile-switch-project))))
+(defun km/magit-show-commit-at-point (&optional choose-project)
+ "Show commit point.
+If there is no current project or if the prefix argument
+CHOOSE-PROJECT is non-nil, prompt for the project name."
+ (interactive "P")
+ (if (save-excursion (skip-chars-backward "A-z0-9")
+ (looking-at "\\b[A-z0-9]\\{4,40\\}\\b"))
+ (let* ((hash (match-string-no-properties 0))
+ (project
+ (and (or choose-project
+ (not (projectile-project-p)))
+ (completing-read "Project: "
+ (projectile-relevant-known-projects))))
+ (default-directory (or project default-directory)))
+ (magit-show-commit hash))
+ (user-error "No hash found at point")))
(defun km/magit-commit-extend-all ()
"Run `magit-commit-extend' with '--all' flag.
@@ -285,8 +287,7 @@ the file name if NO-DIRECTORY is non-nil."
(define-key magit-refs-mode-map "j" 'avy-goto-subword-1)
(define-key magit-cherry-mode-map "j" 'avy-goto-subword-1)
- (define-key km/git-map "c" 'km/magit-show-commit-under-point)
- (define-key km/git-map "C" 'km/magit-show-project-commit-under-point)
+ (define-key km/git-map "." 'km/magit-show-commit-at-point)
(define-key km/git-map "e" 'km/magit-commit-extend-all)
(define-key km/git-map "f" 'km/magit-checkout-file)
(define-key km/git-map "l" 'magit-log-buffer-file)