Function: forge-create-post

forge-create-post is an interactive and byte-compiled function defined in forge-commands.el.

Signature

(forge-create-post &optional QUOTE)

Documentation

Create a new post on an existing topic.

If the region is active, then quote that part of the post. Otherwise and with a prefix argument quote the post that point is currently on.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/forge-20260408.1922/forge-commands.el
(defun forge-create-post (&optional quote)
  "Create a new post on an existing topic.
If the region is active, then quote that part of the post.
Otherwise and with a prefix argument quote the post that
point is currently on."
  (interactive (list current-prefix-arg))
  (unless (derived-mode-p 'forge-topic-mode)
    (user-error "This command is only available from topic buffers"))
  (let* ((quote (cond
                  ((not (magit-section-match 'post)) nil)
                  ((use-region-p)
                   (buffer-str (region-beginning) (region-end)))
                  (quote
                   (with-slots (content end) (magit-current-section)
                     (string-trim (buffer-str content end))))))
         (quote (and quote
                     (lambda ()
                       (goto-char (point-max))
                       (unless (bobp)
                         (insert "\n"))
                       (insert (replace-regexp-in-string "^" "> " quote))
                       (insert "\n\n"))))
         (obj (if (forge-discussion-p forge-buffer-topic)
                  (forge--select-discussion-reply-target)
                forge-buffer-topic)))
    (cl-typecase obj
      (forge-discussion-post
       (forge--setup-post-buffer obj #'forge--submit-create-post
         "%i;%I;new-reply" "New comment on #%i;%I of %p" nil quote))
      (forge-discussion
       (forge--setup-post-buffer obj #'forge--submit-create-post
         "%i;new-answer" "New comment on #%i of %p" nil quote))
      (t
       (forge--setup-post-buffer obj #'forge--submit-create-post
         "%i;new-comment" "New comment on #%i of %p" nil quote)))))