我需要连接路径字符串,如下所示,所以我将以下行添加到我的.emacs文件中:
(setq org_base_path "~/smcho/time/")
(setq org-default-notes-file-path (concatenate 'string org_base_path "notes.org"))
(setq todo-file-path (concatenate 'string org_base_path "gtd.org"))
(setq journal-file-path (concatenate 'string org_base_path "journal.org"))
(setq today-file-path (concatenate 'string org_base_path "2010.org"))
Run Code Online (Sandbox Code Playgroud)
当我做C-h v today-file-path RET检查时,它没有分配变量.
我的代码出了什么问题?有没有其他方法来连接路径字符串?
我发现问题是由错误的设置引起的,代码实际上是有效的.感谢您的答案比我的代码更好.
off*_*by1 62
你可以使用(concat "foo" "bar")而不是(concatenate 'string "foo" "bar").两者都有效,但当然前者更短.
OTZ*_*OTZ 25
首先,不要使用"_"; 用' - '代替.将其插入.emacs并重新启动emacs(或在缓冲区中评估S-exp)以查看效果:
(setq org-base-path (expand-file-name "~/smcho/time"))
(setq org-default-notes-file-path (format "%s/%s" org-base-path "notes.org")
todo-file-path (format "%s/%s" org-base-path "gtd.org")
journal-file-path (format "%s/%s" org-base-path "journal.org")
today-file-path (format "%s/%s" org-base-path "2010.org"))
Run Code Online (Sandbox Code Playgroud)
Jür*_*zel 23
使用expand-file-name构建相对于目录的文件名:
(let ((default-directory "~/smcho/time/"))
(setq org-default-notes-file-path (expand-file-name "notes.org"))
(setq todo-file-path (expand-file-name "gtd.org"))
(setq journal-file-path (expand-file-name "journal.org"))
(setq today-file-path (expand-file-name "2010.org")))
Run Code Online (Sandbox Code Playgroud)