简体   繁体   English

如何确定Emacs缓冲区文件名的基本名称?

[英]How to determine base name of Emacs buffer file name?

Assume I edit in Emacs a file t.txt in my home directory. 假设我在Emacs中的主目录中编辑文件t.txt Then ESC-: buffer-file-name produces /Home/fcihh/t.txt How can I extract the file name part t.txt from that? 然后ESC-: buffer-file-name生成/Home/fcihh/t.txt如何从中提取文件名部分t.txt

According to this link I thought I should be able to write ESC-: (file-name-base buffer-file-name) . 根据此链接,我认为我应该能够编写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. 我在Ubuntu 12.04上使用GNU Emacs 23.3.1。

Unfortunately file-name-base has been introduced in Emacs 24. Here is its definition, from lisp/files.el : 不幸的是,Emacs 24中引入了file-name-base这是它的定义,来自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. file-name-sans-extensionfile-name-nondirectory都应在Emacs 23中可用。

If you want the base name with extension you only need file-name-nondirectory . 如果您想要带有扩展名的基本名称,则只需要file-name-nondirectory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM