summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/files.texi11
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/autoinsert.el11
-rw-r--r--lisp/cus-dep.el4
-rw-r--r--lisp/doc-view.el3
-rw-r--r--lisp/eshell/esh-cmd.el4
-rw-r--r--lisp/files.el6
-rw-r--r--lisp/image-dired.el4
-rw-r--r--lisp/progmodes/ada-xref.el16
-rw-r--r--lisp/progmodes/cc-defs.el4
-rw-r--r--lisp/progmodes/cperl-mode.el3
-rw-r--r--lisp/progmodes/flymake.el2
-rw-r--r--lisp/progmodes/gud.el7
-rw-r--r--lisp/progmodes/idlwave.el4
-rw-r--r--lisp/textmodes/ispell.el3
-rw-r--r--lisp/textmodes/reftex-ref.el6
-rw-r--r--lisp/textmodes/tex-mode.el3
-rw-r--r--lisp/woman.el3
18 files changed, 54 insertions, 51 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 618569c3559..56971bf0ff0 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -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,
+
+@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
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ac24259869a..701dae6c4ef 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
+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
diff --git a/lisp/autoinsert.el b/lisp/autoinsert.el
index e7639b6f8a3..fbf8c466585 100644
--- a/lisp/autoinsert.el
+++ b/lisp/autoinsert.el
@@ -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)))
+ (file-name-base)
" \\- " str
"\n.SH SYNOPSIS
-.B " (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
+.B " (file-name-base)
"\n"
_
"
@@ -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-base)
")
\;;; " (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-sans-extension
- (file-name-nondirectory (buffer-file-name))) ".info\n"
+ (file-name-base) ".info\n"
"@settitle " str "
@c %**end of header
@copying\n"
diff --git a/lisp/cus-dep.el b/lisp/cus-dep.el
index 23f3eac5d66..cd946bdc99b 100644
--- a/lisp/cus-dep.el
+++ b/lisp/cus-dep.el
@@ -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-sans-extension
- (file-name-nondirectory f)))
+ 'file-name-base
preloaded-file-list) t)
"\\.el\\'")))
(dolist (file files)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 78b6610ff3c..f526825b0bd 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -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)
".pdf")
doc-view-current-cache-dir))
(png-file png-file))
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 850cecbc0a5..872d1cdd53e 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -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
- (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)
diff --git a/lisp/files.el b/lisp/files.el
index e19d1d2f16e..2b5717a719c 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -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-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.
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 8151985e747..9fc0a2cb51a 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -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)
diff --git a/lisp/progmodes/ada-xref.el b/lisp/progmodes/ada-xref.el
index 146cc703e1a..1bee783bb17 100644
--- a/lisp/progmodes/ada-xref.el
+++ b/lisp/progmodes/ada-xref.el
@@ -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))
- ".ali"))
+ (let ((short-ali-file-name (concat (file-name-base file) ".ali"))
ali-file-name
is-spec)
@@ -1566,10 +1564,7 @@ the project file."
(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
@@ -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
(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))
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 5d758b53b56..8bccb44f308 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -1818,9 +1818,7 @@ system."
(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
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 9ea42db2a8c..e95b6fa288d 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -2322,8 +2322,7 @@ to nil."
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"
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 654fd3dba8d..a410f45eeb4 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -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
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 7123a8dd7fc..0b67bbed7ea 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -2763,10 +2763,9 @@ Obeying it means displaying in another window the specified file and line."
(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)
diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el
index 015f58df3fb..a35ffd3e45d 100644
--- a/lisp/progmodes/idlwave.el
+++ b/lisp/progmodes/idlwave.el
@@ -5235,9 +5235,7 @@ Can run from `after-save-hook'."
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))))
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index fc2155893a9..0c7966f22d3 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -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)))
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 03690f65281..1882e7dde56 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -313,8 +313,7 @@ also applies `reftex-translate-to-ascii-function' to the string."
(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))))
@@ -323,8 +322,7 @@ also applies `reftex-translate-to-ascii-function' to the string."
(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))
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index a9a2113e7fc..43005a03415 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -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-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
diff --git a/lisp/woman.el b/lisp/woman.el
index 3ab06a5dd73..e220cd8062c 100644
--- a/lisp/woman.el
+++ b/lisp/woman.el
@@ -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
(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))