Function: save-match-data

save-match-data is a macro defined in subr.el.gz.

Signature

(save-match-data &rest BODY)

Documentation

Execute the BODY forms, restoring the global value of the match data.

The value returned is the value of the last form in BODY. NOTE: The convention in Elisp is that any function, except for a few exceptions like car/assoc/+/goto-char, can clobber the match data, so save-match-data should normally be used to save *your* match data rather than your caller's match data.

Other relevant functions are documented in the regexp group.

Probably introduced at or before Emacs version 20.1.

Shortdoc

;; regexp
(save-match-data \.\.\.)

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
;;; Matching and match data.

;; We use save-match-data-internal as the local variable because
;; that works ok in practice (people should not use that variable elsewhere).
;; We used to use an uninterned symbol; the compiler handles that properly
;; now, but it generates slower code.
(defmacro save-match-data (&rest body)
  "Execute the BODY forms, restoring the global value of the match data.
The value returned is the value of the last form in BODY.
NOTE: The convention in Elisp is that any function, except for a few
exceptions like car/assoc/+/goto-char, can clobber the match data,
so `save-match-data' should normally be used to save *your* match data
rather than your caller's match data."
  ;; It is better not to use backquote here,
  ;; because that makes a bootstrapping problem
  ;; if you need to recompile all the Lisp files using interpreted code.
  (declare (indent 0) (debug t))
  (list 'let
	'((save-match-data-internal (match-data)))
	(list 'unwind-protect
	      (cons 'progn body)
	      ;; It is safe to free (evaporate) markers immediately here,
	      ;; as Lisp programs should not copy from save-match-data-internal.
	      '(set-match-data save-match-data-internal 'evaporate))))