56

I need to concatenate path string as follows, so I added the following lines to my .emacs file:

(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"))

When I do C-h v today-file-path RET to check, it has no variable assigned.

What's wrong with my code? Is there any other way to concatenate the path string?

EDIT

I found that the problem was caused by the wrong setup, the code actually works. Thanks for the answers which are better than my code.

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
prosseek
  • 182,215
  • 215
  • 566
  • 871

3 Answers3

81

You can use (concat "foo" "bar") rather than (concatenate 'string "foo" "bar"). Both work, but of course the former is shorter.

offby1
  • 6,767
  • 30
  • 45
30

Use expand-file-name to build filenames relative to a directory:

(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")))
Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58
28

First of all, don't use "_"; use '-' instead. Insert this into your .emacs and restart emacs (or evaluate the S-exp in a buffer) to see the effects:

(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"))
OTZ
  • 3,003
  • 4
  • 29
  • 41