]> code.delx.au - gnu-emacs/commitdiff
* lisp/files.el (file-name-base): New convenience function.
authorSam Steingold <sds@gnu.org>
Tue, 26 Jun 2012 16:23:01 +0000 (12:23 -0400)
committerSam Steingold <sds@gnu.org>
Tue, 26 Jun 2012 16:23:01 +0000 (12:23 -0400)
* 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.

18 files changed:
doc/lispref/files.texi
lisp/ChangeLog
lisp/autoinsert.el
lisp/cus-dep.el
lisp/doc-view.el
lisp/eshell/esh-cmd.el
lisp/files.el
lisp/image-dired.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
lisp/woman.el

index 618569c3559957d5cc353b3b66f98154bf4e966f..56971bf0ff0c8be265c583fae5163ff57c7654cd 100644 (file)
@@ -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
index ac24259869a414f769b7d73e89c2ba833f4863d6..701dae6c4ef424954bdfacdea6d40dba7c9ce5b9 100644 (file)
@@ -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
index e7639b6f8a35f83057400f90777cae3a9a52a30d..fbf8c466585ea38faf515e8af0291b6c0f6f0d4d 100644 (file)
@@ -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"
index 23f3eac5d6677cbfac76cc696ce0a8c64cb2f94f..cd946bdc99b58692d4261a241590bd08e1b634ee 100644 (file)
@@ -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)
index 78b6610ff3cbba08f3460e864704f188d3137864..f526825b0bd60adc9bd4ecb2c43b4c9b6cecbb48 100644 (file)
@@ -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))
index 850cecbc0a500e9f7795878c4d5d2e367bdee98f..872d1cdd53e1612dcee0735c941856d10ea1dd83 100644 (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
-                       (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)
index e19d1d2f16e95ddcae1e7a87cb428ff923e15187..2b5717a719cd79063e3a98c88162fb069c36c522 100644 (file)
@@ -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.
index 8151985e7477176031fab82a0c79ce2f229e6a04..9fc0a2cb51a3574402a4db4c61fb779585a6feba 100644 (file)
@@ -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)
index 146cc703e1a78a69bea14165f1b4f90d32af0f41..1bee783bb17e4cccb73fb240f39fef979ca6a077 100644 (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))
-                  ".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))
index 5d758b53b569af73eca95c64c339590b705f8a76..8bccb44f308d131ed6a91784b19b881bd8613fc0 100644 (file)
@@ -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
index 9ea42db2a8c34314a217119a7d3e86a430c5db84..e95b6fa288d3038c3cd7db352126943af642f35f 100644 (file)
@@ -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"
index 654fd3dba8d48807d8d4df57e07ccbd957e32658..a410f45eeb4b85ea5f91ad3caa5def44cb780f88 100644 (file)
@@ -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
index 7123a8dd7fccc7c58131e9a7f16a94edd186f9af..0b67bbed7ea9558d454ef1a35ac56f880f587416 100644 (file)
@@ -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)
index 015f58df3fb1e2a65c0ac9875b000334a9b49239..a35ffd3e45d43a0a901173124204979a792fc6c8 100644 (file)
@@ -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))))
index fc2155893a9bc5adcf435d1b9d145cc4b5235dbc..0c7966f22d3f10aa04d78ca729a62720b21d7e37 100644 (file)
@@ -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)))
index 03690f65281b2fa1ab607acfd1507f8574f28bd6..1882e7dde5636282ad4e42b85b29bc2de6d25bd7 100644 (file)
@@ -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))
index a9a2113e7fc4e3de53d8c2671774859ba33a5598..43005a034150f87f7994dcaf63c1863512da0b66 100644 (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-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
index 3ab06a5dd73e4746431b8fdc7c1f8245e797966f..e220cd8062cd272d959bf7e77b0190578cf78ebf 100644 (file)
@@ -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))