Function: hpath:substitute-match-value
hpath:substitute-match-value is a byte-compiled function defined in
hpath.el.
Signature
(hpath:substitute-match-value REGEXP STR NEW &optional LITERAL FIXEDCASE)
Documentation
Replace all matches for REGEXP in STR with NEW string and return the result.
Optional LITERAL non-nil means do a literal replacement.
Otherwise treat \ in NEW string as special:
\& means substitute original matched text,
\N means substitute match for (...) number N,
\\ means insert one \.
If optional fifth arg FIXEDCASE is non-nil, do not alter the case of the replacement text. Otherwise, maybe capitalize the whole text, or maybe just word initials, based on the replaced text. If the replaced text has only capital letters and has at least one multiletter word, convert NEW to all caps. Otherwise if all words are capitalized in the replaced text, capitalize each word in NEW.
NEW may instead be a function of one argument (the string to replace in) that returns a replacement string.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(defun hpath:substitute-match-value (regexp str new &optional literal fixedcase)
"Replace all matches for REGEXP in STR with NEW string and return the result.
Optional LITERAL non-nil means do a literal replacement.
Otherwise treat \\ in NEW string as special:
\\& means substitute original matched text,
\\N means substitute match for \(...\) number N,
\\\\ means insert one \\.
If optional fifth arg FIXEDCASE is non-nil, do not alter the case of
the replacement text. Otherwise, maybe capitalize the whole text, or
maybe just word initials, based on the replaced text. If the replaced
text has only capital letters and has at least one multiletter word,
convert NEW to all caps. Otherwise if all words are capitalized
in the replaced text, capitalize each word in NEW.
NEW may instead be a function of one argument (the string to replace in)
that returns a replacement string."
(unless (stringp str)
(error "(hpath:substitute-match-value): 2nd arg must be a string: %s" str))
(unless (or (stringp new) (functionp new))
(error "(hpath:substitute-match-value): 3rd arg must be a string or function: %s"
new))
(let ((rtn-str "")
(start 0)
(special)
match prev-start)
(while (setq match (string-match regexp str start))
(setq prev-start start
start (match-end 0)
rtn-str
(concat
rtn-str
(substring str prev-start match)
(cond ((functionp new)
(replace-regexp-in-string
regexp (funcall new str)
(substring str match start) fixedcase literal))
(literal new)
(t (mapconcat
(lambda (c)
(cond (special
(setq special nil)
(cond ((eq c ?\\) "\\")
((eq c ?&)
(match-string 0 str))
((and (>= c ?0) (<= c ?9))
(if (> c (+ ?0 (length (match-data))))
;; Invalid match num
(error "(hpath:substitute-match-value): Invalid match num: %c" c)
(setq c (- c ?0))
(match-string c str)))
(t (char-to-string c))))
((eq c ?\\)
(setq special t)
nil)
(t (char-to-string c))))
new ""))))))
(if (or (null rtn-str) (string-empty-p rtn-str))
str
(concat rtn-str (substring str start)))))