Function: org-metaup

org-metaup is an interactive and byte-compiled function defined in org.el.gz.

Signature

(org-metaup &optional ARG)

Documentation

Move subtree up or move table row up.

Calls org-move-subtree-up or org-table-move-row or org-move-item-up, depending on context. Everywhere else, move backward the element at point. See the individual commands for more information.

This function runs the functions in org-metaup-hook one by one as a first step, and exits immediately if a function from the hook returns non-nil. In the absence of a specific context, the function runs org-metaup-final-hook using the same logic.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-metaup (&optional _arg)
  "Move subtree up or move table row up.
Calls `org-move-subtree-up' or `org-table-move-row' or
`org-move-item-up', depending on context.  Everywhere else, move
backward the element at point.  See the individual commands for
more information.

This function runs the functions in `org-metaup-hook' one by one
as a first step, and exits immediately if a function from the
hook returns non-nil.  In the absence of a specific context, the
function runs `org-metaup-final-hook' using the same logic."
  (interactive "P")
  (cond
   ((run-hook-with-args-until-success 'org-metaup-hook))
   ((and (org-region-active-p)
         (org-with-limited-levels
          (save-excursion
            (goto-char (region-beginning))
            (org-at-heading-p))))
    (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
    (let ((beg (region-beginning))
          (end (region-end)))
      (save-excursion
        ;; Go a little earlier because `org-move-subtree-down' will
        ;; insert before markers and we may overshoot in some cases.
        (goto-char (max beg (1- end)))
        (setq end (point-marker))
        (goto-char beg)
        (let ((level (org-current-level)))
          (when (or (and (> level 1) (re-search-forward (format "^\\*\\{1,%s\\} " (1- level)) end t))
                    ;; Search previous subtree.
                    (progn
                      (goto-char beg)
                      (forward-line 0)
                      (not (re-search-backward (format "^\\*\\{%s\\} " level) nil t))))
            (user-error "Cannot move past superior level or buffer limit"))
          ;; Drag first subtree above below the selected.
          (while (< (point) end)
            (let ((deactivate-mark nil))
              (call-interactively 'org-move-subtree-down)))))))
   ((org-region-active-p)
    (let* ((a (save-excursion
                (goto-char (region-beginning))
                (line-beginning-position)))
           (b (save-excursion
                (goto-char (region-end))
                (if (bolp) (1- (point)) (line-end-position))))
           (c (save-excursion
                (goto-char a)
                (move-beginning-of-line 0)
                (point)))
           (d (save-excursion
                (goto-char a)
                (move-end-of-line 0)
                (point)))
           (deactivate-mark nil)
           (swap? (< (point) (mark))))
      (transpose-regions a b c d)
      (set-mark c)
      (goto-char (+ c (- b a)))
      (when swap? (exchange-point-and-mark))))
   ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
   ((and (featurep 'org-inlinetask)
         (org-inlinetask-in-task-p))
    (org-drag-element-backward))
   ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
   ((org-at-item-p) (call-interactively 'org-move-item-up))
   ((run-hook-with-args-until-success 'org-metaup-final-hook))
   (t (org-drag-element-backward))))