Function: kmacro-menu-edit-position

kmacro-menu-edit-position is an interactive and byte-compiled function defined in kmacro.el.gz.

Signature

(kmacro-menu-edit-position)

Documentation

Move the keyboard macro at point to a new position.

See the Info node (emacs) Keyboard Macro Ring for more information.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/kmacro.el.gz
;;;; Commands that Modify a Keyboard Macro

(defun kmacro-menu-edit-position ()
  "Move the keyboard macro at point to a new position.

See the Info node `(emacs) Keyboard Macro Ring' for more information."
  (declare (modes kmacro-menu-mode))
  (interactive nil kmacro-menu-mode)
  (let ((id (tabulated-list-get-id)))
    (kmacro-menu--assert-row id)
    (kmacro-menu--query-revert)
    (let* ((new-position (min (length tabulated-list-entries)
                              (max 0
                                   (read-number "New position: " 0))))
           (old-km (kmacro-menu--id-kmacro id))
           (old-pos (kmacro-menu--id-position id)))
      (unless (= old-pos new-position)
        (kmacro-menu--replace-all
         (let ((res)
               (true-new-pos (if (> new-position old-pos)
                                 (1+ new-position)
                               new-position)))
           (kmacro-menu--map-ids (lambda (this-id)
                                   (let ((this-km (kmacro-menu--id-kmacro this-id))
                                         (this-pos (kmacro-menu--id-position this-id)))
                                     (unless (= old-pos this-pos)
                                       (when (= this-pos true-new-pos)
                                         (push old-km res))
                                       (push this-km res)))))
           (when (>= true-new-pos
                     (length tabulated-list-entries))
             (push old-km res))
           (nreverse res)))
        (tabulated-list-revert)))))