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?
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.
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
C++ has a built-in method to concatenate strings. The strcat() method is used to concatenate strings in C++. The strcat() function takes char array as input and then concatenates the input values passed to the function.
The same + operator you use for adding two numbers can be used to concatenate two strings. You can also use += , where a += b is a shorthand for a = a + b .
You can use (concat "foo" "bar")
rather than (concatenate 'string "foo" "bar")
. Both work, but of course the former is shorter.
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")))
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