not an extension.
@end defun
+@defun file-name-base &optional filename
+This function is the composition of @code{file-name-sans-extension}
+and @code{file-name-nondirectory}. For example,
+
+@example
+(file-name-base "/my/home/foo.c")
+ @result{} "foo"
+@end example
+
+The @var{filename} argument defaults to @code{buffer-file-name}.
+@end defun
@node Relative File Names
@subsection Absolute and Relative File Names
+2012-06-26 Sam Steingold <sds@gnu.org>
+
+ * files.el (file-name-base): New convenience function.
+ * autoinsert.el, cus-dep.el, doc-view.el, image-dired.el,
+ * woman.el, eshell/esh-cmd.el, progmodes/ada-xref.el,
+ * progmodes/cc-defs.el, progmodes/cperl-mode.el,
+ * progmodes/flymake.el, progmodes/gud.el, progmodes/idlwave.el,
+ * textmodes/ispell.el, textmodes/reftex-ref.el,
+ * textmodes/tex-mode.el: Use it.
+ Did not touch cedet and org because they are maintained elsewhere.
+
2012-06-26 Martin Rudalics <rudalics@gmx.at>
* calendar/calendar.el (calendar-exit): Don't try to delete or
"
.\\\" You may distribute this file under the terms of the GNU Free
.\\\" Documentation License.
-.TH " (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
+.TH " (file-name-base)
" " (file-name-extension (buffer-file-name))
" " (format-time-string "%Y-%m-%d ")
"\n.SH NAME\n"
- (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
+ (file-name-base)
" \\- " str
"\n.SH SYNOPSIS
-.B " (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
+.B " (file-name-base)
"\n"
_
"
\(provide '"
- (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
+ (file-name-base)
")
\;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")
(("\\.texi\\(nfo\\)?\\'" . "Texinfo file skeleton")
"\\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename "
- (file-name-sans-extension
- (file-name-nondirectory (buffer-file-name))) ".info\n"
+ (file-name-base) ".info\n"
"@settitle " str "
@c %**end of header
@copying\n"
(default-directory (expand-file-name subdir))
(preloaded (concat "\\`"
(regexp-opt (mapcar
- (lambda (f)
- (file-name-sans-extension
- (file-name-nondirectory f)))
+ 'file-name-base
preloaded-file-list) t)
"\\.el\\'")))
(dolist (file files)
;; ODF files have to be converted to PDF before Ghostscript can
;; process it.
(let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))
- (opdf (expand-file-name (concat (file-name-sans-extension
- (file-name-nondirectory doc-view-buffer-file-name))
+ (opdf (expand-file-name (concat (file-name-base doc-view-buffer-file-name)
".pdf")
doc-view-current-cache-dir))
(png-file png-file))
(if (and file
(string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file))
(let ((module-sym
- (intern (file-name-sans-extension
- (file-name-nondirectory
- (concat "eshell-" (match-string 2 file)))))))
+ (intern (file-name-base (concat "eshell-" (match-string 2 file))))))
(if (and (functionp sym)
(or (null module-sym)
(eshell-using-module module-sym)
(if period
"")))))
+(defun file-name-base (&optional filename)
+ "Return the base name of the FILENAME: no directory, no extension.
+FILENAME defaults to `buffer-file-name'."
+ (file-name-sans-extension
+ (file-name-nondirectory (or filename (buffer-file-name)))))
+
(defcustom make-backup-file-name-function nil
"A function to use instead of the default `make-backup-file-name'.
A value of nil gives the default `make-backup-file-name' behavior.
(md5 (file-name-as-directory (file-name-directory f)))))
(format "%s%s%s.thumb.%s"
(file-name-as-directory (expand-file-name (image-dired-dir)))
- (file-name-sans-extension (file-name-nondirectory f))
+ (file-name-base f)
(if md5-hash (concat "_" md5-hash) "")
(file-name-extension f))))
((eq 'per-directory image-dired-thumbnail-storage)
(let ((f (expand-file-name file)))
(format "%s.image-dired/%s.thumb.%s"
(file-name-directory f)
- (file-name-sans-extension (file-name-nondirectory f))
+ (file-name-base f)
(file-name-extension f))))))
(defun image-dired-create-thumb (original-file thumbnail-file)
;; also a separate.
(with-current-buffer (get-file-buffer file)
- (let ((short-ali-file-name
- (concat (file-name-sans-extension (file-name-nondirectory file))
- ".ali"))
+ (let ((short-ali-file-name (concat (file-name-base file) ".ali"))
ali-file-name
is-spec)
(if is-spec
(set 'ali-file-name
(ada-find-ali-file-in-dir
- (concat (file-name-sans-extension
- (file-name-nondirectory
- (ada-other-file-name)))
- ".ali"))))
+ (concat (file-name-base (ada-other-file-name)) ".ali"))))
(setq ali-file-name
;; file_s.ada and file_b.ada), try to go to the other file
;; and look for its ali file
(ada-find-ali-file-in-dir
- (concat (file-name-sans-extension
- (file-name-nondirectory (ada-other-file-name)))
- ".ali"))
+ (concat (file-name-base (ada-other-file-name)) ".ali"))
;; If we still don't have an ali file, try to get the one
;; from the parent unit, in case we have a separate entity.
- (let ((parent-name (file-name-sans-extension
- (file-name-nondirectory file))))
+ (let ((parent-name (file-name-base file)))
(while (and (not ali-file-name)
(string-match "^\\(.*\\)[.-][^.-]*" parent-name))
(t
;; Being evaluated interactively.
(buffer-file-name)))))
- (and file
- (file-name-sans-extension
- (file-name-nondirectory file)))))
+ (and file (file-name-base file))))
(defmacro c-lang-defconst-eval-immediately (form)
"Can be used inside a VAL in `c-lang-defconst' to evaluate FORM
nil t)))) ; Only one
(progn
(forward-word 1)
- (setq name (file-name-sans-extension
- (file-name-nondirectory (buffer-file-name)))
+ (setq name (file-name-base)
p (point))
(insert " NAME\n\n" name
" - \n\n=head1 SYNOPSIS\n\n\n\n"
This function is used in sort to move most possible file names
to the beginning of the list (File.h -> File.cpp moved to top)."
(and (equal (file-name-sans-extension flymake-included-file-name)
- (file-name-sans-extension (file-name-nondirectory file-one)))
+ (file-name-base file-one))
(not (equal file-one file-two))))
(defcustom flymake-check-file-limit 8192
(buffer-file-name)
(car frame)))))
((eq key ?F)
- (setq subst (file-name-sans-extension
- (file-name-nondirectory (if insource
- (buffer-file-name)
- (car frame))))))
+ (setq subst (file-name-base (if insource
+ (buffer-file-name)
+ (car frame)))))
((eq key ?d)
(setq subst (file-name-directory (if insource
(buffer-file-name)
class
(cond ((not (boundp 'idlwave-scanning-lib))
(list 'buffer (buffer-file-name)))
-; ((string= (downcase
-; (file-name-sans-extension
-; (file-name-nondirectory (buffer-file-name))))
+; ((string= (downcase (file-name-base))
; (downcase name))
; (list 'lib))
; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
(insert-file-contents alias-file)
;; Look for a line "add FOO.multi", extract FOO
(when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t)
- (let* ((aliasname (file-name-sans-extension
- (file-name-nondirectory alias-file)))
+ (let* ((aliasname (file-name-base alias-file))
(already-exists-p (assoc aliasname alist))
(realname (match-string 1))
(realdict (assoc realname alist)))
(save-match-data
(cond
((equal letter "f")
- (file-name-sans-extension
- (file-name-nondirectory (buffer-file-name))))
+ (file-name-base))
((equal letter "F")
(let ((masterdir (file-name-directory (reftex-TeX-master-file)))
(file (file-name-sans-extension (buffer-file-name))))
(substring file (length masterdir))
file)))
((equal letter "m")
- (file-name-sans-extension
- (file-name-nondirectory (reftex-TeX-master-file))))
+ (file-name-base (reftex-TeX-master-file)))
((equal letter "M")
(file-name-nondirectory
(substring (file-name-directory (reftex-TeX-master-file))
(let* ((dir (file-name-directory tex-last-temp-file))
(list (and (file-directory-p dir)
(file-name-all-completions
- (file-name-sans-extension
- (file-name-nondirectory tex-last-temp-file))
+ (file-name-base tex-last-temp-file)
dir))))
(while list
(if not-all
;; then use the WoMan search mechanism to find the filename ...
(setq filename
(woman-file-name
- (file-name-sans-extension
- (file-name-nondirectory name))))
+ (file-name-base name)))
;; Cannot find the file, so ...
(kill-buffer (current-buffer))
(error "File `%s' not found" name))