Function: magit-copy-section-value

magit-copy-section-value is an autoloaded, interactive and byte-compiled function defined in magit-extras.el.

Signature

(magit-copy-section-value ARG)

Documentation

Save the value of the current section for later use.

Save the section value to the kill-ring, and, provided that the current section is a commit, branch, or tag section, push the (referenced) revision to the magit-revision-stack for use with magit-pop-revision-stack.

When magit-copy-revision-abbreviated is non-nil, save the abbreviated revision to the kill-ring and the magit-revision-stack.

When the current section is a branch or a tag, and a prefix argument is used, then save the revision at its tip to the kill-ring instead of the reference name.

When the region is active, then save that to the kill-ring, like kill-ring-save would, instead of behaving as described above. If a prefix argument is used and the region is within a hunk, then strip the diff marker column and keep only either the added or removed lines, depending on the sign of the prefix argument.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-extras.el
;;;###autoload
(defun magit-copy-section-value (arg)
  "Save the value of the current section for later use.

Save the section value to the `kill-ring', and, provided that
the current section is a commit, branch, or tag section, push
the (referenced) revision to the `magit-revision-stack' for use
with `magit-pop-revision-stack'.

When `magit-copy-revision-abbreviated' is non-nil, save the
abbreviated revision to the `kill-ring' and the
`magit-revision-stack'.

When the current section is a branch or a tag, and a prefix
argument is used, then save the revision at its tip to the
`kill-ring' instead of the reference name.

When the region is active, then save that to the `kill-ring',
like `kill-ring-save' would, instead of behaving as described
above.  If a prefix argument is used and the region is within
a hunk, then strip the diff marker column and keep only either
the added or removed lines, depending on the sign of the prefix
argument."
  (interactive "P")
  (cond-let*
    ((and arg
          (magit-section-internal-region-p)
          (magit-section-match 'hunk))
     (kill-new
      (thread-last (buffer-substring-no-properties
                    (region-beginning)
                    (region-end))
        (replace-regexp-in-string
         (format "^\\%c.*\n?" (if (< (prefix-numeric-value arg) 0) ?+ ?-))
         "")
        (replace-regexp-in-string "^[ +-]" "")))
     (deactivate-mark))
    ((use-region-p)
     (call-interactively #'copy-region-as-kill))
    ([section (magit-current-section)]
     [value (oref section value)]
     (magit-section-case
       ((branch commit module-commit tag)
        (let ((default-directory default-directory) ref)
          (magit-section-case
            ((branch tag)
             (setq ref value))
            (module-commit
             (setq default-directory
                   (file-name-as-directory
                    (expand-file-name (magit-section-parent-value section)
                                      (magit-toplevel))))))
          (setq value (magit-rev-parse
                       (and magit-copy-revision-abbreviated "--short")
                       value))
          (push (list value default-directory) magit-revision-stack)
          (kill-new (message "%s" (or (and current-prefix-arg ref)
                                      value)))))
       (t (kill-new (message "%s" value)))))))