Assume I edit in Emacs a file t.txt in my home directory. Then
ESC-: buffer-file-name produces /Home/fcihh/t.txt How can I extract the file name part t.txt from that?
According to this link I thought I should be able to write
ESC-: (file-name-base buffer-file-name). But this produces the error
Lisp error: (void-function file-name-base)
I am using GNU Emacs 23.3.1 on Ubuntu 12.04.
Unfortunately file-name-base has been introduced in Emacs 24. Here is its definition, from lisp/files.el:
(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)))))
Both file-name-sans-extension and file-name-nondirectory should be available in Emacs 23.
If you want the base name with extension you only need file-name-nondirectory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With