Commit d2c32364 authored by Sam Steingold's avatar Sam Steingold
Browse files

* lisp/files.el (file-name-base): New convenience function.

* lisp/autoinsert.el, lisp/cus-dep.el, lisp/doc-view.el, lisp/image-dired.el,
* lisp/woman.el, lisp/eshell/esh-cmd.el, lisp/progmodes/ada-xref.el,
* lisp/progmodes/cc-defs.el, lisp/progmodes/cperl-mode.el,
* lisp/progmodes/flymake.el, lisp/progmodes/gud.el, lisp/progmodes/idlwave.el,
* lisp/textmodes/ispell.el, lisp/textmodes/reftex-ref.el,
* lisp/textmodes/tex-mode.el: Use it.
Did not touch cedet and org because they are maintained elsewhere.
parent 62efea5e
......@@ -1846,6 +1846,17 @@ Note that the @samp{.~3~} in the two last examples is the backup part,
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,
(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 <>
* 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 <>
* calendar/calendar.el (calendar-exit): Don't try to delete or
......@@ -140,14 +140,14 @@ If this contains a %s, that will be replaced by the matching rule."
.\\\" 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)))
" \\- " str
.B " (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
.B " (file-name-base)
......@@ -207,7 +207,7 @@ If this contains a %s, that will be replaced by the matching rule."
\(provide '"
(file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
\;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")
(("\\.texi\\(nfo\\)?\\'" . "Texinfo file skeleton")
......@@ -215,8 +215,7 @@ If this contains a %s, that will be replaced by the matching rule."
"\\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename "
(file-name-nondirectory (buffer-file-name))) ".info\n"
(file-name-base) ".info\n"
"@settitle " str "
@c %**end of header
......@@ -53,9 +53,7 @@ Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
(default-directory (expand-file-name subdir))
(preloaded (concat "\\`"
(regexp-opt (mapcar
(lambda (f)
(file-name-nondirectory f)))
preloaded-file-list) t)
(dolist (file files)
......@@ -961,8 +961,7 @@ Those files are saved in the directory given by the function
;; 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)
(png-file png-file))
......@@ -1220,9 +1220,7 @@ COMMAND may result in an alias being executed, or a plain command."
(if (and file
(string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file))
(let ((module-sym
(intern (file-name-sans-extension
(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)
......@@ -4083,6 +4083,12 @@ the value is \"\"."
(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-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.
......@@ -602,14 +602,14 @@ according to the Thumbnail Managing Standard."
(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)
......@@ -1544,9 +1544,7 @@ the project 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))
(let ((short-ali-file-name (concat (file-name-base file) ".ali"))
......@@ -1566,10 +1564,7 @@ the project file."
(if is-spec
(set 'ali-file-name
(concat (file-name-sans-extension
(concat (file-name-base (ada-other-file-name)) ".ali"))))
(setq ali-file-name
......@@ -1584,15 +1579,12 @@ the project file."
;; file_s.ada and file_b.ada), try to go to the other file
;; and look for its ali file
(concat (file-name-sans-extension
(file-name-nondirectory (ada-other-file-name)))
(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))
......@@ -1818,9 +1818,7 @@ system."
;; Being evaluated interactively.
(and file
(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
......@@ -2322,8 +2322,7 @@ to nil."
nil t)))) ; Only one
(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"
......@@ -408,7 +408,7 @@ File contents are not checked."
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
......@@ -2763,10 +2763,9 @@ Obeying it means displaying in another window the specified file and line."
(car frame)))))
((eq key ?F)
(setq subst (file-name-sans-extension
(file-name-nondirectory (if insource
(car frame))))))
(setq subst (file-name-base (if insource
(car frame)))))
((eq key ?d)
(setq subst (file-name-directory (if insource
......@@ -5235,9 +5235,7 @@ Can run from `after-save-hook'."
(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))))
......@@ -1064,8 +1064,7 @@ Return the new dictionary alist."
(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)))
......@@ -313,8 +313,7 @@ also applies `reftex-translate-to-ascii-function' to the string."
((equal letter "f")
(file-name-nondirectory (buffer-file-name))))
((equal letter "F")
(let ((masterdir (file-name-directory (reftex-TeX-master-file)))
(file (file-name-sans-extension (buffer-file-name))))
......@@ -323,8 +322,7 @@ also applies `reftex-translate-to-ascii-function' to the string."
(substring file (length masterdir))
((equal letter "m")
(file-name-nondirectory (reftex-TeX-master-file))))
(file-name-base (reftex-TeX-master-file)))
((equal letter "M")
(substring (file-name-directory (reftex-TeX-master-file))
......@@ -1984,8 +1984,7 @@ If NOT-ALL is non-nil, save the `.dvi' file."
(let* ((dir (file-name-directory tex-last-temp-file))
(list (and (file-directory-p dir)
(file-name-nondirectory tex-last-temp-file))
(file-name-base tex-last-temp-file)
(while list
(if not-all
......@@ -2679,8 +2679,7 @@ If DELETE is non-nil then delete from point."
;; then use the WoMan search mechanism to find the filename ...
(setq filename
(file-name-nondirectory name))))
(file-name-base name)))
;; Cannot find the file, so ...
(kill-buffer (current-buffer))
(error "File `%s' not found" name))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment