-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmajutsu-absorb.el
More file actions
150 lines (129 loc) · 4.62 KB
/
majutsu-absorb.el
File metadata and controls
150 lines (129 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
;;; majutsu-absorb.el --- Absorb transient for Majutsu -*- lexical-binding: t; -*-
;; Copyright (C) 2026 0WD0
;; Author: 0WD0 <wd.1105848296@gmail.com>
;; Maintainer: 0WD0 <wd.1105848296@gmail.com>
;; Keywords: tools, vc
;; URL: https://github.com/0WD0/majutsu
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; This library provides jj absorb transients, managing source and
;; destination selections and optional fileset filtering.
;;; Code:
(require 'majutsu)
(require 'majutsu-file)
(require 'majutsu-selection)
(require 'majutsu-interactive)
(defclass majutsu-absorb-option (majutsu-selection-option)
())
(defclass majutsu-absorb--toggle-option (majutsu-selection-toggle-option)
())
(defun majutsu-absorb--default-args ()
"Return default args from diff buffer context."
(with-current-buffer (majutsu-interactive--selection-buffer)
(when (derived-mode-p 'majutsu-diff-mode)
(when-let* ((source
(seq-some (lambda (arg)
(cond
((string-prefix-p "--revisions=" arg)
(concat "--from=" (substring arg 12)))
((string-prefix-p "--from=" arg)
arg)))
majutsu-buffer-diff-range)))
(list source)))))
(defun majutsu-absorb-arguments ()
"Return the current absorb arguments.
If inside the transient, return transient args.
Otherwise, if no --from/--into is set and point is on a
jj-commit section, add --from from that section."
(let ((args (if (eq transient-current-command 'majutsu-absorb)
(transient-args 'majutsu-absorb)
'())))
(unless (cl-some (lambda (arg)
(or (string-prefix-p "--from=" arg)
(string-prefix-p "--into=" arg)))
args)
(when-let* ((rev (magit-section-value-if 'jj-commit)))
(push (concat "--from=" rev) args)))
args))
;;;###autoload
(defun majutsu-absorb-execute (args)
"Execute jj absorb with ARGS from the transient."
(interactive (list (majutsu-absorb-arguments)))
(let ((exit (apply #'majutsu-run-jj "absorb" args)))
(when (zerop exit)
(message "Absorb completed"))))
;;; Infix Commands
(transient-define-argument majutsu-absorb:--from ()
:description "From"
:class 'majutsu-absorb-option
:selection-label "[FROM]"
:selection-face '(:background "dark orange" :foreground "black")
:key "-f"
:argument "--from="
:reader #'majutsu-diff--transient-read-revset)
(transient-define-argument majutsu-absorb:--into ()
:description "Into"
:class 'majutsu-absorb-option
:selection-label "[INTO]"
:selection-face '(:background "dark cyan" :foreground "white")
:key "-t"
:argument "--into="
:reader #'majutsu-diff--transient-read-revset)
(transient-define-argument majutsu-absorb:from ()
:description "From (toggle at point)"
:class 'majutsu-absorb--toggle-option
:key "f"
:argument "--from=")
(transient-define-argument majutsu-absorb:into ()
:description "Into (toggle at point)"
:class 'majutsu-absorb--toggle-option
:key "t"
:argument "--into=")
(transient-define-argument majutsu-absorb:-- ()
:description "Limit to files"
:class 'transient-files
:key "--"
:argument "--"
:prompt "Limit to file,s: "
:reader #'majutsu-read-files
:multi-value t)
;;; Prefix
;;;###autoload(autoload 'majutsu-absorb "majutsu-absorb" nil t)
(transient-define-prefix majutsu-absorb ()
"Transient for jj absorb operations."
:man-page "jj-absorb"
:transient-non-suffix t
[
:description "JJ Absorb"
["Selection"
(majutsu-absorb:--from)
(majutsu-absorb:--into)
(majutsu-absorb:from)
(majutsu-absorb:into)
("c" "Clear selections" majutsu-selection-clear :transient t)]
["Paths"
(majutsu-absorb:--)]
["Options"
(majutsu-transient-arg-ignore-immutable)]
["Actions"
("a" "Absorb" majutsu-absorb-execute)
("RET" "Absorb" majutsu-absorb-execute)
("q" "Quit" transient-quit-one)]]
(interactive)
(let* ((file (majutsu-file-at-point))
(files (cond
(file (list file))
((and (derived-mode-p 'majutsu-diff-mode)
majutsu-buffer-diff-filesets)
majutsu-buffer-diff-filesets)))
(default-args (majutsu-absorb--default-args))
(value (if files
(append default-args (list (cons "--" files)))
default-args)))
(transient-setup
'majutsu-absorb nil nil
:scope (majutsu-selection-session-begin)
:value value)))
;;; _
(provide 'majutsu-absorb)
;;; majutsu-absorb.el ends here