### Install Majutsu with use-package and straight.el Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Use this configuration to install Majutsu from GitHub via straight.el. ```emacs-lisp (use-package majutsu :straight (:host github :repo "0WD0/majutsu")) ``` -------------------------------- ### Install Majutsu with Doom Emacs, straight.el, and package-vc Source: https://github.com/0wd0/majutsu/blob/main/README.org Installation snippets for Majutsu using Doom Emacs (packages.el), use-package with straight.el, and use-package with package-vc (Emacs 29+). Each method targets a different package manager; choose the one that matches your setup. ```emacs-lisp ;; Doom Emacs (packages.el) (package! majutsu :recipe (:host github :repo "0WD0/majutsu")) ``` ```emacs-lisp ;; use-package + straight.el (use-package majutsu :straight (:host github :repo "0WD0/majutsu")) ``` ```emacs-lisp ;; use-package + package-vc (Emacs 29+) (use-package majutsu :vc (:url "https://github.com/0WD0/majutsu")) ``` -------------------------------- ### Manual Installation of Majutsu Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Clone the repository and add it to your load-path, then require majutsu. ```emacs-lisp (add-to-list 'load-path "/path/to/majutsu") (require 'majutsu) ``` -------------------------------- ### Install Majutsu with package-vc (Emacs 29+) Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Install Majutsu directly with package-vc, then configure it with use-package. ```emacs-lisp (unless (package-installed-p 'majutsu) (package-vc-install '(majutsu :url "https://github.com/0WD0/majutsu"))) (use-package majutsu) ``` -------------------------------- ### Install Majutsu with Doom Emacs (packages.el) Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Add this recipe to your packages.el to install Majutsu from GitHub using Doom Emacs. ```emacs-lisp (package! majutsu :recipe (:host github :repo "0WD0/majutsu")) ``` -------------------------------- ### Example: Annotate current file and walk chunks Source: https://github.com/0wd0/majutsu Shows how to require majutsu-annotate, annotate the current file with majutsu-annotate-addition, optionally from a specific revision, and programmatically walk chunks using majutsu-annotate-chunk-at and majutsu-annotate-chunk-orig-rev. ```emacs-lisp (require 'majutsu-annotate) ;; Annotate the current file (majutsu-annotate-addition) ;; Annotate from a specific revision (majutsu-annotate-addition "@-") ;; Walk chunks programmatically (dolist (pos (number-sequence (point-min) (point-max))) (when-let* ((chunk (majutsu-annotate-chunk-at pos))) (message "Line introduced by %s" (majutsu-annotate-chunk-orig-rev chunk)) (cl-return))) ``` -------------------------------- ### Install Majutsu with use-package :vc (Emacs 30+) Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org For Emacs 30+, use the built-in :vc keyword. :rev :newest follows the default branch. ```emacs-lisp (use-package majutsu :vc (:url "https://github.com/0WD0/majutsu" :rev :newest)) ``` -------------------------------- ### Example usage of majutsu-jj functions Source: https://github.com/0wd0/majutsu Shows how to read a revset with completion, get the file at point in a diff buffer, and handle the 'not a repository' case. Requires 'majutsu-jj' and uses `majutsu-read-revset', `majutsu-jj-lines', `majutsu-file-at-point', and `majutsu--toplevel-safe'. ```emacs-lisp (require 'majutsu-jj) ;; Read a revset with completion (let ((revset (majutsu-read-revset "Rebase onto: " :allow-empty t))) (when revset (majutsu-jj-lines "rebase" "-r" "@" "-d" revset))) ;; File at point in a diff buffer (majutsu-file-at-point) ;; Handle the "not a repository" case (condition-case err (majutsu--toplevel-safe) (majutsu-outside-jj-repo (message "Outside jj repo: %s" err))) ``` -------------------------------- ### Start asynchronous process with majutsu-start-process Source: https://github.com/0wd0/majutsu Starts an executable asynchronously using `start-file-process`, sets up sentinel and filter, and returns the process object. On termination, refreshes the calling buffer and the repository log buffer. ```emacs-lisp (defun majutsu-start-process (program &optional input &rest args) "Start PROGRAM asynchronously, preparing for refresh, and return the process. PROGRAM is started using `start-file-process' and then setup to use `majutsu--process-sentinel' and `majutsu--process-filter'. After the process terminates, the sentinel refreshes the buffer that was current when this function was called (if still alive), as well as the repository's log buffer (see `majutsu-refresh')." ...) ``` -------------------------------- ### Majutsu diff commands example Source: https://github.com/0wd0/majutsu Requires the majutsu-diff library. Shows how to display a diff for a revset, run a DWIM diff for the revision at point, and open the file from a diff buffer in the workspace. ```emacs-lisp (require 'majutsu-diff) ;; Show the diff for a revset (majutsu-diff-revset "@-..@") ;; DWIM diff for the revision at point (majutsu-diff-dwim) ;; From a diff buffer, open the file in the workspace (majutsu-diff-visit-workspace-file) ``` -------------------------------- ### Example usage of diff-editor hosting Source: https://github.com/0wd0/majutsu Shows how to determine if a command needs hosting and how to observe session exit. Requires majutsu-diff-editor and uses the predicate and host selection functions. ```emacs-lisp (require 'majutsu-diff-editor) ;; Determine whether a command needs hosting (if (majutsu-diff-editor-interactive-arguments-p '("diffedit" "-i")) (majutsu-diff-editor-select-host "diffedit" '("-i")) (majutsu-process-jj t "diffedit")) ;; Observe session exit (add-hook 'majutsu-diff-editor-session-exit-hook (lambda (session event) (message "diff-editor session %s ended: %s" session event))) ``` -------------------------------- ### Start jj with editor integration Source: https://github.com/0wd0/majutsu Starts jj ARGS with `JJ_EDITOR' integration. SUCCESS-MSG, FINISH-CALLBACK, and INHIBIT-REFRESH have the same meaning as for `majutsu-start-jj'. ```emacs-lisp (defun majutsu-start-jj-with-editor (args &optional success-msg finish-callback inhibit-refresh) "Start jj ARGS with `JJ_EDITOR' integration. SUCCESS-MSG, FINISH-CALLBACK, and INHIBIT-REFRESH have the same meaning as for `majutsu-start-jj'." (majutsu-with-editor (majutsu-start-jj args success-msg finish-callback inhibit-refresh))) ``` -------------------------------- ### Example usage of majutsu-config Source: https://github.com/0wd0/majutsu Shows how to require the module, read/write user config, list workspace-scoped settings, and resolve the repo config identity used by transient defaults. ```emacs-lisp (require 'majutsu-config) ;; Read and write user config (majutsu-get "user.name") (majutsu-set "user.email" "me@example.com") ;; List workspace-scoped settings (majutsu-list nil 'workspace) ;; Resolve the repo config identity used by transient defaults (majutsu-config-id 'repo t) ``` -------------------------------- ### Example: wrap action and read values Source: https://github.com/0wd0/majutsu Shows how to require the module, wrap a default action inside the selection buffer context using majutsu--transient-with-selection-buffer, and read the selected values with majutsu-selection-values. ```emacs-lisp (require 'majutsu-selection) ;; Wrap a default action inside the selection buffer context (majutsu--transient-with-selection-buffer (lambda () (majutsu-refresh-buffer))) ;; Read the values selected in the active session (majutsu-selection-values 'majutsu-diff) ``` -------------------------------- ### Example: Refresh Majutsu buffers and create a locked log buffer Source: https://github.com/0wd0/majutsu Shows how to require `majutsu-mode`, refresh all Majutsu buffers for the current repository after a mutation, and create a locked log buffer for a specific revset argument set. ```emacs-lisp (require 'majutsu-mode) ;; Refresh every Majutsu buffer for the current repository after a mutation (majutsu-refresh) ;; Create a locked log buffer for a specific revset argument set (majutsu-setup-buffer #'majutsu-log-mode t (majutsu-buffer-log-args '("--revisions=@..@"))) ``` -------------------------------- ### Majutsu base example: confirm, completing-read, assert-mode Source: https://github.com/0wd0/majutsu Shows usage of majutsu-confirm, majutsu-completing-read-payload, and majutsu--assert-mode. Requires majutsu-base. The confirm gate runs a jj command only after user confirmation; completing-read uses bookmark candidate data with completion metadata; assert-mode guards a command to a diff buffer. ```emacs-lisp (require 'majutsu-base) ;; Confirmation gate for a destructive action (when (majutsu-confirm 'abandon "Abandon this revision? ") (majutsu-run-jj "abandon" "-r" "@")) ;; Read a bookmark with completion metadata (majutsu-completing-read-payload "Bookmark: " (majutsu-bookmark-candidate-data) nil t nil 'majutsu-bookmark-name-history nil 'majutsu-bookmark) ;; Guard a command to a diff buffer (majutsu--assert-mode 'majutsu-diff-mode) ``` -------------------------------- ### Example usage of terminal session Source: https://github.com/0wd0/majutsu Shows how to check availability before running jj arrange and how to observe completions via the exit hook. ```emacs-lisp (require 'majutsu-terminal-session) ;; Check whether terminal hosting is available before offering `jj arrange' (when (majutsu-terminal-session-available-p) (majutsu-run-jj "arrange")) ;; Observe completions for diagnostics (add-hook 'majutsu-terminal-session-exit-hook (lambda (session event) (message "Session %s: %S" session event))) ``` -------------------------------- ### Majutsu log usage example Source: https://github.com/0wd0/majutsu Shows how to require the majutsu-log library, open the log for the current repository, open a locked log for a specific commit, jump to the working copy revision, and refresh the log after external changes. ```emacs-lisp (require 'majutsu-log) ;; Open the log for the repository in `default-directory' (majutsu-log) ;; Open a locked log focused on a specific commit (majutsu-log-setup-buffer "abc1234" t) ;; Jump to the working copy revision from Lisp (with-current-buffer (majutsu-log-setup-buffer) (majutsu-log-goto-@)) ;; Update the log after an external change (majutsu-log-refresh) ``` -------------------------------- ### Key aliases for transients Source: https://github.com/0wd0/majutsu Defines the generic function `majutsu-transient-key-aliases` and helper predicates for key alias handling. Key aliases are installed via an `:around` advice on `transient--make-transient-map`; conflicting bindings signal an error, and alias keys render joined with `/`. ```emacs-lisp (cl-defgeneric majutsu-transient-key-aliases (obj) "Return additional key descriptions for OBJ.") (defun majutsu-transient-key= (a b) "Return non-nil when key descriptions or vectors A and B are equal.") (defun majutsu-transient-key-invoked-p (key) "Return non-nil when KEY invoked the current command.") ``` -------------------------------- ### Buffer setup and refresh functions Source: https://github.com/0wd0/majutsu Provides functions to set up and refresh a Majutsu log buffer. majutsu-log-setup-buffer optionally focuses a commit and can lock the buffer; majutsu-log-refresh-buffer refreshes the current buffer; majutsu-log-refresh is an autoloaded command that refreshes an existing log buffer or signals an error if none exists and invoked interactively. ```emacs-lisp (defun majutsu-log-setup-buffer (&optional commit locked) "Set up a Majutsu log buffer and optionally focus COMMIT. When LOCKED is non-nil, avoid reusing existing unlocked log buffers." ...) (defun majutsu-log-refresh-buffer () "Refresh the current Majutsu log buffer." ...) ;;;###autoload (defun majutsu-log-refresh () "Refresh a majutsu log buffer for the current repository. When called outside a log buffer, try to refresh an existing log buffer for the same repository. If none exists and the command is invoked interactively, signal a user error instead of mutating the wrong buffer." (interactive) ...) ``` -------------------------------- ### Explicit method chaining with :method Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Calls methods on objects using :method, with chaining supported. Examples show chaining :commit_id, :parents :len, and :diff with a string argument. ```emacs-lisp (majutsu-tpl [:method [:raw "commit" :Commit] :commit_id]) ; => "commit.commit_id()" (majutsu-tpl [:method [:raw "commit" :Commit] :parents :len]) ; => "commit.parents().len()" (majutsu-tpl [:method [:raw "commit" :Commit] :diff "src"]) ; => "commit.diff(\"src\")" ``` -------------------------------- ### Open and edit files with majutsu-file Source: https://github.com/0wd0/majutsu Requires the majutsu-file library. Opens src/main.rs at the working-copy commit, opens the parent revision in another window, and starts editing the blob via jj diffedit. ```emacs-lisp (require 'majutsu-file) ;; Open src/main.rs at the working-copy commit (majutsu-find-file "@" "src/main.rs") ;; Open the parent revision version in another window (majutsu-find-file-other-window "@-" "src/main.rs") ;; Enter editing to change the revision via jj diffedit (with-current-buffer (majutsu-find-file-noselect "@" "src/main.rs") (majutsu-blob-edit-start)) ``` -------------------------------- ### majutsu-process usage example Source: https://github.com/0wd0/majutsu Shows synchronous and asynchronous jj command execution with majutsu-process. The synchronous query returns exit code and buffer content; the async command triggers a refresh and success message; environment awareness is demonstrated with a diff command. ```emacs-lisp (require 'majutsu-process) ;; Synchronous query: exit code + buffer content (with-temp-buffer (let ((exit (majutsu-process-jj t "log" "-r" "@" "--no-graph"))) (unless (zerop exit) (error "jj log failed with %s" exit)) (buffer-string))) ;; Async command with refresh and success message (majutsu-start-jj '("rebase" "-r" "@" "-d" "@-") "Rebased" (lambda (_proc exit) (message "done %s" exit))) ;; Environment awareness (majutsu-process-environment '("diff" "--stat")) ``` -------------------------------- ### Example: Using majutsu-conflict functions Source: https://github.com/0wd0/majutsu Requires the majutsu-conflict library. Enables marker-aware editing, programmatically resolves conflicts by keeping the first side, and jumps between conflicts. ```emacs-lisp (require 'majutsu-conflict) ;; Enable marker-aware editing for the current buffer (majutsu-conflict-ensure-mode) ;; Programmatic resolution: keep the first side of every conflict (dolist (conflict (majutsu-conflict-parse-buffer)) (when (majutsu-conflict-at-point) (majutsu-conflict-keep-side 1))) ;; Jump between conflicts (majutsu-conflict-next) (majutsu-conflict-prev) ``` -------------------------------- ### Enable Majutsu Forge integration Source: https://github.com/0wd0/majutsu/blob/main/README.org Requires Forge to be installed. Enables Majutsu integration, adding Forge issue, pull-request, and discussion sections to Majutsu log buffers and binding N / ' to forge-dispatch. Intended for colocated jj/Git repositories; Forge sections depend on a configured, tracked repository and populated Forge database. ```emacs-lisp (require 'majutsu-forge) (majutsu-forge-mode 1) ``` -------------------------------- ### Split transient value with majutsu-filesets-split-transient-value Source: https://github.com/0wd0/majutsu Splits a transient value into args and filesets. The example input '("--limit=10" ("--" "src/")) returns (("--limit=10") ("src/")). ```emacs-lisp ;; Split a transient value into args + filesets (majutsu-filesets-split-transient-value '("--limit=10" ("--" "src/"))) ;; => (("--limit=10") ("src/")) ``` -------------------------------- ### Read transient revset with majutsu-transient-read-revset Source: https://github.com/0wd0/majutsu Requires 'majutsu-transient. Reads a transient revset, used as an infix reader. The example passes "Revisions: " as prompt, "@" as initial input, and a history variable. ```emacs-lisp (require 'majutsu-transient) ;; Read a transient revset (used as an infix reader) (majutsu-transient-read-revset "Revisions: " "@" 'majutsu-read-revset-history) ``` -------------------------------- ### Define reusable template function with parameters and optional value Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Defines a helper that takes a label and an optional value, returning a Template that concatenates the label, a colon and space, and the value (or empty string if omitted). The example shows the output for a call with both arguments. ```emacs-lisp (majutsu-template-defun my-helper ((label Template) (value Template :optional t)) (:returns Template) `[:concat ,label [:str ": "] ,(or value [:str ""])]) (majutsu-tpl [:my-helper [:str "ID"] [:str "VAL"]]) ; => "concat(\"ID\", \": \", \"VAL\")" ``` -------------------------------- ### Compile template string at runtime with majutsu-template-compile Source: https://github.com/0wd0/majutsu Compiles a template string at runtime using the `majutsu-template-compile` function. The example shows a vector form with `:concat`, `:change_id`, `:short`, `:description`, and `:first_line`, producing a jj DSL string. Requires `majutsu-template`. ```emacs-lisp (require 'majutsu-template) ;; Compile a template string at runtime (majutsu-template-compile '[:concat [:change_id :short] " " [:description :first_line]] 'Commit) ;; => "change_id.short() ++ \" \" ++ description.first_line()" (jj DSL) ``` -------------------------------- ### majutsu-get Source: https://github.com/0wd0/majutsu Gets a config value for a given key from jj. ```APIDOC ## majutsu-get ### Description Get config value for KEY from jj. ### Parameters - `key` (string) - Required - The config key to retrieve. ### Returns - Value string (trimmed) or nil. ``` -------------------------------- ### majutsu-file-revert-buffer Source: https://github.com/0wd0/majutsu Reverts a blob buffer to its pinned revision. This function is installed as `revert-buffer-function` for blob buffers. ```APIDOC ## majutsu-file-revert-buffer ### Description Reverts a blob buffer to its pinned revision. This function is installed as `revert-buffer-function` for blob buffers. ### Signature ```emacs-lisp (defun majutsu-file-revert-buffer (_ignore-auto noconfirm &optional rev-info) "Revert a blob buffer to its pinned revision.") ``` ### Parameters - `_ignore-auto` - Required - Ignored (for compatibility). - `noconfirm` - Required - If non-nil, do not ask for confirmation. - `rev-info` (optional) - Optional - Revision information. ### Behavior - Reverts the blob buffer to its pinned revision. ``` -------------------------------- ### Require majutsu and use dispatch Source: https://github.com/0wd0/majutsu Loads the majutsu package, opens the log for the current jj workspace with `majutsu-log`, uses the discoverable alias `majutsu`, and binds the dispatch command to a global key. ```emacs-lisp (require 'majutsu) ;; Open the log for the current jj workspace (majutsu-log) ;; The discoverable alias does the same (majutsu) ;; Bind dispatch to a global key (global-set-key (kbd "C-x m j") #'majutsu-dispatch) ``` -------------------------------- ### majutsu-bug-reference-try-setup: Set up bug-reference-mode from JJ Git remotes Source: https://github.com/0wd0/majutsu Placeholder function used by `bug-reference-auto-setup-functions` for buffers managed by Majutsu, including JJ description buffers. Registered at the end of the file after `bug-reference` is loaded, and ` ` is bound to `bug-reference-push-button` in `bug-reference-map`. ```emacs-lisp (defun majutsu-bug-reference-try-setup (&optional _ignored) "Try to set up `bug-reference-mode' from JJ Git remotes. This is used by `bug-reference-auto-setup-functions' for buffers managed by Majutsu, including JJ description buffers." ...) ``` -------------------------------- ### Catch majutsu-gerrit-rest-error Source: https://github.com/0wd0/majutsu Use condition-case to handle Gerrit REST errors. The error data includes status, body, and URL, which can be destructured with pcase. ```emacs-lisp (condition-case err (majutsu-gerrit-rest-account-self spec) (majutsu-gerrit-rest-error (pcase err (`(,sym ,status ,body ,url) (message "HTTP %s from %s: %s" status url body))))) ``` -------------------------------- ### Compile a profile for a custom listing and read buffer Source: https://github.com/0wd0/majutsu Requires 'majutsu-row. Creates a profile with a custom id template and columns, then compiles and reads the buffer. The message prints the parsed row data. ```emacs-lisp (require 'majutsu-row) ;; Compile a profile for a custom listing (let ((profile (majutsu-row-make-profile :id-template [:commit_id] :columns '((:field short-id :module heading :template [:label "s" [:commit_id :short]]))))) (with-current-buffer (majutsu-jj-buffer-string "log" "-T" (majutsu-template-compile (majutsu-row-template-form (majutsu-row-compile profile))))) (message "%S" (majutsu-row-read-buffer (majutsu-row-compile profile)))) ``` -------------------------------- ### Set workspace-session default with majutsu-transient-set-current-value Source: https://github.com/0wd0/majutsu Programmatically sets a workspace-session default. The example sets the value of '--limit to "10" for the 'majutsu-log transient. ```emacs-lisp ;; Set a workspace-session default programmatically (majutsu-transient-set-current-value 'majutsu-log '--limit "10") ``` -------------------------------- ### Majutsu diff entry commands Source: https://github.com/0wd0/majutsu Defines the interactive entry points for showing diffs: `majutsu-diff-dwim` derives a revision from the thing at point (falling back to `@`), `majutsu-diff-revset` accepts a revset passed as `--revisions=REVSET`, and `majutsu-diff-setup-buffer` creates/locks the diff buffer via `majutsu-setup-buffer`. `majutsu-diff-arguments` returns the transient arguments. ```emacs-lisp ;;;###autoload(autoload 'majutsu-diff-dwim "majutsu-diff" nil t) (transient-define-suffix majutsu-diff-dwim (&optional args range filesets) "Show changes for the thing at point." :advice* #'majutsu--transient-with-selection-buffer (interactive (majutsu-diff-arguments)) ...) ;;;###autoload (defun majutsu-diff-revset (revset &optional args _range filesets) "Show changes for a REVSET. REVSET is passed to jj diff using `--revisions='." (interactive (cons (majutsu-read-revset "Diff revset") (majutsu-diff-arguments))) ...) (defun majutsu-diff-setup-buffer (args range filesets &optional locked) "Display a diff buffer configured by ARGS, RANGE and FILESETS." ...) (defun majutsu-diff-arguments (&optional mode) "Return diff transient arguments. ...") ``` -------------------------------- ### Elisp embedding evaluated at compile time Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Elisp expressions are evaluated when the template is compiled. The example shows that a backquoted template with an embedded if is evaluated at compile time, while a quoted template is not. ```emacs-lisp (let* ((tmp 1) (s1 `[:concat ,(if (> 2 tmp) [:str "T"] [:str "F"]) [:str "!"]]) (s2 [:concat (if (> 2 tmp) [:str "T"] [:str "F"]) [:str "!"]]) (tmp 3)) (concat (majutsu-tpl s1) (majutsu-tpl s2))) ; => "concat(\"T\", \"!\")concat(\"F\", \"!\")" ``` -------------------------------- ### majutsu-diff-setup-buffer Source: https://github.com/0wd0/majutsu Displays a diff buffer configured by ARGS, RANGE and FILESETS. This function creates or locks the diff buffer through `majutsu-setup-buffer`. ```APIDOC ## majutsu-diff-setup-buffer ### Description Displays a diff buffer configured by ARGS, RANGE and FILESETS. This function creates or locks the diff buffer through `majutsu-setup-buffer`. ### Signature `(majutsu-diff-setup-buffer args range filesets &optional locked)` ### Parameters - `args` - Transient arguments. - `range` - Revision range. - `filesets` - Filesets to include. - `locked` (optional) - If non-nil, lock the buffer. ``` -------------------------------- ### majutsu-template-compile Source: https://github.com/0wd0/majutsu Public entry point: compile a form into a jj template string. Optional SELF-TYPE overrides the default self type for the root implicit self context installed during this compilation. ```APIDOC ## majutsu-template-compile ### Description Public entry point: compile a form into a jj template string. Optional SELF-TYPE overrides the default self type for the root implicit self context installed during this compilation. ### Parameters - `form` : a template s-expression. - `self-type` : optional root self type symbol (default `majutsu-template-default-self-type` = `'Commit`). ### Returns - string — the rendered jj template (e.g. for `jj log -T`). ### Example ```emacs-lisp ;;;###autoload (defun majutsu-template-compile (form &optional self-type) "Public entry point: compile FORM into a jj template string. Optional SELF-TYPE overrides `majutsu-template-default-self-type' for the root implicit self context installed during this compilation." ...) ``` ``` -------------------------------- ### Catch majutsu-outside-jj-repo and majutsu-jj-executable-not-found Source: https://github.com/0wd0/majutsu Use condition-case to handle errors when not inside a jj repository or when the jj executable is missing. The error data includes the directory or executable name. ```emacs-lisp (condition-case err (majutsu--toplevel-safe) (majutsu-outside-jj-repo (message "Not in a jj repo: %S" err)) ; err = (majutsu-outside-jj-repo dir) (majutsu-jj-executable-not-found (message "No jj executable: %S" err))) ``` -------------------------------- ### Set Majutsu variables and add hook Source: https://github.com/0wd0/majutsu Configure the jj executable path, disable confirmation for abandon and restore operations, enable refined hunk diffing, and enable visual-line-mode in majutsu-log-mode. ```emacs-lisp (setq majutsu-jj-executable "/usr/local/bin/jj" majutsu-no-confirm '(abandon restore) majutsu-diff-refine-hunk t) (add-hook 'majutsu-log-mode-hook #'visual-line-mode) ``` -------------------------------- ### Define majutsu-dispatch transient prefix Source: https://github.com/0wd0/majutsu Defines the top-level Majutsu command dispatcher as a transient prefix. Keys with `:if`/`:if-not majutsu-dispatch--evil-keys-p` offer alternate bindings when Evil integration is active. The "Essential commands" group appears only in `majutsu-mode` buffers; the "Copy commands" group only in `majutsu-log-mode`, `majutsu-evolog-mode`, or `majutsu-op-log-mode`. ```emacs-lisp ;;;###autoload(autoload 'majutsu-dispatch "majutsu" nil t) (transient-define-prefix majutsu-dispatch () "Top-level Majutsu command dispatcher." [["Transient and dwim commands" [("k" "Abandon" majutsu-abandon :if-not majutsu-dispatch--evil-keys-p) ("x" "Abandon" majutsu-abandon :if majutsu-dispatch--evil-keys-p) ("b" "Bookmarks" majutsu-bookmark) ("t" "Tags" majutsu-tag) ("c" "Describe" majutsu-describe) ("C" "Commit" majutsu-commit) ("m" "Metaedit" majutsu-metaedit) ("d" "Diff" majutsu-diff) ("v" "Evolution log" majutsu-evolog) ("D" "Diff (dwim)" majutsu-diff-dwim) ("e" "Edit revision" majutsu-edit) ("E" "Ediff" majutsu-ediff) ("M" "Resolve conflicts" majutsu-resolve)] [("G" "Git" majutsu-git-transient) ("!" "Run" majutsu-command) ("l" "Log options" majutsu-log-transient :if-not majutsu-dispatch--evil-keys-p) ("L" "Log options" majutsu-log-transient :if majutsu-dispatch--evil-keys-p) ("o" "New" majutsu-new) ("O" "New (dwim)" majutsu-new-dwim) ("r" "Rebase" majutsu-rebase) ("P" "Simplify parents" majutsu-simplify-parents) ("V" "Revert" majutsu-revert :if-not majutsu-dispatch--evil-keys-p) ("_" "Revert" majutsu-revert :if majutsu-dispatch--evil-keys-p) ("R" "Restore" majutsu-restore)] [("s" "Squash" majutsu-squash) ("S" "Split" majutsu-split) ("a" "Absorb" majutsu-absorb) ("A" "Arrange (TUI)" majutsu-arrange-tui) ("y" "Duplicate" majutsu-duplicate) ("j" "Sign" majutsu-sign) ("J" "Unsign" majutsu-unsign) (">" "Sparse" majutsu-sparse) ("Z" "Workspaces" majutsu-workspace :if-not majutsu-dispatch--evil-keys-p) ("*" "Workspaces" majutsu-workspace :if majutsu-dispatch--evil-keys-p) ("X" "Operations" majutsu-op-transient) ("C-/" "Undo" majutsu-undo :if-not majutsu-dispatch--evil-keys-p) ("u" "Undo" majutsu-undo :if majutsu-dispatch--evil-keys-p) ("C-?" "Redo" majutsu-redo :if-not majutsu-dispatch--evil-keys-p) ("C-r" "Redo" majutsu-redo :if majutsu-dispatch--evil-keys-p)]] ["Essential commands" :if-derived majutsu-mode [("g" "Refresh" majutsu-refresh) ("q" "Quit" majutsu-mode-bury-buffer)] [("?" "Help" transient-help) ("$" "Process buffer" majutsu-process-buffer :if-not majutsu-dispatch--evil-keys-p) ("`" "Process buffer" majutsu-process-buffer :if majutsu-dispatch--evil-keys-p)] [("C-x m" "Show all key bindings" describe-mode)]] ["Copy commands" :if-derived (majutsu-log-mode majutsu-evolog-mode majutsu-op-log-mode) [("w" "Copy…" majutsu-row-copy-transient)]]) ``` -------------------------------- ### List-oriented methods: map and join styles Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Shows equivalent styles for map and join: historical binder sugar, direct method call, dash-style lambda, dash-style anaphoric shorthand, and composition of map and join. ```emacs-lisp ;; Historical explicit-binder sugar (lowers to a native lambda internally) (majutsu-tpl [:map [:raw "self.bookmarks()"] b [:raw "b.name()"]]) ; => "self.bookmarks().map(|b| b.name())" ;; Direct jj-style method call with an anonymous lambda (majutsu-tpl [:method [:raw "refs"] :map [:lambda [c] [:description]]]) ; => "refs.map(|c| c.description())" ;; Dash-style explicit lambda (majutsu-tpl [:-map [:lambda [c] [:description]] [:raw "refs"]]) ; => "refs.map(|c| c.description())" ;; Dash-style anaphoric shorthand (majutsu-tpl [:--map [:method 'it :description] [:raw "refs"]]) ; => "refs.map(|it| it.description())" (majutsu-tpl [:method [:map [:raw "self.parents()"] p [:raw "p.commit_id()"]] :join [:str ", "]]) ; => "self.parents().map(|p| p.commit_id()).join(\", \")" (majutsu-tpl [:method [:raw "self.parents()"] :map [:lambda [p] [:raw "p.commit_id()"]] :join [:str ", "]]) ; => "self.parents().map(|p| p.commit_id()).join(\", \")" ``` -------------------------------- ### majutsu-log-goto-@ Source: https://github.com/0wd0/majutsu Jump to the working-copy revision (@) in the log. ```APIDOC ## majutsu-log-goto-@ ### Description Jump to the working-copy revision (@) in the log. ### Method Interactive command ### Signature `(defun majutsu-log-goto-@ () ...)` ### Usage Call interactively or from Lisp code. ``` -------------------------------- ### Define syntax-level sugar with majutsu-template-defspecial Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Defines a special form that receives raw forms and lowers them to primitive template syntax. The example wraps a body in angle brackets, producing a concat call with the body and literal '<' and '>'. ```emacs-lisp (majutsu-template-defspecial :wrap-angle (body) `[:concat [:str "<"] ,body [:str ">"]]) (majutsu-tpl [:wrap-angle [:str "x"]]) ; => "concat(\"<\", \"x\", \">\")" ``` -------------------------------- ### Conditionals and composition Source: https://github.com/0wd0/majutsu/blob/main/docs/majutsu.org Demonstrates :if for conditional output and :separate for joining multiple labels with a separator. ```emacs-lisp (majutsu-tpl [:if [:root] "(root)" [:commit_id]]) ; => "if(self.root(), \"(root)\", self.commit_id())" (majutsu-tpl [:separate " " [:label "a" "A"] [:label "b" "B"]]) ; => "separate(\" \", label(\"a\", \"A\"), label(\"b\", \"B\"))" ``` -------------------------------- ### Raw request with bearer token override Source: https://github.com/0wd0/majutsu Performs a raw (non-JSON) GET request to `/config/server/version` using `majutsu-gerrit-rest-request`. Includes a query parameter `pp=0` and an `Authorization` header with a bearer token override. ```emacs-lisp ;; Raw (non-JSON) request with a bearer token override (majutsu-gerrit-rest-request "GET" "/config/server/version" nil spec '(("pp" . "0")) '(("Authorization" . "Bearer abc"))) ``` -------------------------------- ### Other majutsu-annotate commands Source: https://github.com/0wd0/majutsu Provides commands for visiting blobs, quitting, navigating chunks, cycling style, showing commits, copying hashes, scrolling, and showing messages. ```emacs-lisp (defun majutsu-annotate-visit-file () "Visit the blob related to the current chunk." (interactive) ...) (defun majutsu-annotate-visit-other-file () "Visit the blob related to the current chunk's parent revision." (interactive) ...) (defun majutsu-annotate-quit () "Turn off Majutsu-Annotate mode. If the buffer was created during a recursive blame, then also kill the buffer." (interactive) ...) (defun majutsu-annotate-next-chunk () "Move to the next annotation chunk." (interactive) ...) (defun majutsu-annotate-previous-chunk () "Move to the previous annotation chunk." (interactive) ...) (defun majutsu-annotate-next-chunk-same-commit (&optional previous) "Move to the next chunk with the same commit." (interactive) ...) (defun majutsu-annotate-previous-chunk-same-commit () "Move to the previous chunk with the same commit." (interactive) ...) (defun majutsu-annotate-cycle-style () "Cycle the annotation display style." (interactive) ...) (defun majutsu-annotate-show-commit () "Show the commit of the chunk at point." (interactive) ...) (defun majutsu-annotate-copy-hash () "Copy the hash of the chunk at point." (interactive) ...) (defun majutsu-annotate-show-or-scroll-up () "Show chunk info or scroll up." (interactive) ...) (defun majutsu-annotate-show-or-scroll-down () "Show chunk info or scroll down." (interactive) ...) (defun majutsu-annotate-maybe-show-message () "Show a chunk summary in the echo area when crossing chunks." ...) ``` -------------------------------- ### majutsu-goto-prev-revision Source: https://github.com/0wd0/majutsu Navigate to the previous revision in the log. ```APIDOC ## majutsu-goto-prev-revision ### Description Navigate to the previous revision in the log. ### Method Interactive command ### Signature `(defun majutsu-goto-prev-revision () ...)` ### Usage Call interactively or from Lisp code. ``` -------------------------------- ### Blob visit functions Source: https://github.com/0wd0/majutsu Functions to bury or kill the current buffer, visit the file at point from the workspace, or open the blob in Magit. All are interactive commands. ```emacs-lisp (defun majutsu-bury-or-kill-buffer (&optional bury-buffer) "Bury or kill the current buffer. With prefix, kill instead. ...") (defun majutsu-blob-visit-file () "Visit the file at point from the workspace." (interactive) ...) (defun majutsu-blob-visit-magit () "Open the blob in Magit." (interactive) ...) ``` -------------------------------- ### majutsu-dispatch (transient prefix) Source: https://github.com/0wd0/majutsu Top-level Majutsu command dispatcher. A transient popup grouping every Majutsu command, with key bindings for various operations. ```APIDOC ## majutsu-dispatch (transient prefix) ### Description Top-level Majutsu command dispatcher. A transient popup grouping every Majutsu command, with key bindings for various operations. ### Usage Invoke via `M-x majutsu-dispatch` or through key bindings. ### Key Bindings - `k` / `x` - Abandon - `b` - Bookmarks - `t` - Tags - `c` - Describe - `C` - Commit - `m` - Metaedit - `d` - Diff - `v` - Evolution log - `D` - Diff (dwim) - `e` - Edit revision - `E` - Ediff - `M` - Resolve conflicts - `G` - Git - `!` - Run - `l` / `L` - Log options - `o` - New - `O` - New (dwim) - `r` - Rebase - `P` - Simplify parents - `V` / `_` - Revert - `R` - Restore - `s` - Squash - `S` - Split - `a` - Absorb - `A` - Arrange (TUI) - `y` - Duplicate - `j` - Sign - `J` - Unsign - `>` - Sparse - `Z` / `*` - Workspaces - `X` - Operations - `C-/` / `u` - Undo - `C-?` / `C-r` - Redo - `g` - Refresh - `q` - Quit - `?` - Help - `$` / `` ` `` - Process buffer - `C-x m` - Show all key bindings - `w` - Copy… ``` -------------------------------- ### Defcustom majutsu-diff-editor-host Source: https://github.com/0wd0/majutsu Configures how Majutsu hosts jj diff-editor sessions. 'auto uses Ghostel when available, 'ghostel requires Ghostel, and 'process always uses an ordinary process which cannot host jj's built-in terminal editor. ```emacs-lisp (defcustom majutsu-diff-editor-host 'auto "How Majutsu hosts jj diff-editor sessions. `auto' uses Ghostel when it is available. Local commands which can later invoke jj's description editor also need a working `emacsclient'; remote Ghostel sessions use with-editor's TRAMP sleeping-editor bridge. Without a suitable terminal host, `auto' permits an ordinary process only for a known external editor. `ghostel' requires Ghostel. `process' always uses an ordinary process, which cannot host jj's built-in terminal editor." :type '(choice (const :tag "Automatic" auto) (const :tag "Ghostel terminal" ghostel) (const :tag "Ordinary process (external editor only)" process)) :group 'majutsu-diff-editor) ``` -------------------------------- ### Editable blob mode and related functions Source: https://github.com/0wd0/majutsu Defines majutsu-blob-edit-mode and functions to start, finish, exit, and abort editable blob editing. Saving applies changes via jj diffedit and re-pins the buffer. Errors include user-error messages for invalid states. ```emacs-lisp (define-minor-mode majutsu-blob-edit-mode "Edit a blob and apply changes to its revision when saving." ...) (defun majutsu-blob-edit-start () "Enter editable blob mode. Edits are applied to the revision through jj diffedit when saving." (interactive) ...) (defun majutsu-blob-edit-finish () "Save and apply editable blob changes." (interactive) ...) (defun majutsu-blob-edit-exit () "Exit editable blob mode. If there are unsaved changes, prompt to save or abort, like `wdired-exit'." (interactive) ...) (defun majutsu-blob-edit-abort () "Abort editable blob changes and restore snapshot." (interactive) ...) ``` -------------------------------- ### Define public selection functions Source: https://github.com/0wd0/majutsu Public API for selection sessions: begin a session, end it if owner, find sections, get selected values, render overlays, highlight trees, and clear selections. Each function has a docstring describing its purpose. ```emacs-lisp (defun majutsu-selection-session-begin () "Begin a selection session for the current buffer/point and return it. The session records its originating buffer and the current revision selection targets." ...) (defun majutsu-selection-session-end-if-owner () "Remove selection overlays in the current buffer." ...) (defun majutsu-selection-find-section (value &optional type root) "Find the section for VALUE in the session buffer and return its section. TYPE and ROOT restrict the search to a section type and root section." ...) (defun majutsu-selection-values (id) "Return the selected values for SELECTION ID, or nil." ...) (defun majutsu-selection-render (&optional session) "Render selection overlays for SESSION (default: the active one)." ...) (defun majutsu-selection-highlight-tree (root state-function selected-face partial-face) "Highlight a section tree based on STATE-FUNCTION." ...) (defun majutsu-selection-clear (&optional id) "Clear the selection with ID or all selections." ...) ``` -------------------------------- ### majutsu-goto-next-revision Source: https://github.com/0wd0/majutsu Navigate to the next revision in the log. ```APIDOC ## majutsu-goto-next-revision ### Description Navigate to the next revision in the log. ### Method Interactive command ### Signature `(defun majutsu-goto-next-revision () ...)` ### Usage Call interactively or from Lisp code. ```