26.9.7 标准文件名

有时,Emacs Lisp 程序需要为特定用途指定一个标准文件名——通常用于存放当前用户的配置数据。这类文件一般应放在 user-emacs-directory 指定的目录下,默认通常为 ~/.config/emacs/~/.emacs.d/(see How Emacs Finds Your Init File in The GNU Emacs Manual)。例如,缩写定义默认保存在 ~/.config/emacs/abbrev_defs~/.emacs.d/abbrev_defs。指定这类文件名最简单的方式是使用函数 locate-user-emacs-file

Function: locate-user-emacs-file base-name &optional old-name

该函数返回一个 Emacs 专用配置或数据文件的绝对文件名。参数 base-name 应为相对文件名。返回值是 user-emacs-directory 目录下对应文件的绝对路径;如果该目录不存在,函数会创建它。

如果可选参数 old-namenil,它指定用户主目录下的文件 ~/old-name。如果该文件存在,则返回该文件的绝对路径,而非 base-name 指定的文件。该参数用于 Emacs 包提供向后兼容。例如,在引入 user-emacs-directory 之前,缩写文件位于 ~/.abbrev_defs。下面是 abbrev-file-name 的定义:

(defcustom abbrev-file-name
  (locate-user-emacs-file "abbrev_defs" ".abbrev_defs")
  "Default name of file from which to read abbrevs."
  ...
  :type 'file)

一个用于标准化文件名的更低层函数是 convert-standard-filename,它被 locate-user-emacs-file 作为子程序使用。

Function: convert-standard-filename filename

该函数基于 filename 返回一个符合当前操作系统规范的文件名。

在 GNU 及类 POSIX 系统上,它直接返回 filename。在其他操作系统上,它会强制执行系统特定的文件名规范;例如在 MS-DOS 上,该函数会做一系列修改以满足 8.3 格式限制,包括将开头的 ‘.’ 转为 ‘_’,并将点号后的字符截断为 3 个。

推荐用法是:先指定一个符合 GNU/Unix 规范的名称,再传入 convert-standard-filename


emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike