Skip to main content
added 156 characters in body
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133

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.

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.

added 65 characters in body
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133
;; 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) ) ) ) ) ) ) ) 
deleted 10 characters in body
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133
;; 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) ) ) ) ) ) ) ) 
deleted 1 character in body
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133
Loading
added 426 characters in body
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133
Loading
Source Link
ideasman42
  • 9.5k
  • 2
  • 38
  • 133
Loading