Function: just-src-edit

just-src-edit is an interactive and natively compiled function defined in just-ts-mode.el.

Signature

(just-src-edit)

Documentation

Edit the task body at point in a dedicated buffer.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/1vmf8s52d6vniw28ckf3szxslimhfphb-emacs-packages-deps/share/emacs/site-lisp/elpa/just-ts-mode-20260319.1513/just-ts-mode.el
(defun just-src-edit ()
  "Edit the task body at point in a dedicated buffer."
  (interactive)
  (let ((task-info (just-src-edit--find-task-bounds)))
    (unless task-info
      (user-error "Not in a task body"))

    (let* ((task-name (nth 0 task-info))
           (body-start (nth 1 task-info))
           (body-end (nth 2 task-info))
           (original-buffer (current-buffer))
           (indentation (just-src-edit--calculate-indentation body-start body-end))
           (content (buffer-substring-no-properties body-start body-end))
           (clean-content (just-src-edit--remove-indentation content indentation))
           (edit-buffer (generate-new-buffer (format "*Just Task: %s*" task-name))))

      ;; Switch to edit buffer
      (pop-to-buffer edit-buffer)

      ;; Insert content and set up buffer
      (insert clean-content)
      (goto-char (point-min))

      ;; Ensure buffer ends with newline
      (goto-char (point-max))
      (unless (and (> (point-max) (point-min))
                   (= (char-before) ?\n))
        (insert "\n"))
      (goto-char (point-min))

      ;; Detect and set appropriate mode
      (if (string-match "^#!" clean-content)
          (normal-mode)
        (sh-mode))

      ;; Set up buffer-local variables
      (setq just-src-edit--original-buffer original-buffer)
      (setq just-src-edit--beg-marker (with-current-buffer original-buffer
                                        (copy-marker body-start)))
      (setq just-src-edit--end-marker (with-current-buffer original-buffer
                                        (copy-marker body-end t)))
      (setq just-src-edit--indentation indentation)
      (setq just-src-edit--task-name task-name)

      ;; Enable the minor mode for keybindings
      (just-src-edit-mode 1)

      ;; Show helpful message
      (message "Edit task '%s'. %s" task-name (just-src-edit--describe-bindings)))))