@@ -359,19 +359,8 @@ mode.")
359359; ;
360360; ; (setq agitate-log-edit-informative-show-root-log nil
361361; ; agitate-log-edit-informative-show-files nil))
362- (use-package cond-let
363- :ensure (:host github :repo " tarsius/cond-let" ))
364-
365- (use-package llama
366- :ensure (:host github :repo " tarsius/llama" ))
367362
368363; ;; Interactive and powerful git front-end (Magit)
369- (use-package transient
370- :ensure (:host github :repo " magit/transient" )
371- :defer t
372- :config
373- (setq transient-show-popup 0.2 ))
374- (use-package with-editor :ensure (:host github :repo " magit/with-editor" ))
375364
376365(defgroup gas/vcs nil
377366 " VCS utilities."
@@ -439,137 +428,172 @@ once no Magit status windows remain."
439428 (dolist (buf (magit-mode-get-buffers))
440429 (vcs--kill-buffer buf)))))
441430
442- (defun gas/get-display-window (source-window &optional create-if-needed )
443- " Return a good window to display Magit aux buffers near SOURCE-WINDOW.
444- Prefer a right neighbor, then a non-minibuffer, non-dedicated window below.
445- If CREATE-IF-NEEDED is non-nil, split SOURCE-WINDOW below."
446- (let* ((valid-win-p
447- (lambda (w )
448- (and w (window-live-p w)
449- (not (window-minibuffer-p w))
450- (not (window-dedicated-p w))))))
451- (or
452- (let ((right (window-in-direction 'right source-window)))
453- (when (funcall valid-win-p right) right))
454- (let ((below (window-in-direction 'below source-window)))
455- (when (funcall valid-win-p below) below))
456- (when create-if-needed
457- (when (window-live-p source-window)
458- (let ((new (split-window source-window nil 'below )))
459- (when (funcall valid-win-p new) new)))))))
460-
461- (defun gas/magit-display-buffer (buffer _alist )
462- " Display Magit BUFFER in a neighbor window chosen by `my/get-display-window' ."
463- (when-let* ((target (gas/get-display-window (selected-window ) t )))
464- (set-window-buffer target buffer)
465- target))
466-
467- ; ; (defun my/get-display-window
468- ; ; (source-window &optional create-if-needed)
469- ; ; (save-excursion
470- ; ; (goto-char (window-start source-window))
471- ; ; (or
472- ; ; (window-in-direction 'right source-window)
473- ; ; (let ((below-window (window-in-direction 'below source-window)))
474- ; ; (when (and below-window
475- ; ; (not (window-minibuffer-p below-window)))
476- ; ; below-window))
477- ; ; (when create-if-needed
478- ; ; (split-window source-window nil 'below)))))
479-
480- ; ; (defun my/magit-display-buffer (buffer alist)
481- ; ; (when-let* ((target-window (my/get-display-window
482- ; ; (selected-window) t)))
483- ; ; (set-window-buffer target-window buffer)
484- ; ; target-window))
485-
486- (defun gas/magit-extract-branch-tag (branch-name )
487- " Extract branch tag from BRANCH-NAME."
488- (let ((ticket-pattern " \\ ([[:alpha:]]+-[[:digit:]]+\\ )" ))
489- (when (string-match-p ticket-pattern branch-name)
490- (upcase (replace-regexp-in-string ticket-pattern " \\ 1: " branch-name)))))
491- (defun gas/magit-git-commit-insert-branch ()
492- " Insert the branch tag in the commit buffer if feasible."
493- (when-let* ((tag (gas/magit-extract-branch-tag (magit-get-current-branch))))
494- (unless
495- ; ; avoid repeated insertion when amending
496- (save-excursion (search-forward (string-trim tag) nil 'no-error ))
497- (insert tag))))
431+ ; ; (defun gas/magit-extract-branch-tag (branch-name)
432+ ; ; "Extract branch tag from BRANCH-NAME."
433+ ; ; (let ((ticket-pattern "\\ ([[:alpha:]]+-[[:digit:]]+\\ )"))
434+ ; ; (when (string-match-p ticket-pattern branch-name)
435+ ; ; (upcase (replace-regexp-in-string ticket-pattern "\\ 1: " branch-name)))))
436+ ; ; (defun gas/magit-git-commit-insert-branch ()
437+ ; ; "Insert the branch tag in the commit buffer if feasible."
438+ ; ; (when-let* ((tag (gas/magit-extract-branch-tag (magit-get-current-branch))))
439+ ; ; (unless
440+ ; ; ;; avoid repeated insertion when amending
441+ ; ; (save-excursion (search-forward (string-trim tag) nil 'no-error))
442+ ; ; (insert tag))))
498443
499444(use-package magit
500445 :ensure (:host github :repo " magit/magit" )
501- :custom
502- (magit-git-executable " /opt/homebrew/bin/git" )
446+ :after project
447+ ; ; :custom
448+ ; ; (magit-git-executable "/opt/homebrew/bin/git")
503449 :hook ((git-commit-mode . flyspell-mode)
504- ; ; (git-commit-mode . gas/magit-git-commit-insert-branch)
505- )
450+ (git-commit-mode . gas/magit-insert-branch-tag-maybe))
506451 :bind
507- ((" C-c g" . magit-status)
508- :map magit-mode-map
509- (" C-w" . nil )
510- (" M-w" . nil ))
452+ ((" C-c g" . magit-status)
453+ (" C-x g" . magit-status)
454+ ; ; :map magit-mode-map
455+ ; ; ("C-w" . nil)
456+ ; ; ("M-w" . nil)
457+ )
511458 :functions (magit-get-current-branch)
512459 :custom
513460 (magit-ediff-dwim-show-on-hunks t )
514461 (magit-diff-refine-ignore-whitespace t )
515462 (magit-diff-refine-hunk 'all )
516- ; ; :preface
517- :init
518- ; ; (setq magit-refresh-verbose t)
519- (setq magit-define-global-key-bindings nil )
463+ :preface
464+ (defun gas/get-display-window
465+ (source-window &optional create-if-needed)
466+ (save-excursion
467+ (goto-char (window-start source-window))
468+ (or
469+ (window-in-direction 'right source-window)
470+ (let ((below-window (window-in-direction 'below source-window)))
471+ (when (and below-window
472+ (not (window-minibuffer-p below-window)))
473+ below-window))
474+ (when create-if-needed
475+ (split-window source-window nil 'below )))))
476+ (defun gas/magit-display-buffer (buffer alist )
477+ (when-let ((target-window (gas/get-display-window
478+ (selected-window ) t )))
479+ (set-window-buffer target-window buffer)
480+ target-window))
481+ (defun gas/magit-extract-branch-tag (branch-name )
482+ " Extract a ticket tag like 'abc-123' from BRANCH-NAME and return 'abc-123: '.
483+ Lowercases the match and replaces underscores with hyphens."
484+ (let ((ticket-pattern " \\ ([[:alpha:]_]+-[[:digit:]]+\\ )" )) ; allow underscores in the alpha chunk
485+ (when (string-match ticket-pattern branch-name)
486+ (let* ((raw (match-string 1 branch-name))
487+ (norm (downcase (subst-char-in-string ?_ ?- raw))))
488+ (concat norm " : " )))))
489+ (defun gas/magit-insert-branch-tag-maybe ()
490+ " Insert the branch tag at the start of a commit message when appropriate.
491+ Skips if this is an --amend commit, or if the tag is already present."
492+ (when-let* ((branch (ignore-errors (magit-get-current-branch)))
493+ (tag (and branch (gas/magit-extract-branch-tag branch))))
494+ (unless (or
495+ ; ; 1) Skip if this commit is an --amend in Magit
496+ (and (boundp 'magit-commit-arguments )
497+ (listp magit-commit-arguments)
498+ (member " --amend" magit-commit-arguments))
499+ ; ; 2) Skip if the tag is already in the buffer (avoid duplicates)
500+ (save-excursion
501+ (goto-char (point-min ))
502+ (search-forward (string-trim tag) nil t )))
503+ (save-excursion
504+ (goto-char (point-min ))
505+ (insert tag)))))
506+ :init
520507 (setq magit-section-visibility-indicator '(magit-fringe-bitmap> . magit-fringe-bitmapv))
521- ; ; Have magit-status go full screen and quit to previous
508+ ; ; Have magit-status go full screen and quit to previous
522509 ; ; configuration. Taken from
523510 ; ; http://whattheemacsd.com/setup-magit.el-01.html#comment-748135498
524511 ; ; and http://irreal.org/blog/?p=2253
525- ; ; (defadvice magit-status (around magit-fullscreen activate)
526- ; ; (window-configuration-to-register :magit-fullscreen)
527- ; ; ad-do-it
528- ; ; (delete-other-windows))
529- ; ; (defadvice magit-quit-window (after magit-restore-screen activate)
530- ; ; (jump-to-register :magit-fullscreen))
512+ (defadvice magit-status (around magit-fullscreen activate)
513+ (window-configuration-to-register :magit-fullscreen )
514+ ad-do-it
515+ (delete-other-windows ))
516+ (defadvice magit-quit-window (after magit-restore-screen activate)
517+ (jump-to-register :magit-fullscreen ))
531518 :config
532- ; ; (setq magit-refresh-verbose t)
533- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-tags-header)
534- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-status-headers)
535- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-pushremote)
536- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-pushremote)
537- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-upstream)
538- ; ; (remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream-or-recent)
519+ (setq magit-refresh-verbose t )
539520 (setq git-commit-summary-max-length 70 )
540521 (setq git-commit-style-convention-checks '(non-empty-second-line))
541- ; ; properly kill leftover magit buffers on quit
542- (define-key magit-status-mode-map
543- [remap magit-mode-bury-buffer]
544- #'vcs-quit )
545- (setq magit-revision-show-gravatars
546- '(" ^Author: " . " ^Commit: " ))
547- ; ; (setq magit-commit-show-diff nil)
548- (setq magit-delete-by-moving-to-trash nil )
549- (setq magit-display-buffer-function
550- #'magit-display-buffer-same-window-except-diff-v1 )
551- ; ; (setq magit-log-auto-more t)
552522 (setq magit-log-margin-show-committer-date t )
553523 (setq magit-revert-buffers 'silent )
554524 (setq magit-save-repository-buffers 'dontask )
525+ ; ; (setq magit-log-auto-more t)
555526 (setq magit-wip-after-apply-mode t )
556527 (setq magit-wip-after-save-mode t )
557528 (setq magit-wip-before-change-mode t )
558- (setq transient-values
559- '((magit-log:magit-log-mode " --graph" " --color" " --decorate" )))
560-
561- ; ; Show icons for files in the Magit status and other buffers.
562- (setq magit-format-file-function #'magit-format-file-nerd-icons )
563- ; ; (add-to-list 'display-buffer-alist
564- ; ; '("\\ (magit-revision:\\ |magit-diff:\\ )"
565- ; ; (gas/magit-display-buffer)
566- ; ; (inhibit-same-window . t)))
567- )
529+ ; ; (setq transient-values
530+ ; ; '((magit-log:magit-log-mode "--graph" "--color" "--decorate")))
531+ ; ; ;; properly kill leftover magit buffers on quit
532+ ; ; (define-key magit-status-mode-map
533+ ; ; [remap magit-mode-bury-buffer]
534+ ; ; #'vcs-quit)
535+ ; ; (setq magit-revision-show-gravatars
536+ ; ; '("^Author: " . "^Commit: "))
537+ ; ; ;; (setq magit-commit-show-diff nil)
538+ (setq magit-delete-by-moving-to-trash nil )
539+ ; ; (setq magit-display-buffer-function
540+ ; ; #'magit-display-buffer-same-window-except-diff-v1)
541+ (add-to-list 'display-buffer-alist
542+ '(" \\ (magit-revision:\\ |magit-diff:\\ )"
543+ (gas/magit-display-buffer)
544+ (inhibit-same-window . t ))))
545+ ; ; (use-package magit
546+ ; ; :ensure (:host github :repo "magit/magit")
547+ ; ; :after project
548+ ; ; ;; :custom
549+ ; ; ;; (magit-git-executable "/opt/homebrew/bin/git")
550+ ; ; :hook ((git-commit-mode . flyspell-mode)
551+ ; ; (git-commit-mode . gas/magit-git-commit-insert-branch))
552+ ; ; :bind
553+ ; ; (("C-c g" . magit-status)
554+ ; ; :map magit-mode-map
555+ ; ; ("C-w" . nil)
556+ ; ; ("M-w" . nil))
557+ ; ; :functions (magit-get-current-branch)
558+ ; ; :custom
559+ ; ; (magit-ediff-dwim-show-on-hunks t)
560+ ; ; (magit-diff-refine-ignore-whitespace t)
561+ ; ; (magit-diff-refine-hunk 'all)
562+ ; ; ;; :preface
563+ ; ; :init
564+ ; ; (setq magit-section-visibility-indicator '(magit-fringe-bitmap> . magit-fringe-bitmapv))
565+ ; ; ;; Have magit-status go full screen and quit to previous
566+ ; ; ;; configuration. Taken from
567+ ; ; ;; http://whattheemacsd.com/setup-magit.el-01.html#comment-748135498
568+ ; ; ;; and http://irreal.org/blog/?p=2253
569+ ; ; (defadvice magit-status (around magit-fullscreen activate)
570+ ; ; (window-configuration-to-register :magit-fullscreen)
571+ ; ; ad-do-it
572+ ; ; (delete-other-windows))
573+ ; ; (defadvice magit-quit-window (after magit-restore-screen activate)
574+ ; ; (jump-to-register :magit-fullscreen))
575+ ; ; :config
576+ ; ; ;; (setq magit-refresh-verbose t)
577+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-tags-header)
578+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-status-headers)
579+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-pushremote)
580+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-pushremote)
581+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-upstream)
582+ ; ; ;; (remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream-or-recent)
583+ ; ; (setq git-commit-summary-max-length 70)
568584
569- (use-package magit
570- :after project
571- :config
572- (add-to-list 'project-switch-commands '(magit-project-status " Magit" ) t ))
585+
586+ ; ;
587+ ; ; ;; Show icons for files in the Magit status and other buffers.
588+ ; ; (setq magit-format-file-function #'magit-format-file-nerd-icons)
589+ ; ; (add-to-list 'display-buffer-alist
590+ ; ; '("\\ (magit-revision:\\ |magit-diff:\\ )"
591+ ; ; (gas/magit-display-buffer)
592+ ; ; (inhibit-same-window . t)))
593+ ; ; (with-eval-after-load 'project
594+ ; ; (add-to-list 'project-switch-commands '(magit-project-status "Magit") t))
595+ ; ; (with-eval-after-load 'transient
596+ ; ; (setq transient-show-popup 0.2))
573597
574598; ; (use-package magit-todos
575599; ; :disable t
@@ -583,11 +607,4 @@ If CREATE-IF-NEEDED is non-nil, split SOURCE-WINDOW below."
583607 :ensure t
584608 :hook (prog-mode . hl-todo-mode))
585609
586- ; ; (use-package magit-repos
587- ; ; :ensure nil ; part of `magit'
588- ; ; :commands (magit-list-repositories)
589- ; ; :init
590- ; ; (setq magit-repository-directories
591- ; ; '(("~/work" . 2))))
592-
593610(provide 'frap-tools )
0 commit comments