Edit, I've since written made a version of this which parses the diff hunks, here.
Posting own answer, it works but it has some limitations.
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalEdit, I've since written made a version of this which parses the diff hunks, here.
Posting own answer, it works but it has some limitations.
Posting own answer, it works but it has some limitations.
Edit, I've since written made a version of this which parses the diff hunks, here.
Posting own answer, it works but it has some limitations.
;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame,. jumpingJumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ( (current-filename-rel (file-relative-name current-filename default-directory))) (file-relative-namewhen current(search-filename defaultforward-directory)regexp )(concat ) "^" (when ;; Prefix (search'-forward-regexp- '. (concat "\\-\\-\\-[[:blank:]]+.*\n" ;; Prefix '+++ '. "^\\++[["\\+\\+\\+[[:blank:]]+" ;; Optional 'b/' (git quirk). "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' (subversion ;; Subversion quirk). "\\(\\|[[:blank:]]+.*\\)"\n" "$""@@[[:blank:]]+.*@@" ;; may have trailing text, ignore this. ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\( \\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) ) ;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame, jumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ( (current-filename-rel (file-relative-name current-filename default-directory) ) ) (when (search-forward-regexp (concat ;; Prefix '+++ '. "^\\++[[:blank:]]+" ;; Optional 'b/' (git quirk). "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' (subversion quirk). "\\(\\|[[:blank:]]+.*\\)" "$" ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\( \\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) ) ;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame. Jumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ((current-filename-rel (file-relative-name current-filename default-directory))) (when (search-forward-regexp (concat "^" ;; Prefix '--- '. "\\-\\-\\-[[:blank:]]+.*\n" ;; Prefix '+++ '. "\\+\\+\\+[[:blank:]]+" ;; Optional 'b/'. "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' ;; Subversion quirk. "\\(\\|[[:blank:]]+.*\\)\n" "@@[[:blank:]]+.*@@" ;; may have trailing text, ignore this. ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\( \\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) ) ;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame, jumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ( (current-filename-rel (file-relative-name current-filename default-directory) ) ) (when (search-forward-regexp (concat ;; Prefix '+++ '. "^\\++[[:spaceblank:]]+" ;; Optional 'b/' (git quirk). "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' ;; Subversion(subversion quirk). "\\(\\|[[:spaceblank:]]+.*\\)" "$" ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\([[:space:]]\\|\\+\\ \\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) ) ;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame, jumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ( (current-filename-rel (file-relative-name current-filename default-directory) ) ) (when (search-forward-regexp (concat ;; Prefix '+++ '. "^\\++[[:space:]]+" ;; Optional 'b/'. "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' ;; Subversion quirk. "\\(\\|[[:space:]]+.*\\)" "$" ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\([[:space:]]\\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) ) ;; Override pop-up-windows, (defun vc-root-diff-fullscreen-and-jump-to-point () " Open a diff of the repository in the current frame, jumping to the file, then line if possible. " (interactive) (let ( (pop-up-windows nil) (current-filename (buffer-file-name)) ;; TODO, parse the diff chunks instead of searching for plain text. ;; not urgent. (current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ;; Chars to move backwards (so we keep the same relative point). (point-offset (- (save-excursion (end-of-line) (point)) (point))) ) (when (vc-root-diff nil) ;; It's possible we don't have a file. (when current-filename ;; Go to the file in the diff which we were previously viewing. (let ( (current-filename-rel (file-relative-name current-filename default-directory) ) ) (when (search-forward-regexp (concat ;; Prefix '+++ '. "^\\++[[:blank:]]+" ;; Optional 'b/' (git quirk). "\\(\\|b/\\)" (regexp-quote current-filename-rel) ;; Optional ' (some text)' (subversion quirk). "\\(\\|[[:blank:]]+.*\\)" "$" ) nil t 1 ) ;; Now search for the current line. (when (search-forward-regexp (concat ;; Space or '+' line prefix. "^\\( \\|\\+\\)" (regexp-quote current-line) "$" ) nil t 1 ) (backward-char point-offset) ) ) ) ) ) ) )