Function: edmacro-set-macro-to-region-lines

edmacro-set-macro-to-region-lines is an interactive and byte-compiled function defined in edmacro.el.gz.

Signature

(edmacro-set-macro-to-region-lines BEG END)

Documentation

Set the macro text to lines of text in the buffer between BEG and END.

Interactively, BEG and END are the beginning and end of the region. If the region does not begin at the start of a line or if it does not end at the end of a line, the region is extended to include complete lines. If the region ends at the beginning of a line, that final line is excluded.

View in manual

Probably introduced at or before Emacs version 30.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/edmacro.el.gz
(defun edmacro-set-macro-to-region-lines (beg end)
  "Set the macro text to lines of text in the buffer between BEG and END.

Interactively, BEG and END are the beginning and end of the
region.  If the region does not begin at the start of a line or
if it does not end at the end of a line, the region is extended
to include complete lines.  If the region ends at the beginning
of a line, that final line is excluded."
  (interactive "*r" edmacro-mode)
  ;; Use `save-excursion' to restore region if there are any errors.
  ;; If there are no errors, update the macro text, then go to the
  ;; beginning of the macro text.
  (let ((final-position))
    (save-excursion
      (goto-char beg)
      (unless (bolp) (setq beg (pos-bol)))
      (goto-char end)
      (unless (or (bolp) (eolp)) (setq end (pos-eol)))
      (let ((text (buffer-substring beg end)))
        (goto-char (point-min))
        (if (not (let ((case-fold-search nil))
                   (re-search-forward edmacro--macro-lines-regexp nil t)))
            (user-error "\"Macro:\" line not found")
          (delete-region (match-end 0)
                         (point-max))
          (goto-char (point-max))
          (insert text)
          (setq final-position (match-beginning 0)))))
    (goto-char final-position)))