Drupal, Emacs, and templates: Module update functions

Drupal’s coding conventions make it easier to hook into system behavior, but they also result in a lot of repetitive typing. For example, you can run code when upgrading a module by putting the code in a function named modulename_update_N() in your module’s install file. I found myself scrolling up and copy-pasting stuff too many times, so I decided to automate it instead.

I’ve been using yasnippet for my Emacs templates. All I needed to do to automate that little update bit was to write some code that figured out what the next update number should be. Here’s the snippet file I’ve just added (~/elisp/snippets/php-mode/drupal-mode/_update):

function `(sacha/drupal-module-name)`_update_`(sacha/drupal-module-update-number)`() {
  $ret = array();
  $0
  $ret[] = array(
    'success' => true,
    'query' => '$1',
  );
  return $ret;
}

The relevant functions from my ~/.emacs:

(defun sacha/drupal-module-update-number ()
  "Return the number of the next module update function.
This is one more than the highest number used so far.
This function should be called in a module's .install file."
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (let ((module-name (sacha/drupal-module-name))
	    (max 0))
	(while (re-search-forward
		(concat "function[ \t\n]+" module-name "_update_\\([0-9]+\\)") nil t)
	  (setq max (max (string-to-number (match-string 1)) max)))
	(number-to-string (1+ max))))))

(defun sacha/drupal-module-name ()
  "Return the Drupal module name for .module and .install files."
  (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))

I can’t think of how I’d do that in Eclipse. =) Don’t get me wrong–I still like Eclipse–but I heart being able to hack my editor on the fly.

Tweaking my scheduling process for delegation

Scheduling stresses me out. I’ve had several calendar hiccups before: wrong dates, ambiguous locations, no contact information (or incorrect ones!), and so on. I want to fix that so that I can get better at meeting people and following up.

What would success look like? I think it would be awesome to get to the point where I can easily set lunches, coffees, and calls with people. This is how that process might look like:

  1. I bump into people in person or get an email from them. If I meet them in person, I scan in or take a picture of their business card and add it to my file.
  2. I introduce my assistant through e-mail and ask him/her to schedule lunch/coffee/a call. I use an e-mail template on my computer or a snippet on my phone to make sure that I include all the information necessary. My assistant also refers to a note with my preferences and processes.
  3. My assistant contacts the person and negotiates schedule / location using http://scheduleonce.com or manual scheduling through e-mail, following up in case people don’t respond. If possible, we’ll suggest a venue with good WiFi near the person’s office or location. He or she would create a calendar entry for the meeting as well as travel/preparation time around it.
  4. We have a task board where I could see where people are in the process, so I can be sure that nothing slips through the cracks. My assistant updates it, and we review it periodically.

It’s important to me that the process doesn’t make people feel like I’m standoffish or self-important. I also want to make sure that we don’t drop the ball even if I change assistants or take tasks back, so I want to use something like Trello to track scheduling status.

Here are some templates that I’m thinking of using:

Sample e-mail introducing the assistant and asking her to set things up

Hello, John!

I’d love to meet with you for lunch to discuss sketchnoting – my treat. Criselda (cc’d here) will be helping us set up something that works with your schedule. Criselda: Could you please organize lunch for maybe the second week of December? Thank you!

Sacha Chua

Sample e-mail from assistant

Hello, John!

I’m Criselda, and I’m looking forward to helping you and Sacha get together for a great conversation about sketchnotes. For lunch, would either Dec 10 (Mon), Dec 11 (Tue), or Dec 13 (Thu) work for you? 12pm usually works, but she’s happy to meet earlier or later if needed. Alternatively, if none of those dates work for you, you can check her availability at http://meetme.so/sachac or send me a few dates and times that fit your schedule.

Also, where will you be at that time? If you’ll be near your office at 123 Anywhere Street, I can find a restaurant nearby. If you’ll be elsewhere, tell me and I’ll look for somewhere close – anywhere near the subway line would be fantastic. Got a favourite? We’d love to find out about it!

What phone number would be the best to reach you at in case something comes up?

Best regards,
Criselda Hernandez

Sample calendar entry

Subject: Lunch: John / Sacha – sketchnotes
Attendees: [email protected]
Location: Restaurant Name (123 Restaurant Address St., Toronto)
Sacha’s phone: 416-823-2669
Your phone: 123-456-7890
Restaurant website: http://www.example.com
On Yelp: http://www.example.com
To reschedule, please contact Criselda at ______ . Need to reschedule on the day of the event? Please call Sacha.

<agenda / notes from e-mail>

Sample confirmation

Hello, John!

This is Criselda again. I’ve set up the calendar invitation for your meeting with Sacha for 12pm on Dec 13 at Restaurant Name. Please tell me if you’re having problems adding it to your calendar. If you need to reschedule, please feel free to get in touch with me. You can check http://meetme.so/sachac for Sacha’s updated availability. If you’re rescheduling on the same day, please call Sacha at 416-823-2669. Thank you, and I hope you have a great conversation!

Criselda Hernandez

What do you think? If I used a process like this to schedule something with you, would you feel weird about it? What would make it better? Have you delegated or are you in the process of figuring out how to delegate! I’d love to talk to you!