Commit 23dafac32d5f

Vincent Demeester <vincent@sbr.pm>
2025-05-28 18:51:38
tools/emacs/mini : more vcs and diff configuration
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent cde1f48
Changed files (2)
tools
emacs
mini
tools/emacs/mini/site-lisp/vde-vcs.el
@@ -8,6 +8,30 @@
 
 ;;; Code:
 
+;;;###autoload
+(defun vde/vc-browse-remote (&optional current-line)
+  "Open the repository's remote URL in the browser.
+If CURRENT-LINE is non-nil, point to the current branch, file, and line.
+Otherwise, open the repository's main page."
+  (interactive "P")
+  (let* ((remote-url (string-trim (vc-git--run-command-string nil "config" "--get" "remote.origin.url")))
+	 (branch (string-trim (vc-git--run-command-string nil "rev-parse" "--abbrev-ref" "HEAD")))
+	 (file (string-trim (file-relative-name (buffer-file-name) (vc-root-dir))))
+	 (line (line-number-at-pos)))
+    (message "Opening remote on browser: %s" remote-url)
+    (if (and remote-url (string-match "\\(?:git@\\|https://\\)\\([^:/]+\\)[:/]\\(.+?\\)\\(?:\\.git\\)?$" remote-url))
+	(let ((host (match-string 1 remote-url))
+	      (path (match-string 2 remote-url)))
+	  ;; Convert SSH URLs to HTTPS (e.g., git@github.com:user/repo.git -> https://github.com/user/repo)
+	  (when (string-prefix-p "git@" host)
+	    (setq host (replace-regexp-in-string "^git@" "" host)))
+	  ;; Construct the appropriate URL based on CURRENT-LINE
+	  (browse-url
+	   (if current-line
+	       (format "https://%s/%s/blob/%s/%s#L%d" host path branch file line)
+	     (format "https://%s/%s" host path))))
+      (message "Could not determine repository URL"))))
+
 ;;;###autoload
 (defun vde/gh-get-current-repo ()
   "Get the current repository name using the `gh' command line."
tools/emacs/mini/init.el
@@ -559,7 +559,8 @@
          ("C-x u" . vundo)))
 
 (use-package vde-vcs
-  :commands (vde/gh-get-current-repo))
+  :commands (vde/gh-get-current-repo vde/vc-browse-remote)
+  :bind (("C-x v B" . vde/vc-browse-remote)))
 
 (use-package project-func
   :commands (vde/project-magit-status vde/project-eat vde/project-vterm vde/project-run-in-vterm vde/project-try-local vde/open-readme))
@@ -626,6 +627,24 @@
     '(1 "=o" "Set push option" "--push-option="))  ;; Will prompt, can only set one extra
   )
 
+(use-package ediff
+  :commands (ediff ediff-files ediff-merge ediff3 ediff-files3 ediff-merge3)
+  :custom
+  (ediff-window-setup-function 'ediff-setup-windows-plain)
+  (ediff-split-window-function 'split-window-horizontally)
+  (ediff-diff-options "-w")
+  :hook
+  (ediff-after-quit-hook-internal . winner-undo))
+
+(use-package diff
+  :custom
+  (diff-default-read-only nil)
+  (diff-advance-after-apply-hunk t)
+  (diff-update-on-the-fly t)
+  (diff-refine 'font-lock)
+  (diff-font-lock-prettify nil)
+  (diff-font-lock-syntax nil))
+
 (use-package gitconfig-mode
   :commands (gitconfig-mode)
   :mode (("/\\.gitconfig\\'"  . gitconfig-mode)