1

I'm trying to configure my org based init file to work on 2 different machines where some of my org file would be accessed remotely. For example I want to define within the same config different org capture based on which machine I'm currently on (hostname).

I have this initial code:

(when (string= system-name "home")

(add-to-list 'org-capture-templates
'("z" "web capture " item
         (file+headline "/home/zeltak/org/files/web/wbookmarks.org" "Temporary Links")
         "%?\nEntered on %U\n \%i\n %a"))
)


(when (string= system-name "work")

(add-to-list 'org-capture-templates
'("z" "web capture " item
         (file+headline "/sshx:work:~/org/files/wbookmarks.org" "Temporary Links")
         "%?\nEntered on %U\n \%i\n %a"))
)

I have 30 captures like this where I have to reproduce for both machines. I am sure there is a more intelligent way to do this and am looking for suggestions. Perhaps define a Path variable that changes based on machine?

  • Please do not sign off posts with "best", "thanks", etc. – Dan Feb 20 '17 at 14:49
1

I think your idea is fine:

(if (string= system-name "home")
    (setq my-org-path "/home/zeltak/org/files/")
  (setq my-org-path "/sshx:work:~/org/files/"))

(add-to-list 'org-capture-templates
             '("z" "web capture " item
               (file+headline (expand-file-name "web/wbookmarks.org" my-org-path) "Temporary Links")
               "%?\nEntered on %U\n \%i\n %a"))

If you're only going to use my-org-path in the context of setting the org-capture-templates list, you could isolate it in a let form:

(let ((my-org-path 
       (if (string= system-name "home")
           "/home/zeltak/org/files/"
         "/sshx:work:~/org/files/")))

  (add-to-list 'org-capture-templates
               '("z" "web capture " item
                 (file+headline (expand-file-name "web/wbookmarks.org" my-org-path) "Temporary Links")
                 "%?\nEntered on %U\n \%i\n %a")))

This has the advantage of not polluting your global name space with my-org-path if you're not going to use it after loading your config. Probably not a big deal either way.

  • Don't forget to quasiquote in the template within add-to-list. – Dan Feb 20 '17 at 14:27
  • great works really well.thx! – zeltak Feb 20 '17 at 14:39
  • @Dan good point, but not necessary in this case I think. The filename for a template target (i.e., (concat my-org-path ...)) may be an elisp form (see the help for org-capture-templates), so presumably orgmode knows how to accommodate this behind the scenes. It must be, if the code as written is working for zeltak. – Tyler Feb 20 '17 at 14:50
  • 2
    I would recommend (expand-file-name "web/wbookmarks.org" my-org-path) instead of using concat, since expand-file-name is tailored towards paths. – Erik Sjöstrand Feb 20 '17 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.