diff options
| author | Michael Albinus | 2021-06-19 14:01:13 +0200 |
|---|---|---|
| committer | Michael Albinus | 2021-06-19 14:01:13 +0200 |
| commit | 284dfd3613128a6993dc2386cc6000db96e760b8 (patch) | |
| tree | 1a52a7c06fe1053aa7fbb218f800c9562598af45 | |
| parent | 4f1a5e456e35930e8d0713b990bd7b14923cfe97 (diff) | |
| download | emacs-284dfd3613128a6993dc2386cc6000db96e760b8.tar.gz emacs-284dfd3613128a6993dc2386cc6000db96e760b8.zip | |
Revert "Add `file-name-set-extension'"
This reverts commit 4f1a5e456e35930e8d0713b990bd7b14923cfe97.
| -rw-r--r-- | lisp/files.el | 14 | ||||
| -rw-r--r-- | test/lisp/files-tests.el | 20 |
2 files changed, 0 insertions, 34 deletions
diff --git a/lisp/files.el b/lisp/files.el index 5fb9b9dcdcb..2450daf5bfc 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4892,20 +4892,6 @@ extension, the value is \"\"." | |||
| 4892 | (if period | 4892 | (if period |
| 4893 | ""))))) | 4893 | ""))))) |
| 4894 | 4894 | ||
| 4895 | (defun file-name-with-extension (filename extension) | ||
| 4896 | "Set the EXTENSION of a FILENAME. | ||
| 4897 | Consolidates leading/trailing dots so that either `foo' or `.foo' | ||
| 4898 | can be passed as an EXTENSION. | ||
| 4899 | |||
| 4900 | See also `file-name-sans-extension'." | ||
| 4901 | (let* ((patt "[ .]+") | ||
| 4902 | (file (string-trim-right filename patt)) | ||
| 4903 | (extn (string-trim-left extension patt))) | ||
| 4904 | (cond ((string-empty-p file) (error "Malformed filename: %s" filename)) | ||
| 4905 | ((string-empty-p extn) (error "Malformed extension: %s" extension)) | ||
| 4906 | ((directory-name-p file) (error "Filename is a directory: %s" filename)) | ||
| 4907 | (t (concat (file-name-sans-extension file) "." extn))))) | ||
| 4908 | |||
| 4909 | (defun file-name-base (&optional filename) | 4895 | (defun file-name-base (&optional filename) |
| 4910 | "Return the base name of the FILENAME: no directory, no extension." | 4896 | "Return the base name of the FILENAME: no directory, no extension." |
| 4911 | (declare (advertised-calling-convention (filename) "27.1")) | 4897 | (declare (advertised-calling-convention (filename) "27.1")) |
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 80f47a78dc8..dc96dff6398 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el | |||
| @@ -1478,25 +1478,5 @@ The door of all subtleties! | |||
| 1478 | (buffer-substring (point-min) (point-max)) | 1478 | (buffer-substring (point-min) (point-max)) |
| 1479 | nil nil))))) | 1479 | nil nil))))) |
| 1480 | 1480 | ||
| 1481 | (ert-deftest files-tests-file-name-with-extension-good () | ||
| 1482 | "Test that `file-name-with-extension' succeeds with reasonable input." | ||
| 1483 | (should (string= (file-name-with-extension "Jack" "css") "Jack.css")) | ||
| 1484 | (should (string= (file-name-with-extension "Jack" ".css") "Jack.css")) | ||
| 1485 | (should (string= (file-name-with-extension "Jack.scss" "css") "Jack.css")) | ||
| 1486 | (should (string= (file-name-with-extension "Jack..." "...css") "Jack.css")) | ||
| 1487 | (should (string= (file-name-with-extension "/path/to/Jack.md" "org") "/path/to/Jack.org"))) | ||
| 1488 | |||
| 1489 | (ert-deftest files-tests-file-name-with-extension-bad () | ||
| 1490 | "Test that `file-name-with-extension' fails on malformed input." | ||
| 1491 | (should-error (file-name-with-extension nil nil)) | ||
| 1492 | (should-error (file-name-with-extension "Jack" nil)) | ||
| 1493 | (should-error (file-name-with-extension nil "css")) | ||
| 1494 | (should-error (file-name-with-extension "" "")) | ||
| 1495 | (should-error (file-name-with-extension "" "css")) | ||
| 1496 | (should-error (file-name-with-extension "Jack" "")) | ||
| 1497 | (should-error (file-name-with-extension "Jack" "...")) | ||
| 1498 | (should-error (file-name-with-extension "..." "css")) | ||
| 1499 | (should-error (file-name-with-extension "/is/a/directory/" "css"))) | ||
| 1500 | |||
| 1501 | (provide 'files-tests) | 1481 | (provide 'files-tests) |
| 1502 | ;;; files-tests.el ends here | 1482 | ;;; files-tests.el ends here |