comparison lisp/dired.el @ 10214:82e7df72b8a0

(dired-string-replace-match): Function moved here.
author Richard M. Stallman <rms@gnu.org>
date Thu, 22 Dec 1994 04:17:30 +0000
parents b4262885826e
children c643f6d0e579
comparison
equal deleted inserted replaced
10213:dd2102e33b29 10214:82e7df72b8a0
1159 "\""))))) 1159 "\"")))))
1160 (if (eq localp 'no-dir) 1160 (if (eq localp 'no-dir)
1161 file 1161 file
1162 (and file (concat (dired-current-directory localp) file))))) 1162 (and file (concat (dired-current-directory localp) file)))))
1163 1163
1164 ;; Cloning replace-match to work on strings instead of in buffer:
1165 ;; The FIXEDCASE parameter of replace-match is not implemented.
1166 (defun dired-string-replace-match (regexp string newtext
1167 &optional literal global)
1168 "Replace first match of REGEXP in STRING with NEWTEXT.
1169 If it does not match, nil is returned instead of the new string.
1170 Optional arg LITERAL means to take NEWTEXT literally.
1171 Optional arg GLOBAL means to replace all matches."
1172 (if global
1173 (let ((result "") (start 0) mb me)
1174 (while (string-match regexp string start)
1175 (setq mb (match-beginning 0)
1176 me (match-end 0)
1177 result (concat result
1178 (substring string start mb)
1179 (if literal
1180 newtext
1181 (dired-expand-newtext string newtext)))
1182 start me))
1183 (if mb ; matched at least once
1184 (concat result (substring string start))
1185 nil))
1186 ;; not GLOBAL
1187 (if (not (string-match regexp string 0))
1188 nil
1189 (concat (substring string 0 (match-beginning 0))
1190 (if literal newtext (dired-expand-newtext string newtext))
1191 (substring string (match-end 0))))))
1192
1164 (defun dired-make-absolute (file &optional dir) 1193 (defun dired-make-absolute (file &optional dir)
1165 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname." 1194 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname."
1166 ;; We can't always use expand-file-name as this would get rid of `.' 1195 ;; We can't always use expand-file-name as this would get rid of `.'
1167 ;; or expand in / instead default-directory if DIR=="". 1196 ;; or expand in / instead default-directory if DIR=="".
1168 ;; This should be good enough for ange-ftp, but might easily be 1197 ;; This should be good enough for ange-ftp, but might easily be