diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-06-08 20:55:37 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-06-08 20:55:37 -0400 |
commit | e62ca119c70fab3840e9e4917fe78d1417b7328d (patch) | |
tree | 663425513b40107e98be288069a4b6d06cecd1d7 /lisp | |
parent | 7c480c975550a3e91d3c408435f26ab006843206 (diff) | |
download | emacs.d-e62ca119c70fab3840e9e4917fe78d1417b7328d.tar.gz |
Add git-shorten-hash-at-point command
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-git.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el index 62b6513..225330b 100644 --- a/lisp/init-git.el +++ b/lisp/init-git.el @@ -368,4 +368,36 @@ the file name if NO-DIRECTORY is non-nil." (setq magit-annex-all-action-arguments (delete "--auto" magit-annex-all-action-arguments))) + +;;; Other git + +(defun km/git-shorten-hash-at-point (&optional n) + "Shorten hash at point to N characters. +N defaults to 10 and can be controlled by a numeric prefix +argument." + (interactive (list (or (and current-prefix-arg + (prefix-numeric-value current-prefix-arg)) + 10))) + (cond + ((< n 4) + (user-error "Hash must be at least 4 characters")) + ((>= n 40) + (user-error "Full hashes are 40 characters")) + ((> n 30) + (message "That doesn't seem incredibly useful, but OK"))) + (let ((offset (- (skip-chars-backward "A-z0-9")))) + (if (looking-at "\\b[A-z0-9]\\{5,40\\}\\b") + (let ((hash-len (- (match-end 0) (match-beginning 0))) + (hash (match-string 0))) + (when (< hash-len n) + (user-error "Desired hash length is greater than current")) + (replace-match (substring hash 0 n) 'fixedcase) + (when (< offset n) + (skip-chars-backward "A-z0-9") + (goto-char (+ (point) offset)))) + (goto-char (+ (point) offset)) + (user-error "No hash found at point")))) + +(define-key km/git-map "n" 'km/git-shorten-hash-at-point) + (provide 'init-git) |