+(make-obsolete 'tildify--pick-alist-entry
+ "it should not be used in new code." "25.1")
+
+(defun tildify--deprecated-ignore-evironments (callback beg end)
+ "Call CALLBACK on regions between BEG and END.
+
+Call CALLBACK on each region outside of environment to ignore. Stop scanning
+the region as soon as CALLBACK returns nil. Environments to ignore are
+defined by deprecated `tildify-ignored-environments-alist'. CALLBACK may be
+called on portions of the buffer outside of [BEG END)."
+ (let ((pairs (tildify--pick-alist-entry tildify-ignored-environments-alist)))
+ (if pairs
+ (tildify-foreach-ignore-environments pairs callback beg end)
+ (funcall callback beg end))))
+(make-obsolete 'tildify--deprecated-ignore-evironments
+ "it should not be used in new code." "25.1")
+
+(defun tildify-foreach-ignore-environments (pairs callback _beg end)
+ "Outside of environments defined by PAIRS call CALLBACK.
+
+PAIRS is a list of (BEG-REGEX . END-REGEX) cons. BEG-REGEX is a regexp matching
+beginning of a text part to be skipped. END-REGEX defines end of the
+corresponding text part and can be either:
+- a regexp matching the end of the skipped text part
+- a list of regexps and numbers, which will compose the ending regexp by
+ concatenating themselves, while replacing the numbers with corresponding
+ subexpressions of BEG-REGEX (this is used to solve cases like
+ \\\\verb<character> in TeX).
+
+CALLBACK is a function accepting two arguments -- REG-BEG and REG-END -- that
+will be called for portions of the buffer outside of the environments defined by
+PAIRS regexes.
+
+The function will return as soon as CALLBACK returns nil or point goes past END.
+CALLBACK may be called on portions of the buffer outside of [BEG END); in fact
+BEG argument is ignored.
+
+This function is meant to be used to set `tildify-foreach-region-function'
+variable. For example, for an XML file one might use:
+ (setq-local tildify-foreach-region-function
+ (apply-partially 'tildify-foreach-ignore-environments
+ '((\"<! *--\" . \"-- *>\") (\"<\" . \">\"))))"
+ (let ((beg-re (concat "\\(?:" (mapconcat 'car pairs "\\)\\|\\(?:") "\\)"))
+ p end-re)
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (while (and (< (setq p (point)) end)
+ (if (setq end-re (tildify--find-env beg-re pairs))
+ (and (funcall callback p (match-beginning 0))
+ (< (point) end)
+ (re-search-forward end-re nil t))
+ (funcall callback p end)
+ nil)))))))
+
+(defun tildify--foreach-region (callback beg end)
+ "Call CALLBACK on portions of the buffer between BEG and END.
+
+Which portions to call CALLBACK on is determined by
+`tildify-foreach-region-function' variable. This function merely makes sure
+CALLBACK is not called with portions of the buffer outside of [BEG END)."
+ (let ((func (lambda (reg-beg reg-end)
+ (setq reg-beg (max reg-beg beg) reg-end (min reg-end end))
+ (and (or (>= reg-beg reg-end)
+ (funcall callback reg-beg reg-end))
+ (< reg-end end)))))
+ (funcall tildify-foreach-region-function func beg end)))
+
+(defun tildify--find-env (regexp pairs)