aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-08-21 01:15:25 +0000
committerRichard M. Stallman1995-08-21 01:15:25 +0000
commit856321e221094e93285cd3e03b6699e1152793de (patch)
tree5583b607af69d49d26be0be06a3bb6ea5a5a3644
parent0b1c32a15f983fdb6691de0a99b256cab4a3f03f (diff)
downloademacs-856321e221094e93285cd3e03b6699e1152793de.tar.gz
emacs-856321e221094e93285cd3e03b6699e1152793de.zip
(dired-string-replace-match): Simplify using replace-match.
-rw-r--r--lisp/dired.el26
1 files changed, 7 insertions, 19 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 1385c798535..9b0ba468fb5 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1177,8 +1177,6 @@ Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
1177 file 1177 file
1178 (and file (concat (dired-current-directory localp) file))))) 1178 (and file (concat (dired-current-directory localp) file)))))
1179 1179
1180;; Cloning replace-match to work on strings instead of in buffer:
1181;; The FIXEDCASE parameter of replace-match is not implemented.
1182(defun dired-string-replace-match (regexp string newtext 1180(defun dired-string-replace-match (regexp string newtext
1183 &optional literal global) 1181 &optional literal global)
1184 "Replace first match of REGEXP in STRING with NEWTEXT. 1182 "Replace first match of REGEXP in STRING with NEWTEXT.
@@ -1186,25 +1184,15 @@ If it does not match, nil is returned instead of the new string.
1186Optional arg LITERAL means to take NEWTEXT literally. 1184Optional arg LITERAL means to take NEWTEXT literally.
1187Optional arg GLOBAL means to replace all matches." 1185Optional arg GLOBAL means to replace all matches."
1188 (if global 1186 (if global
1189 (let ((result "") (start 0) mb me) 1187 (let ((start 0))
1190 (while (string-match regexp string start) 1188 (while (string-match regexp string start)
1191 (setq mb (match-beginning 0) 1189 (let ((from-end (- (length string) (match-end 0))))
1192 me (match-end 0) 1190 (setq string (replace-match newtext t literal string))
1193 result (concat result 1191 (setq start (- (length string) from-end))))
1194 (substring string start mb) 1192 string)
1195 (if literal
1196 newtext
1197 (dired-expand-newtext string newtext)))
1198 start me))
1199 (if mb ; matched at least once
1200 (concat result (substring string start))
1201 nil))
1202 ;; not GLOBAL
1203 (if (not (string-match regexp string 0)) 1193 (if (not (string-match regexp string 0))
1204 nil 1194 nil
1205 (concat (substring string 0 (match-beginning 0)) 1195 (replace-match newtext t literal string))))
1206 (if literal newtext (dired-expand-newtext string newtext))
1207 (substring string (match-end 0))))))
1208 1196
1209(defun dired-make-absolute (file &optional dir) 1197(defun dired-make-absolute (file &optional dir)
1210 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname." 1198 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname."