1

I know this may sound silly but what does defvar do in the code below? Does it define a variable that hold a capture template? or we say that the template is bound to the variable capture-template-contact?

I tried C-h f defvar for help but still don't get it being a non-native speaker of English.

   (defvar my/capture-template-contact
      (concat "* %^{Name}\n"
              ":PROPERTIES:\n"
              ":Created: %U\n"
              ":Birthday: yyyy-mm-dd\n"
              ":Email:\n"
              ":Mobile:\n"
              ":Skype:\n"
              ":Address:\n"
              ":City:\n"
              ":State:\n"
              ":Country:\n"
              ":PostalCode:\n"
              ":Website:\n"
              ":Note:\n"
              ":END:\n") "Contact")
Drew
  • 75,699
  • 9
  • 109
  • 225
Zoli
  • 381
  • 1
  • 7

1 Answers1

1
  1. defvar declares a global variable, more precisely, a variable that is dynamically bound. And it can define that variable, that is, give it an initial value.

  2. If only one value (the variable symbol) is passed to defvar then it does not give the variable a value; it just declares it.

  3. defvar does nothing if the variable it defines already has a value.

Does it define a variable that hold a capture template? or we say that the template is bound to the variable capture-template-contact?

It defines a variable my/capture-template-contact if that's not already defined. It gives it the string value that's the result of that (concat ...) expression. It gives the variable the doc string "Contact". That's all it does. As for your second question, the defvar doesn't answer that question - it says nothing about what the variable it defines means, or how it might be used in some code somewhere. And the variable name is my/capture-template-contact, not capture-template-contact.

The Elisp manual, node Defining Variables, tells you what you need to know about defvar.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Thank you. I moved all my capture templates in such variables. If you were to write a git log message how would you caption such a change? `Use variables for each capture template` or `Define variables to hold capture templates`? – Zoli Feb 19 '23 at 17:20
  • That's up to you; I have no advice about that. I'd imagine that you're the one who most needs to understand what your message means. – Drew Feb 19 '23 at 19:41
  • Why have you chosen not to customize `org-capture-templates`? – Phil Hudson Feb 21 '23 at 22:31