# HG changeset patch # User Roland McGrath # Date 717560731 0 # Node ID d4324e885a417aaa621691f9c4b9af781dda4faa # Parent 8abf83cc14b18e4dda1886b1b8ef046e69c876ce (file-relative-name): New function. diff -r 8abf83cc14b1 -r d4324e885a41 lisp/files.el --- a/lisp/files.el Sun Sep 27 01:55:21 1992 +0000 +++ b/lisp/files.el Sun Sep 27 02:25:31 1992 +0000 @@ -936,6 +936,15 @@ (defun file-nlinks (filename) "Return number of names file FILENAME has." (car (cdr (file-attributes filename)))) + +(defun file-relative-name (filename &optional directory) + "Convert FILENAME to be relative to DIRECTORY (default: default-directory)." + (setq filename (expand-file-name filename) + directory (file-name-as-directory (or (expand-file-name directory) + default-directory))) + (while (not (string-match (concat "^" (regexp-quote directory)) filename)) + (setq directory (file-name-directory (substring directory 0 -1)))) + (substring filename (match-end 0))) (defun save-buffer (&optional args) "Save current buffer in visited file if modified. Versions described below.