Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate strings in elisp

Tags:

emacs

elisp

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.

like image 526
prosseek Avatar asked Sep 16 '10 20:09

prosseek


People also ask

How do you concatenate strings together?

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.

Can we concatenate strings in C++?

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.

Can you use += for string concatenation?

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 .


2 Answers

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

like image 198
offby1 Avatar answered Nov 07 '22 09:11

offby1


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"))) 
like image 24
Jürgen Hötzel Avatar answered Nov 07 '22 10:11

Jürgen Hötzel