+ (cond
+ ((not (re-search-forward (if (stringp match) match (car match))
+ nil t))
+ ;; No match yet, try the next rule.
+ (setq match nil))
+ ((and (consp (cdr-safe match)) (nth 2 match))
+ ;; Matched a replacement rule.
+ (let* ((inhibit-read-only t)
+ (buffer-undo-list t)
+ (submatch (nth 1 match))
+ (replacement (nth 2 match))
+ (props (text-properties-at (match-beginning submatch))))
+ (replace-match replacement nil nil nil submatch)
+ (set-text-properties (match-beginning submatch)
+ (match-end submatch)
+ props)
+ ;; Replacement done, now keep trying with subsequent rules.
+ (setq match nil)
+ (goto-char (point-min))))
+ ;; Matched a non-replacement (i.e. electric hide) rule, no need to
+ ;; keep trying.
+ (t (setq regexps nil))))))