aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-07-24 13:30:58 +0200
committerLars Ingebrigtsen2021-07-24 13:30:58 +0200
commit5431a58e86d3f2579c1edf1dc8d7074de73ac694 (patch)
treef33798b55f473cbb7337a84e669b3c07053671d9 /src
parent9ac6ff53b105925400a773a5088c9d0ec5b095a4 (diff)
downloademacs-5431a58e86d3f2579c1edf1dc8d7074de73ac694.tar.gz
emacs-5431a58e86d3f2579c1edf1dc8d7074de73ac694.zip
Add new function `directory-append'
* doc/lispref/files.texi (Directory Names): Document it, and remove the concat-based file concatenation description. * lisp/emacs-lisp/shortdoc.el (file-name): Add. And add more expand-file-name examples. * src/fileio.c (Fdirectory_append): New function.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 04c9d7d4af3..277da48315e 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -749,6 +749,51 @@ For that reason, you should normally use `make-temp-file' instead. */)
749 empty_unibyte_string, Qnil); 749 empty_unibyte_string, Qnil);
750} 750}
751 751
752DEFUN ("directory-append", Fdirectory_append, Sdirectory_append, 2, 2, 0,
753 doc: /* Return FILE (a string) appended to DIRECTORY (a string).
754DIRECTORY may or may not end with a slash -- the return value from
755this function will be the same. */)
756 (Lisp_Object directory, Lisp_Object file)
757{
758 USE_SAFE_ALLOCA;
759 char *p;
760
761 CHECK_STRING (file);
762 CHECK_STRING (directory);
763
764 if (SCHARS (file) == 0)
765 xsignal1 (Qfile_error, build_string ("Empty file name"));
766
767 if (SCHARS (directory) == 0)
768 return file;
769
770 /* Make the strings the same multibytedness. */
771 if (STRING_MULTIBYTE (file) != STRING_MULTIBYTE (directory))
772 {
773 if (STRING_MULTIBYTE (file))
774 directory = make_multibyte_string (SSDATA (directory),
775 SCHARS (directory),
776 SCHARS (directory));
777 else
778 file = make_multibyte_string (SSDATA (file),
779 SCHARS (file),
780 SCHARS (file));
781 }
782
783 /* Allocate enough extra space in case we need to put a slash in
784 there. */
785 p = SAFE_ALLOCA (SBYTES (file) + SBYTES (directory) + 2);
786 ptrdiff_t offset = SBYTES (directory);
787 memcpy (p, SSDATA (directory), offset);
788 if (! IS_DIRECTORY_SEP (p[offset - 1]))
789 p[offset++] = DIRECTORY_SEP;
790 memcpy (p + offset, SSDATA (file), SBYTES (file));
791 p[offset + SBYTES (file)] = 0;
792 Lisp_Object result = build_string (p);
793 SAFE_FREE ();
794 return result;
795}
796
752/* NAME must be a string. */ 797/* NAME must be a string. */
753static bool 798static bool
754file_name_absolute_no_tilde_p (Lisp_Object name) 799file_name_absolute_no_tilde_p (Lisp_Object name)
@@ -6488,6 +6533,7 @@ This includes interactive calls to `delete-file' and
6488 defsubr (&Sdirectory_file_name); 6533 defsubr (&Sdirectory_file_name);
6489 defsubr (&Smake_temp_file_internal); 6534 defsubr (&Smake_temp_file_internal);
6490 defsubr (&Smake_temp_name); 6535 defsubr (&Smake_temp_name);
6536 defsubr (&Sdirectory_append);
6491 defsubr (&Sexpand_file_name); 6537 defsubr (&Sexpand_file_name);
6492 defsubr (&Ssubstitute_in_file_name); 6538 defsubr (&Ssubstitute_in_file_name);
6493 defsubr (&Scopy_file); 6539 defsubr (&Scopy_file);