diff options
| author | Lars Ingebrigtsen | 2021-11-10 00:26:32 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-11-10 00:26:32 +0100 |
| commit | 2e6ed253ce485698df649904bd9e5254a3f4bf94 (patch) | |
| tree | 80d51ebb50d65eddd987b89e93d4d52499a48109 /lisp | |
| parent | fdc00b98361300861db6402e021d335025f6e8ce (diff) | |
| download | emacs-2e6ed253ce485698df649904bd9e5254a3f4bf94.tar.gz emacs-2e6ed253ce485698df649904bd9e5254a3f4bf94.zip | |
Add new function 'file-name-split'
* doc/lispref/files.texi (File Name Components): Document it.
* lisp/files.el (file-name-split): New function (bug#50572).
* lisp/emacs-lisp/shortdoc.el (file-name): Mention it.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/shortdoc.el | 3 | ||||
| -rw-r--r-- | lisp/files.el | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index c3d6c742940..a9f548b104e 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el | |||
| @@ -281,6 +281,9 @@ There can be any number of :example/:result elements." | |||
| 281 | :eval (file-name-base "/tmp/foo.txt")) | 281 | :eval (file-name-base "/tmp/foo.txt")) |
| 282 | (file-relative-name | 282 | (file-relative-name |
| 283 | :eval (file-relative-name "/tmp/foo" "/tmp")) | 283 | :eval (file-relative-name "/tmp/foo" "/tmp")) |
| 284 | (file-name-split | ||
| 285 | :eval (file-name-split "/tmp/foo") | ||
| 286 | :eval (file-name-split "foo/bar")) | ||
| 284 | (make-temp-name | 287 | (make-temp-name |
| 285 | :eval (make-temp-name "/tmp/foo-")) | 288 | :eval (make-temp-name "/tmp/foo-")) |
| 286 | (file-name-concat | 289 | (file-name-concat |
diff --git a/lisp/files.el b/lisp/files.el index 0bc7a92fbea..c694df38268 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -5051,6 +5051,29 @@ See also `file-name-sans-extension'." | |||
| 5051 | (file-name-sans-extension | 5051 | (file-name-sans-extension |
| 5052 | (file-name-nondirectory (or filename (buffer-file-name))))) | 5052 | (file-name-nondirectory (or filename (buffer-file-name))))) |
| 5053 | 5053 | ||
| 5054 | (defun file-name-split (filename) | ||
| 5055 | "Return a list of all the components of FILENAME. | ||
| 5056 | On most systems, this will be true: | ||
| 5057 | |||
| 5058 | (equal (string-join (file-name-split filename) \"/\") filename)" | ||
| 5059 | (let ((components nil)) | ||
| 5060 | ;; If this is a directory file name, then we have a null file name | ||
| 5061 | ;; at the end. | ||
| 5062 | (when (directory-name-p filename) | ||
| 5063 | (push "" components) | ||
| 5064 | (setq filename (directory-file-name filename))) | ||
| 5065 | ;; Loop, chopping off components. | ||
| 5066 | (while (length> filename 0) | ||
| 5067 | (push (file-name-nondirectory filename) components) | ||
| 5068 | (let ((dir (file-name-directory filename))) | ||
| 5069 | (setq filename (and dir (directory-file-name dir))) | ||
| 5070 | ;; If there's nothing left to peel off, we're at the root and | ||
| 5071 | ;; we can stop. | ||
| 5072 | (when (equal dir filename) | ||
| 5073 | (push "" components) | ||
| 5074 | (setq filename nil)))) | ||
| 5075 | components)) | ||
| 5076 | |||
| 5054 | (defcustom make-backup-file-name-function | 5077 | (defcustom make-backup-file-name-function |
| 5055 | #'make-backup-file-name--default-function | 5078 | #'make-backup-file-name--default-function |
| 5056 | "A function that `make-backup-file-name' uses to create backup file names. | 5079 | "A function that `make-backup-file-name' uses to create backup file names. |