# HG changeset patch # User Eli Zaretskii # Date 1003767072 0 # Node ID 85c9805cd23725ae07fbe958f3c9800f28ad81d6 # Parent e6f3d0e027264b830a2e2aa1cd3a91ca8515eaa5 (file-name-sans-extension, file-name-extension): Don't count the leading dots in file names as signaling an extension. diff -r e6f3d0e02726 -r 85c9805cd237 lisp/files.el --- a/lisp/files.el Mon Oct 22 14:53:30 2001 +0000 +++ b/lisp/files.el Mon Oct 22 16:11:12 2001 +0000 @@ -2238,11 +2238,13 @@ (defun file-name-sans-extension (filename) "Return FILENAME sans final \"extension\". -The extension, in a file name, is the part that follows the last `.'." +The extension, in a file name, is the part that follows the last `.', +except that a leading `.', if any, doesn't count." (save-match-data (let ((file (file-name-sans-versions (file-name-nondirectory filename))) directory) - (if (string-match "\\.[^.]*\\'" file) + (if (and (string-match "\\.[^.]*\\'" file) + (not (eq 0 (match-beginning 0)))) (if (setq directory (file-name-directory filename)) (expand-file-name (substring file 0 (match-beginning 0)) directory) @@ -2251,7 +2253,8 @@ (defun file-name-extension (filename &optional period) "Return FILENAME's final \"extension\". -The extension, in a file name, is the part that follows the last `.'. +The extension, in a file name, is the part that follows the last `.', +except that a leading `.', if any, doesn't count. Return nil for extensionless file names such as `foo'. Return the empty string for file names such as `foo.'. @@ -2260,7 +2263,8 @@ the value is \"\"." (save-match-data (let ((file (file-name-sans-versions (file-name-nondirectory filename)))) - (if (string-match "\\.[^.]*\\'" file) + (if (and (string-match "\\.[^.]*\\'" file) + (not (eq 0 (match-beginning 0)))) (substring file (+ (match-beginning 0) (if period 0 1))) (if period "")))))