diff options
| author | Richard M. Stallman | 1994-12-22 04:17:30 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-12-22 04:17:30 +0000 |
| commit | 437fe5aeffe4782f9cc8b149a91139027a1b1e4d (patch) | |
| tree | f4e047c51a3f09669c19f33b5425af3be9fc315f | |
| parent | f9acc7fb73e679264f68f00be9b3a9fabccff30d (diff) | |
| download | emacs-437fe5aeffe4782f9cc8b149a91139027a1b1e4d.tar.gz emacs-437fe5aeffe4782f9cc8b149a91139027a1b1e4d.zip | |
(dired-string-replace-match): Function moved here.
| -rw-r--r-- | lisp/dired.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index e0303cb4f00..a02f63a7efe 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -1161,6 +1161,35 @@ Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on | |||
| 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 `.' |