aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Aspinall2000-05-29 15:24:38 +0000
committerDavid Aspinall2000-05-29 15:24:38 +0000
commitbcb6426ef3fe0643628ab8b38b5bff20f0ddc462 (patch)
tree28be95e6afeed867f7b3a5cf464e0f35ca2e27cc
parentdf76c2522005c5dbd4453c8ee146c50301e9a3fe (diff)
Added replace-string for FSF.
-rw-r--r--generic/proof-compat.el53
1 files changed, 53 insertions, 0 deletions
diff --git a/generic/proof-compat.el b/generic/proof-compat.el
index c047b364..041f1abc 100644
--- a/generic/proof-compat.el
+++ b/generic/proof-compat.el
@@ -49,6 +49,7 @@
;;; FSF compatibility
;;;
+
;; These days cl is dumped with XEmacs (20.4,21.1) but not FSF Emacs
;; 20.2. Would rather it was autoloaded but the autoloads are broken
;; in FSF so we load it now.
@@ -75,6 +76,58 @@
"Dummy function for Proof General on FSF Emacs."
nil)) ;; pretend always interactive.
+;; Replacing in string (useful function from subr.el in XEmacs 21.1.9)
+(or (fboundp 'replace-in-string)
+(defun replace-in-string (str regexp newtext &optional literal)
+ "Replace all matches in STR for REGEXP with NEWTEXT string,
+ and returns the new string.
+Optional LITERAL non-nil means do a literal replacement.
+Otherwise treat \\ in NEWTEXT string as special:
+ \\& means substitute original matched text,
+ \\N means substitute match for \(...\) number N,
+ \\\\ means insert one \\."
+ ;; Not present in FSF
+ ;; (check-argument-type 'stringp str)
+ ;; (check-argument-type 'stringp newtext)
+ (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 (literal newtext)
+ (t (mapconcat
+ (lambda (c)
+ (if special
+ (progn
+ (setq special nil)
+ (cond ((eq c ?\\) "\\")
+ ((eq c ?&)
+ (substring str
+ (match-beginning 0)
+ (match-end 0)))
+ ((and (>= c ?0) (<= c ?9))
+ (if (> c (+ ?0 (length
+ (match-data))))
+ ;; Invalid match num
+ (error "Invalid match num: %c" c)
+ (setq c (- c ?0))
+ (substring str
+ (match-beginning c)
+ (match-end c))))
+ (t (char-to-string c))))
+ (if (eq c ?\\) (progn (setq special t) nil)
+ (char-to-string c))))
+ newtext ""))))))
+ (concat rtn-str (substring str start)))))
+
+
+
;; In case Emacs is not aware of the function read-shell-command,
;; we duplicate some code adjusted from minibuf.el distributed