Function: majutsu--jj-insert

majutsu--jj-insert is a natively compiled function defined in majutsu-jj.el.

Signature

(majutsu--jj-insert RETURN-ERROR &rest ARGS)

Documentation

Run jj with ARGS and insert output at point.

If RETURN-ERROR is nil, return the exit code. If RETURN-ERROR is non-nil, return the error message if the command fails, or the exit code if there is no error output. When RETURN-ERROR is full, return the full stderr output on error.

This is the low-level worker for majutsu-jj-insert and similar functions.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-jj.el
(defun majutsu--jj-insert (return-error &rest args)
  "Run jj with ARGS and insert output at point.

If RETURN-ERROR is nil, return the exit code.  If RETURN-ERROR is
non-nil, return the error message if the command fails, or the
exit code if there is no error output.  When RETURN-ERROR is
`full', return the full stderr output on error.

This is the low-level worker for `majutsu-jj-insert' and similar
functions."
  (setq args (flatten-tree args))
  (let* ((start-time (current-time))
         (err-file (and return-error
                        (make-nearby-temp-file "majutsu-jj-err")))
         exit-code)
    (majutsu--debug "Running command: %s %s" (majutsu-jj--executable) (string-join args " "))
    (setq exit-code (majutsu-process-jj (list t err-file) args))
    (majutsu--debug "Command completed in %.3f seconds, exit code: %d"
                    (float-time (time-subtract (current-time) start-time))
                    exit-code)
    (when (and majutsu-show-command-output (> (point-max) (point-min)))
      (majutsu--debug "Command output: %s"
                      (string-trim (buffer-substring (point-min) (point-max)))))
    (prog1 (if (and err-file (not (zerop exit-code)))
               (with-temp-buffer
                 (insert-file-contents err-file)
                 (if (eq return-error 'full)
                     (buffer-string)
                   (let ((line (car (split-string (buffer-string) "\n" t))))
                     (or line exit-code))))
             exit-code)
      (when err-file (ignore-errors (delete-file err-file))))))