June 2014

Weekly review: Week ending May 30, 2014

June 1, 2014 - Categories: weekly

Lots of gardening this weekend! We picked up more compost, reseeded the lawn, planted more seeds, and covered the blueberries with a net. =)

Blog posts

Sketches

Link round-up

Focus areas and time review

  • Business (28.8h – 17%)
    • ☑ Cancel speaking engagements
    • ☑ Complete 4clojure elementary exercises
    • Earn (13.0h – 44% of Business)
      • ☑ E1 Attend training
      • ☑ E1: Update names
      • ☐ Earn: E1: 2.5-3.5 days of consulting
      • ☐ E1: Do monthly stats
    • Build (6.7h – 23% of Business)
      • Drawing (6.3h)
      • Delegation (0.0h)
      • Packaging (0.0h)
      • Paperwork (0.4h)
    • Connect (9.1h – 31% of Business)
      • ☑ E1: Attend team event
      • ☐ E1: Attend another team event
      • ☐ Have breakfast with Aaron, Jen, and Bernie
      • ☐ Catch up with Jeff Widman
  • Relationships (7.3h – 4%)
    • ☑ Attend Peter’s housewarming party
    • ☑ Call C tomorrow about P
    • ☑ Pick up compost
    • ☑ Make pizza
    • ☑ Plant more seeds
    • ☑ Drop off donations for Free Geek
    • ☐ Work on project F2
    • ☐ Go to Postmodern Jukebox concert
  • Discretionary – Productive (24.0h – 14%)
    • ☑ Go to the dentist
    • Writing (7.9h)
    • Emacs
      • ☑ Host chat with Christopher Wellons
      • ☑ Host chat with Bodil Stokke (oh no! didn’t record!)
      • ☑ Write objectives and practice for section 3, revise section 3
      • ☐ Write objectives and practice for section 4, revise section 4
  • Discretionary – Play (7.1h – 4%)
  • Personal routines (27.7h – 16%)
  • Unpaid work (11.2h – 6%)
  • Sleep (62.5h – 37% – average of 8.9 per day)

What am I learning about and what can I write about more?

June 2, 2014 - Categories: life

I’ve been feeling a little distracted, a little stretched these past weeks. I tell people that if they have a hard time blogging, they can look at what they’re learning and write about that, since they’re probably learning at least one new thing every day. Time to take my own advice. =)

Clojure: I’ve been slowly working through the exercises at 4clojure.com, solving two or three a day (56 done now!). I’m slowly getting the hang of loop, for, partition-by, and all these functions that I’m not used to playing with in Emacs Lisp. My solutions are nowhere near elegant, but they get me to the point of being able to read other people’s solutions. That’s how I’ve been learning about interesting functions. I’m also reading through the Clojure core documentation. Hard to remember everything, but I’m getting better at thinking “Hmm, I remember coming across something that might be useful.”

I’m learning this out of curiosity at the moment, since I haven’t thought of any personal projects that are better suited to Clojure than, say, Rails or Emacs Lisp. Maybe I’ll finally get around to coding that script to check the library for the locations of newly-released DVDs, or building something to help me analyze my Quantified Self data. In order to get to that point, I’ll need to learn core Clojure functions, popular frameworks and libraries, and workflow/debugging tools. It seems a little daunting, but it’s a good kind of daunting. I’m chipping away at it steadily. This also helps me empathize with programming newbies, which is great because I’m working on that course to help people learn Emacs Lisp. =)

Gardening: The sorrel I bought from the farmer’s market turned out to have leaf miners. I’ve been removing the rows of eggs under the leaves by hand, and I cut off a few of the affected leaves and trashed them (far, far away from the garden). It’s a pity about the bugs, but at least I’m learning how to identify and control pests.

The blueberries we planted in 2010 have more flowers than I’d ever seen on them before, and some of those flowers are beginning to set fruit. I cut some twigs off the backyard trees to replace the bamboo hoops that were acting as tomato stakes, and I moved the hoops to the front so that I could drape the net over them. I’m beginning to get the hang of this – no more buying stakes for me!

Some of the bok choy plants are starting to bolt, and the Thai basil is flowering. I pinched the tips, hoping that will extend their growth a little further. I’ve been erring on the side of watering almost every day, since our soil is sandy. The soil often feels dry to a few inches’ depth, even if I’d watered just the day before. We’ve been mixing lots of compost into it and laying even more on top as mulch, but it still has a long way to go.

Emacs: This week I’ll polish the fourth segment in the beginner e-mail course for learning Emacs Lisp. It’s wonderful to have reached this point! I’m glad I started this experiment. Writing tutorials is much easier with other people’s feedback, and e-mail seems to be a less intimidating way for people to interact. I’ll probably roll it out as a blog series as well, so that people can find it while searching my blog. After I finish that, maybe I’ll take a short break before doing the intermediate course. That way, I have some time to experiment with the nifty things I’ve been coming across.

So yeah, I’m learning about stuff. Ah! Maybe it’s because I haven’t been writing in the process of doing so. For Clojure, I can write about my solutions to problems and wha I’m learning by looking at people’s solutions. For gardening, I can post pictures. For Emacs, well, I’m used to writing about that already! =) I think the bottleneck there is that I’ve been working on stuff that’s posted on Github and at http://emacslife.com , but I haven’t been posting those notes (or meta-notes about the process) on my personal blog. Since my personal blog is likely to outlive both of those other resources, I should copy things over anyway. Also, I can give myself permission to spend time exploring Emacs instead of answering mail or working on the course, since it’s fun to write about cool features I’m experimenting with.

If I think of writer’s block as learner’s block, it’s easy to chip away at it. Onward!

Emacs: beginner, intermediate, advanced

June 3, 2014 - Categories: emacs

In a recent Emacs Chat, Bozhidar Batsov mentioned the need for more intermediate to advanced resources, not just tutorials covering the same introductory ground. It got me thinking about different levels of Emacs use, and what kinds of things would help people move upwards.

I think of Emacs beginners as people who are getting the hang of using Emacs. They might even use Emacs regularly. They might have installed and configured a number of packages with lots of help from StackOverflow, coworkers, IRC, and so on. They are not yet comfortable with customization, so they find workflow descriptions and code snippets helpful.

Intermediate users are those who have figured out workflows that fit them well. They may have installed and configured a number of packages. They’re comfortable reading the documentation to figure out how to customize variables, and may even have written a few custom functions and keybindings. They’ve dived into the Emacs Lisp Reference Manual a few times, and know where to go to find examples and common idioms. Some have written tutorials to help beginners get started with useful packages or tips.

Advanced users are those who can imagine a new use for Emacs and make it happen. Here’s where you’ll find people with complex workflows built around combinations of packages, people who write custom modes and other tools, and people for whom hacking Emacs has become a recreational activity. They’re comfortable digging through the source and creating their own versions. They might even package the new code in order to share those features with others. Their code feels like Emacs code, following conventions and idioms.

What have I learned from Emacs Chats about how people move from one stage to the other?

Beginner to intermediate: “Oh, neat, Emacs can do that! I wonder how I can…”

Many people find it inspiring to see how other people have tweaked Emacs. Demos, examples, IRC conversations, and peeking over people’s shoulders are all great ways to find out that Emacs can do more than you think it does, which is an important motivator for moving from the beginner stage to the intermediate stage.

Useful resources could include:

  • Demos of interesting features that require some configuration, with notes on other things you might tweak along the way (exercises for the reader?)
  • Walkthroughs of advanced users’ workflows, since people pick up little tips that advanced users may forget to mention
  • Tips on how to read and modify code

Intermediate to advanced: “I’m in Emacs all the time anyway, so I might as well…”

Going from intermediate to advanced tends to involve a lot of practice in creating little tools, much rereading of the Emacs Lisp Reference and well-written package source code, and participation in the community (through mailing lists, IRC, StackOverflow, Github, etc). It can involve a commitment to use Emacs for way more than you might expect, possibly pushing it to be equivalent or superior to other tools.

People who maintain packages with active communities or who answer questions on mailing lists/newsgroups StackOverflow/Quora/IRC tend to grow a lot, too, since they actively learn from other people’s questions.

Useful resources could include:

  • Practical applications of concepts from the Emacs Lisp Reference
  • Tweaks using internal or obscure code
  • Posts that new features or “What if…” and walk through the code (and possibly the thought process as well)

Emacs is so big, so people probably have different levels of competence for different things. For example, one can be a beginner at Smartparens (memorized the keybindings for some common operations), while being an intermediate/advanced user of completions (have defined a custom completion backend).

What kinds of resources have helped you move from stage to stage? What would you like to see more of?

Monthly review: May 2014

June 4, 2014 - Categories: monthly, review

I wrote that in May, I’d like to:

  • ☑ Learn how to write extensions for E1
  • ☑ Develop “How to Read Emacs Lisp” into a proper course, with objectives, modules, exercises and other useful things
  • ☑ Add compost and herbs to our garden

I hadn’t realized how busy May was in terms of Emacs chats and other good things until I put this review together. That’s one of the advantages of reviews. You get to see the accumulation of little things. Oh, and I paid myself too.

Thanks to some help from the vendor, I made a lot of progress on my consulting project for E1. I’m rusty at J2EE, but I’m doing okay.

The weather was nice and warm in May, so I did a lot of biking and gardening. I added tire liners and patched a few holes in my tires, so that should result in fewer flats. We planted herbs and vegetables, added lots of compost (both free and purchased from Home Depot), and started turning our compost heap regularly. I discovered that yes, I do actually enjoy watching grass grow. Learning slowly, but getting there.

This month, I focused on helping the Emacs community. I’ve been experimenting with delivering an e-mail-based course on reading Emacs Lisp, and that’s going well. I’ve also been paying Emacs geeks to help me with transcripts of chats, videos, and other resources. I’d like to eventually build http://emacslife.com into a useful resource that complements the Emacs Wiki and Emacs-related blogs.

I also dusted off Quantified Awesome’s unit tests and brought it back up to 100% coverage, at least as reported by simplecov. Eventually I want to upgrade it to Rails 4. I’ve been learning Clojure too. I’ve completed all the elementary problems on 4clojure.com and am now working my way through the easy ones. Lots of things to try out!

In June, I’d like to:

  • Deliver a chunk of functionality for project E1
  • Polish and publish the Emacs Lisp beginner course, possibly on a self-serve platform
  • Take it easy because of project F2

Here’s what I blogged about:

Sketches:

Read Lisp, Tweak Emacs [Beginner 1/4]: How to try Emacs Lisp

June 5, 2014 - Categories: emacs
This entry is part 1 of 4 in the series Read Lisp, Tweak Emacs

Okay! People have given lots of great feedback on the e-mail course. It’s time to post the course content on my blog so that you can read it here too (or search for it in case you want). =) I’ll post these one section at a time, but you can read the current draft at http://emacslife.com/how-to-read-emacs-lisp.html if you want to. Any updates will probably be over there too!

Some conventions we’ll use:

  • Inline code will be boxed and monospace in the HTML version and generally surrounded by equal signs in plain text.
  • Code samples will be monospace and in boxes in the HTML version, and enclosed in #+begin_src#+end_src in plain text. Example:
    (message "Hello world")
    

After this section, you should be able to

  • find Emacs Lisp code to study and use
  • try Emacs Lisp code before saving it to your configuration (that way, you don’t have to keep restarting Emacs)
  • add code to your configuration so that it runs whenever Emacs starts

Finding Emacs Lisp code

It’s easier to learn how to read Emacs Lisp when you start with simple examples that will help you use Emacs more effectively. Here are some useful sources:

Emacs documentation

Manuals and FAQs for Emacs-related tools often include code snippets. For example, the Emacs FAQ has an entry like this:

5.47 How can I tell Emacs to fill paragraphs with a single space after each period?
===================================================================================

Add the following line to your `.emacs' file:

     (setq sentence-end-double-space nil)

You can read the Emacs manual by typing C-h i (info) and choosing the Emacs item. If you’re on a terminal that doesn’t understand the C-h key, use F1 or M-x help whenever you see a reference to C-h, or use M-x to call the command by name (ex: F1 i, or M-x info). To jump directly to the Emacs manual, you can use C-h r (info-emacs-manual). You can also find the Emacs Manual at http://www.gnu.org/software/emacs/manual/emacs.html .

Packages

Emacs has lots of packages in different repositories, many of which require a little extra code in order to be used to full effect. You can use M-x package-list-packages to list the packages that Emacs knows about by default. You will need an Internet connection for that.

If you’re new to Emacs, try getting used to Emacs without packages first. There’s plenty of functionality already built in. When you come across a gap, chances are that someone has written a package to make Emacs behave the way you want it to. Since there are lots of packages that do similar things, you might want to look for recommendations or ask people which ones you should start with.

In addition to the default package repository, there are other community-supported repositories. See Installing packages if you would like to install a package from a different repository.

If you install a package, check out the README, description, documentation, or source code comments for interesting packages to find suggested code to add to your Emacs configuration.

Here are some packages that might be interesting:

  • company: adds text completion
  • yasnippet: snippets and templates
  • undo-tree: visualize your undo/redo history

You will need to be connected to the Internet in order to view and install packages. You can use M-x package-list-packages to show the available packages and read the descriptions for the packages above.

Webpages, blog posts, and the Emacs Wiki

While searching for information related to Emacs, you’ll probably come across lots of Emacs Lisp snippets. The EmacsWiki has lots of code, too. Since this is a community-maintained wiki, you may come across code that is out of date or that refers to packages that you don’t have. I’ve included common errors in this guide to help you figure things out – see “Oh no! I have an error!”

Here are some sites you may want to check out:

Mailing lists, newsgroups, and Q&A sites

There are many places where you can ask for help with Emacs. gnu.emacs.help is available as a mailing list or as a newsgroup – check your favourite Usenet server or use Gmane. StackOverflow and Quora are popular as well. If you ask questions there, you might get answers in the form of Emacs Lisp code. You’ll also come across Emacs Lisp code while searching for answers.

Find a snippet of Emacs Lisp code you want to understand more deeply, or look at the examples in the sections below.

Trying out code

It’s easier to understand code if you can experiment with it. Emacs Lisp code is made up of symbolic expressions (known as S-expressions, expressions, or sexp for short). Expressions are usually enclosed in pairs of parentheses. There are several ways you can try Emacs Lisp expressions before saving them in your configuration.

Note: As you experiment with Emacs Lisp, you might run into errors. Check out “Oh no! I have an error!” for some common errors and what to do about them.

Here are some ways you can run Emacs Lisp code. I’ll explain them in more detail below.

  • M-x ielm (Inferior Emacs Lisp Mode) – evaluates expressions after you press RET, which is handy for pasting in code
  • The *scratch* buffer and Emacs Lisp files – makes it easy to edit and re-evaluate expressions
  • M-: (eval-expression) – good for quickly evaluating Emacs Lisp code while you’re doing something else
  • C-x C-e (eval-last-sexp) – handy when reading expressions in manuals or other text

M-x ielm (Inferior Emacs Lisp Mode)

The Inferior Emacs Lisp Mode gives you a prompt where you can type or paste in Emacs Lisp code. Start it with M-x ielm. Press RET after you enter code, and the results will be displayed. “Inferior” is a technical term referring to how it’s run, not a comment on the simplicity of the tool or the code you want to try. You can go to previously-executed code, change things, and press RET to run (or “evaluate”) it again.

If you’re copying or typing code, make sure your parentheses are all matched – every “(” should have a “)“. IELM won’t run the code unless it sees the closing parenthesis. So the following code is incomplete:

(message "Hello

but this will work:

(message "Hello world")

You can use M-p (comint-previous-input) to go through the previously-typed expressions. M-n (comint-next-input) goes forward.

Tip: When you’re trying out an unfamiliar mode, use C-h m (describe-mode) to learn more about the commands that are available in that mode.

The *scratch* buffer and Emacs Lisp .el files

When Emacs starts, it creates a buffer called *scratch* with the following contents:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

You can add code to the end.

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

(message "Hello world")

Note: ; is the comment character. Anything after the comment character is considered part of the comment. Make sure you add your code on a new line, not in the comment. ;; above is how we usually start comments that take up the entire line.

To run code (“evaluate” it, in Emacs terms), you can use the following commands based on what you want to run:

  • M-x eval-buffer runs all the code in the current file or buffer.
  • M-x eval-region runs the code in the selected region. You can select a region of text by using the mouse. Alternatively, you can type C-SPC to mark the start of the region, then move your cursor to the end of the region. If you want to learn more about selecting regions, check out the Emacs tutorial (C-h t, C-h t, or M-x help-with-tutorial).
  • C-x C-e (eval-last-sexp) runs the expression (S-expression, or sexp) before the cursor. NOTE: Your cursor should be after the closing parenthesis, not on it.

In the *scratch* buffer, you can also press C-j (eval-print-last-sexp) after an expression in order to evaluate it and display the results in the buffer.

The *scratch* buffer is not automatically saved. If you would like to save your code for future use, you can create a file with an .el ending. el stands for Emacs Lisp, and Emacs will open these files in Emacs Lisp mode. The commands listed above work in Emacs Lisp files.

M-: (eval-expression)

If you want to quickly try a single expression, you can use M-: (eval-expression). It will display the results in the echo area near the bottom of your screen. If you want to insert the results into your buffer, call it with C-u M-: instead. For example, you can use C-u M-: (* 18 2) to multiply 18 and 2 quickly. To review previous results, you can switch to the *Messages* buffer.

C-x C-e (eval-last-sexp)

C-x C-e (eval-last-sexp) runs the expression (S-expression, or sexp) before the cursor. NOTE: Your cursor should be after the closing parenthesis, not on it. C-x C-e (eval-last-sexp) works in lots of buffers, not just in Emacs Lisp ones. You can use it to quickly try expressions while reading manual pages or other documentation.

You can get the text file for this lesson from http://emacslife.com/read-lisp-tweak-emacs/beginner-1-try-emacs-lisp.txt . If you’re reading this lesson in Emacs, try putting your cursor after the closing ) and calling C-x C-e (eval-last-sexp) on the following line:

(menu-bar-mode -1)

This turns off the menu bar along the top of your Emacs window. If you like the menu bar, you can turn it on again by evaluating:

(menu-bar-mode 1)

As with M-: (eval-expression), you can use the C-u prefix to insert the results instead of displaying them. For example, try using C-u C-x C-e (eval-last-sexp) to evaluate the following expression:

(* 6 7)

If you want that code to run every time you start Emacs…

then add it to your ~/.emacs.d/init.el file. You can generally add new code at the end. If the code has something to do with add-to-list and load-path, it might be good to add it to the beginning instead.

Note: The Emacs configuration file used to be ~/.emacs, and most webpages refer to that. ~/.emacs still works – in fact, if you have that, it may stop Emacs from loading ~/.emacs.d/init.el. On the other hand, if you use ~/.emacs.d/init.el (and move your ~/.emacs code to that file instead), then you have one less hidden file in your home directory (~). If you’re adding code to your config and it’s not getting loaded, make sure you have either ~/.emacs or ~/.emacs.d/init.el, but not both.

When you’re starting out, it’s a good idea to keep your configuration in one file. Later on, you can split it up into multiple files if you want.

Practice

Try this out:

Next module: “How can I understand what Emacs Lisp code does?”

  1. Browse through http://www.emacswiki.org/emacs/CategoryDotEmacs for some code that looks like it will make Emacs work more like the way you want it to. If you need help figuring it out, send me a copy of the code ([email protected]).
  2. Use M-x ielm to evaluate this expression interactively:
    system-type
    

    This shows you the value of the system-type variable. Note: Variables can be evaluated without the parentheses, but functions can’t. Use You can use ielm to call functions like this, though:

    (max 2 6 10 5)
    
  3. Use M-: (eval-expression) buffer to evaluate the following expression:
    (* 21 2)
    

    M-: is handy for quick calculations. Remember, you can use it with
    C-u (that is, C-u M-:) to insert the result into the buffer.
    Try it now: C-u M-: (* 21 2)

  4. Use C-x C-e (eval-last-sexp) to evaluate the expression below. If you are reading this in Emacs, you can evaluate it by putting your cursor after the last ) and calling C-x C-e (eval-last-sexp). If you are reading this outside Emacs, you can copy that text into any buffer and then use C-x C-e (eval-last-sexp) to evaluate it.
    (* (+ 1 2) 3)
    
  5. Add (message "Hello, world!") to the end of your ~/.emacs.d/init.el (or ~/.emacs, if you’re using that file instead). Use M-x eval-buffer to load your config. It should display the message near the bottom of your screen. If you restart Emacs, you should also see that message briefly.
  6. Call M-x visual-line-mode to tell Emacs to visually wrap lines without actually changing the text. If you like this, add (visual-line-mode) to your ~/.emacs.d/init.el.

What could Emacs coaching look like?

June 6, 2014 - Categories: emacs

I asked people on Twitter how much they might pay for 30-60 minutes of Emacs coaching. Based on replies and e-mails, the general consensus seems to be about $25-35 for 30 minutes and $35-50 for an hour, depending on the level of tweaking.

This is how I imagine it might work and why it might be worth it:

Troubleshooting
You could spend days (or weeks!) posting and replying to mailing lists or StackOverflow, or you could spend an interactive session quickly digging into what’s wrong and how to work around or fix it. In addition, you’ll probably pick up lots of tips by watching someone’s problem-solving or debugging process. This probably works as a quick e-mail describing the problem, a 30-60 minute troubleshooting session over screen sharing or SSH/tmux, and possibly a free or paid-for follow-up if more investigation is needed. Probably a good idea to have a satisfaction guarantee, since some problems are harder to solve than others.
Guidance, pair programming, or coding
You’ve got an idea for an Emacs customization or major mode, but it requires more Emacs Lisp geekery than you’re comfortable with or you don’t know how to go about implementing it. A few high-level pointers might get you going: check out these examples, use this function to do that, etc. Or you might want to write most of the code yourself while having someone around so that you can ask questions if you get stuck – maybe a lower rate for the virtual equivalent of hanging out in a cafe together while working on separate things? Alternatively, a code review can point out how you can debug or improve things. Lastly, there’s also the option of handing off most of the coding, with some interactive sessions as you nail down exactly how you want it to behave.
Coaching
I think this is where incredible is, actually – getting help when you don’t even know what you don’t know. Emacs is really big. It can be difficult to get a sense of what’s possible or what’s surprisingly easy, so you might be plodding along with an inefficient workflow that could be tweaked with a little configuration or a few changed practices. A good coach can discuss your goals, watch how you do things, demonstrate better ways to work, and help you implement those changes.
Gradual learning
On a related note, it’s also easy to get intimidated by how much there is. It can help to have a gradual learning path. I’ve talked to quite a few people who found Org Mode task management overwhelming and had hundreds of tasks piled up in their text files. Ditto for Emacs Lisp learning! Imagine having the Emacs equivalent of a personal trainer who can help you come up with an individualized program of learning so that you’re focused on one small chunk at a time. =)

Plot twist! This is actually for Bastien Guerry (Org Mode maintainer, also http://emacs-doctor.com/), not for me. I’ve been doing Emacs-related Helpouts for a token fee and I’m happy to chat with people about Emacs gratis as well, but I think it would be even awesomer to see if someone as wonderful as Bastien can build a nice little business out of it.

How wonderful is Bastien? Well, if you’ve seen my Emacs Chat with him or read his posts on the Org Mode mailing list, you know that he’s smart, experienced, and friendly. In fact, the more I think about what Emacs consulting might be like, the more I want to sign up too. I use Org a lot and I’m generally comfortable tinkering with the source code, but there are a few things that I haven’t quite wrapped by mind around yet: more export tweaks, more Babel/tangling, a better capture workflow… And I have yet to get around to setting up proper autocomplete and other development tools, too!

Bastien’s travelling at the moment, but wouldn’t it be lovely if he got back to a bunch of e-mails to [email protected] with requests or suggestions? =) E-mail him if you’re interested, and help him figure out what’s a good way to help you. He mentioned being open to pay-what-you-want pricing. If money is tight, reach out to him anyway – and if you want to donate more as a way of thanking him for all the other stuff he does, that’s also a great excuse to ask him to help improve how you use Emacs.

Hey, if there are Eclipse consultants… Surely we can get even more value out of Emacs consulting!

Weekly review: Week ending June 6, 2014

June 8, 2014 - Categories: review, weekly

Eventful week in terms of non-work things! =) Concert, movie, projects, and more.

Blog posts

Sketches

None posted this week.

Link round-up

Focus areas and time review

  • Business (27.4h – 16%)
    • Earn (16.2h – 59% of Business)
      • E1: Do monthly stats
      • E1: Attend another team event
      • Earn: E1: 2.5-3.5 days of consulting
      • E1: BW homepage
    • Build (7.4h – 27% of Business)
      • Drawing (3.0h)
      • Delegation (0.0h)
        • Reflect on delegation challenges
      • Packaging (0.0h)
      • Paperwork (0.0h)
        • Follow up on misdirected mail
        • File payroll return
      • Work on a 4clojure problem
      • Renew domain names
      • Fix the library thing
      • Work on a 4clojure problem
    • Connect (3.7h – 13% of Business)
      • Have breakfast with Aaron, Jen, and Bernie
      • Chat with Doug regarding sketchnoting
  • Relationships (13.0h – 7%)
    • Call C tomorrow about P
    • Chat with Jeff Widman
    • Fill out form
    • Go to Postmodern Jukebox concert
    • Milestone for F2
    • Plan substitute plans in detail
    • Work on project F2
    • Attend Hacklab meeting
  • Discretionary – Productive (22.6h – 13%)
    • Postmodern Jukebox
    • Reduce Dropbox use
    • Write about Emacs coaching
    • Writing (3.9h)
    • Emacs
      • Add more examples
      • Add more exercises
      • [#A] Add objectives and practice to section 4
      • Write objectives for each section
      • Take notes on people who are interested in taking course, process course steps
      • Review transcript for Emacs NYC talk
      • Review technomancy transcript
      • Learn about Calc
      • Consider moving back-to-top, e-mail to the top right?
      • Chat with Tom and Neil about Clojure
      • Take notes on people who are interested in taking course, process course steps
  • Discretionary – Play (8.5h – 5%)
  • Personal routines (28.4h – 16%)
  • Unpaid work (9.9h – 5%)
  • Sleep (58.4h – 34% – average of 8.3 per day)

SSL issues after moving to Ubuntu Precise

June 9, 2014 - Categories: geek

My Rails script for checking library due dates and renewing items stopped working the other day to BadGateway errors. While debugging I ended up going down this rabbit-hole of trying to upgrade RVM’s OpenSSL and Ruby versions. rvmsudo rvm pkg install openssl failed in my production environment because the Linode VPS was now 64-bit, so even though I had the appropriate development libraries installed, the code still didn’t compile. I tried all sorts of things like rvm get head; rvm reload and gem update --system.

I kept running into errors like There was an error while trying to resolve rubygems version for 'latest'. when reinstalling Ruby and /usr/bin/ld: cannot find -lz when using RVM to reinstall OpenSSL (even though I had zlib1g-dev installed).

After an hour and a half of searching through StackOverflow and mailing list messages, I finally paid attention to the curl error message:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I searched for that and Ubuntu Precise. As it turns out, the upgrade from Ubuntu 10 to Ubuntu 12 resulted in some issues with Verisign-certified sites. I know, I know, old news (almost two years old!) but I hadn’t gotten around to upgrading off Lucid until recently.

Anyway, I followed the recommended steps to copy the text from https://knowledge.verisign.com/support/ssl-certificates-support/index?page=content&id=AR1556 into /usr/local/share/ca-certificates/verisign.crt and ran update-ca-certificates. After that, rvm reinstall 2.0.0 worked, and so did my script.

Harumph! Anyway, I’m glad that’s fixed.

Dealing with uncertainty

June 10, 2014 - Categories: life
2014-06-09 Dealing with uncertainty

2014-06-09 Dealing with uncertainty

Some projects are mostly under my control. I might not know exactly how to get to my goals, but if I make steady progress, I’ll eventually figure things out and get there. Programming is like that. I have a good idea of what’s possible. If I break the challenge down into small, manageable tasks, I’ll solve it eventually. Juggling two or more projects makes it easier for me to switch to something that I can act on whenever I get stuck or whenever I need to wait for something else.

Other projects are less certain, but I can use other people’s experiences to improve my estimates. Research helps me figure out the odds, and that lets me take calculated risks or make decisions. If things don’t go my way, I can remind myself that success wasn’t certain in the first place. You can do everything right, but you’re still subject to forces beyond your control. No point in stressing out over things you can’t influence as much as you’d like, anyway. All you can do is prepare for flexibility and safety nets so that you can take advantage of opportunities and mitigate risks. =)

For some projects, I don’t even know the odds. Am I doing better or worse than expected? No clue! For example, in terms of gardening, is my garden doing well despite the shade and the sandy soil, or are there other things I can do to improve it? Someone with more experience might be able to figure things out. I’m still working on figuring out how to ask better questions. It helps to pay attention and do the best I can, celebrating the journey along the way. (The grass is growing! The bitter melon are starting to flower! I’m getting into the habit of rubbing off the leafminer eggs on the sorrel!) It also helps to remember that many of the projects in this category are long-term ones, so even if I make mistakes this year (apparently, you’re not supposed to prune early tomato flowers), I can learn from those mistakes and make next year even better.

I like being mostly in control, or at least knowing what to expect. I’m gradually getting better at dealing with uncertainty, though. =)

 

Slowly getting the hang of Clojure

June 11, 2014 - Categories: geek

At least in terms of 4clojure problems. =) I’ve worked my way through the elementary and easy problems (woohoo!), with 88 exercises completed so far. It took me a while to get the hang of lazy-seq, since Emacs Lisp doesn’t do lazy evaluation. Once I started thinking of it as a macro, though, I finally got the hang of it. Here’s my solution for the exercise for reimplementing map:

(fn my-map [func input]
      (if (sequential? input) 
        (cons (func (first input))
              (lazy-seq (my-map func (next input))))))

There are more exercises to do, and it’s fun to feel the different concepts start coming together. I might not do the hard exercises, though. I still haven’t thought of any practical purposes I’d like to use it for, though…

Quantified Awesome: Added sparklines and percentages

June 12, 2014 - Categories: quantified

As I was answering the standard question of “Who are you and what do you do?”, I thought it might be interesting to come up with the percentages for what I actually do based on my time records. After all, I have the data. In the past, I used to export my records to a spreadsheet and do some easy number-crunching. Why bother, though, if I can program the system to do this for me?`

I ended up spending 3.5 hours adding percentages and sparklines to Quantified Awesome, updating my RSpec tests along the way. (100% coverage, yay!) Here’s what the result looks like:

2014-06-11 13_34_46-quantified awesome

The sparklines let me easily see trends and exceptions, while percentages can be easily multiplied by 168 hours to get weekly estimates or 24 hours to get daily ones. For example, sleep took up 35.8% of my time from 2012-02-17 to 2014-06-11, or an average of 8.6 hours a day. Activities directly related to earning money took up 10.9% of my time, or roughly 18.3 hours a week. The sprints and spikes are easier to see with sparklines than with tabular data, and they were easy to implement with JQuery Sparklines.

So now I can be more accurate when answering the question: “What do you do?” It doesn’t make sense to include all the minutiae. People don’t really answer that question with “Sleep,” even though that takes up much of people’s time. However, I can pick a threshold (1%?) and look at the activities above that. That is, for the ~28 months of this 5-year experiment so far, I:

  • consult (10.3%)
  • connect with people (5.0%)
  • write (3.0%)
  • draw (2.5%)
  • cook (2.3%)
  • bike (2.0%)
  • work on Emacs (1.2%) and
  • work on Quantified Awesome and other tracking tools (1%)

Data! Mwahahaha…

Read Lisp Tweak Emacs [Beginner 2/4]: How to understand what Emacs Lisp code does

June 13, 2014 - Categories: emacs
This entry is part 2 of 4 in the series Read Lisp, Tweak Emacs

Some conventions we’ll use:

  • Inline code will be boxed and monospace in the HTML version and generally surrounded by equal signs in plain text.
  • Code samples will be monospace and in boxes in the HTML version, and enclosed in #+begin_src#+end_src in plain text. Example:
    (message "Hello world")
    

After this module, you should be able to

  • learn more about the functions and variables that you find in Emacs Lisp code
  • pay attention to important details when copying code, such as ‘ (quote) and . (dot notation)
  • add to and remove items from lists

Learn more about functions

The symbol after ( is usually a function name, unless it’s part of a list of literals (numbers, strings, etc.). You’ll learn how to recognize literal lists later.

In math, operators like + and * go between the numbers they will work on. In Emacs Lisp, the operator (or the “function”) is at the start of the expression, followed by the things it’s going to operate on (“arguments”).

Here’s how to calculate (1 + 2) * 3 in Emacs Lisp. Note that the multiplication is surrounded by parentheses, even if we usually leave out the parentheses in math. That’s because in Emacs Lisp, all function calls have their own set of parentheses.

(* (+ 1 2) 3)

Let’s take a closer look:

( ( 1 + 2 ) * 3 )    Math expression
( * ( + 1 2 ) 3 )    Emacs Lisp expression

math-to-emacs-lisp.png

See how the operators are at the beginning of whatever they’re working on, and the parentheses enclose everything that’s related to that operator?

Understanding this will let you read code like:

(global-hl-line-mode)

This calls the global-hl-line-mode function, which highlights the current line.

(show-paren-mode)

This calls the show-paren-mode function, which shows matching parentheses when your cursor is after them.

(blink-cursor-mode -1)

This calls the blink-cursor-mode function with -1 as the argument, which turns blinking cursors off.

(find-file "~/todo.org")

This calls the find-file function with the todo.org file in your home directory. It opens the file, creating it if it doesn’t exist yet.

(turn-on-eldoc-mode)

This turns on eldoc-mode, which displays the argument list for the current function. You can move your cursor around to see argument lists for other functions.

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

This turns on eldoc-mode when a buffer is switched to Emacs Lisp mode. You’ll learn more about why some things have ​'​ and some don’t in the section “Some things are taken literally” in this module.

To find out if something is a function, what it does, what arguments it takes, and if it has any keyboard shortcuts, use the C-h f (describe-function) command. Give it the function name. For example, C-h f add-hook will show you the documentation for add-hook, and C-h f show-paren-mode will show you the documentation for that.

The documentation for show-paren-mode starts with “show-paren-mode is an interactive autoloaded Lisp function”. Interactive functions are functions that can be called with M-x or with keyboard shortcuts, and they’re usually functions that you’ll find useful while interacting with Emacs. Non-interactive functions tend to be for internal use, such as code that other Emacs Lisp code will call. Read the description of the function to learn more about arguments that you can pass to change its behavior. If it mentions a prefix argument, that means that you can change its behaviour by typing C-u before you call the function.

Emacs is extensively documented. Whenever you come across a strange function, check it out with C-h f (describe-function). If you have the Emacs Lisp sources installed, you can learn more about how the functions work. Just follow the link from the documentation, or use M-x find-function to learn more.

In fact, you can learn more about functions even if you don’t know what they’re called. For example, if you know the keyboard shortcut or you can see the item on one of the menus, use C-h k (describe-key) to learn more about that command. Emacs will show you the function that’s associated with that keyboard shortcut or menu item. You can also look up functions by keyword if you use M-x apropos.

  1. Use C-h f (describe-function) to learn more about the following functions:
  2. describe-function: Yes, this is also a function! The documentation will give you alternative keyboard shortcuts such as F1 f.
  3. find-file: You can use this to open specific files. See the function description to learn how to use this with remote files.
  4. message: This is an example of a function that has a variable number of arguments. The first argument says how the message will be displayed, and the rest of the arguments contain the values.
  5. just-one-space: Handy way to clean up space. What keyboard shortcut is it bound to?
  6. Look for Emacs configuration code that you would like to understand further. Use C-h f (describe-function) to learn more about the functions in the code. For example, here are some snippets from my configuration. What do the functions do?
    (savehist-mode 1)
    (tooltip-mode -1)
    (tool-bar-mode -1)
    (menu-bar-mode -1)
    (scroll-bar-mode -1)
    (prefer-coding-system 'utf-8)
    

Learn more about variables

Variables are containers that can hold different values. In Emacs Lisp, you can change the value of a variable as many times as you want, and you can change it to different types of data as needed.

Like the way you can use C-h f (describe-function) to learn more about a function, you can use C-h v (describe-variable) to learn more about a variable by name. For example, use C-h v to look up the documentation for visible-bell. It says:

Non-nil means try to flash the frame to represent a bell.

A non-nil value is anything that isn’t nil, such as t or 1. If you would like to configure your Emacs to flash instead of ringing the bell,
you could add the following code to your ~/.emacs.d/init.el:

(setq visible-bell t)

Here’s another useful snippet:

(setq column-number-mode t)

This turns on the display of the column number in the modeline.

Many variables have the same value no matter what you’re looking at. Some variables change depending on the buffer you’re in, and are called “buffer-local” variables. Use C-h v to find out if a variable is buffer-local. For example, the documentation for tab-width includes:

Automatically becomes buffer-local when set.

This means you can’t globally set it with setq, because any changes you make will only be applied to the current buffer. However, you can set the default value with setq-default like this:

(setq-default tab-width 2)

To make it easier for you to customize Emacs without writing Emacs Lisp code, many variables give you an interface for setting the variable. If you use describe-variable to look up the definition, you’ll often see a line like “You can customize this variable.” Click on the customize link in the documentation or move your point to it and press RET. You can change the value there and try it temporarily, or you can save it to your configuration. The Customize interface is good for exploring, but because the code that it generates can difficult to read or share, many people skip it and use Emacs Lisp code instead.

  1. Use C-h v (describe-variable) to learn more about the variables in the following code snippet:
    (setq-default indicate-empty-lines t)
    (setq-default show-trailing-whitespace t)
    
  2. Look for Emacs configuration code that has variables you would like to learn more about. Use C-h v (describe-variable) to look up their definition and the values they can be set to.

Understand symbols

Let’s take a closer look at this example.

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

add-hook is a function. ‘emacs-lisp-mode-hook and ‘turn-on-eldoc-mode have single quotes, which tells Emacs to skip evaluating them. They refer to the name of the thing instead of its value. emacs-lisp-mode-hook is a variable that contains a list of functions to run, and turn-on-eldoc-mode is a function that we’re adding to that list.

The single quote means take it literally – treat it as the name of something. If you remove the quote from emacs-lisp-mode-hook, Emacs will look up the value in that variable and use that as the name of the variable to actually set, and you’ll probably get an error.

Use M-: (eval-expression) or another way to evaluate expressions to tell the difference between:

emacs-lisp-mode-hook

and

'emacs-lisp-mode-hook

The first one does not have a quotation mark, and Emacs replaces it with the value that the variable emacs-lisp-mode-hook contains. The second one is quoted, so Emacs treats it as the name of a thing.

Here’s another example:

(fset 'yes-or-no-p 'y-or-n-p)

This calls the fset function, which sets the function definition of yes-or-no-p to the function y-or-n-p. In short, it changes the “yes” or “no” prompts to “y” or “n”, which can be convenient.

Not everything is quoted. You’ll often see lines like this in Emacs configuration files:

(setq delete-old-versions -1)

setq stands for “set quoted”. This is actually the same code as (set 'delete-old-versions -1) or (set (quote delete-old-versions) -1), but
setq is shorter, so it’s more common.

This can be confusing. When you’re starting out, copy code carefully. If there’s a single quote, make sure there’s a single quote in your copy. If there isn’t, skip it.

Work with lists

You can set the value of a variable to multiple things. In Emacs configuration files, you’ll often see ‘ used for lists. For example,

(setq diff-switches '("-b" "-u"))

sets the options for the diff command to a list containing two items, -b and -u. Quoting the list creates a list and quotes all the content in it as needed. You can create lists with the list function instead. The code above is the same as:

(setq diff-switches (list "-b" "-u"))

The code above sets the value of the variable to a list, ignoring any previous values it had.

Add to a list

Most of the time, though, you want to add to a list instead of completely replacing it. You’ll often see something like this in people’s configuration files:

(add-to-list 'load-path "~/elisp")

This adds the ~/elisp directory to the beginning of the list of directories that Emacs checks when loading libraries. If the directory is already in the list, add-to-list does nothing.

Hooks

Hooks are lists of functions that are called from Emacs Lisp in order to modify the behaviour of something. For example, different modes have their own hooks so that you can add functions that will run when that mode is initialized. You saw this example earlier in the module:

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

This is equivalent to:

(add-to-list 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

It adds the turn-on-eldoc-mode function to the list of functions
when a buffer is initialized with emacs-lisp-mode.

Deleting from a list

If you need to delete something from a list, you can use the delete function like this:

(setq load-path (delete "~/elisp" load-path))

This deletes the specified member from the list. Note that the second argument for delete is not quoted, so Emacs Lisp uses the value instead of treating it as the name of a list.

Hooks are lists of functions, so you can delete items using delete. Alternatively, a cleaner way to remove a hook is to use remove-hook like this:

(remove-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

Dot notation

Some things look like lists, but there’s a dot between the first element and the last element. Whether something should have a dot or not depends on what’s expected by the function that uses the data. For example:

(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))

This calls the add-to-list function with two arguments. The first argument (‘package-archives) specifies the list to add an item to, and the second argument (‘("melpa" . "http://melpa.milkbox.net/packages/")) is the data to add.

The dot (x . y) shows that this is a cons cell, which is something that has two parts. These parts are called the car and the cdr, and can contain symbols, values, lists, and so on. A cons cell like ("abc" . "def") looks like this:

       car              cdr
+----------------+----------------+
|     "abc"      |     "def"      |
+----------------+----------------+

A list like ‘("abc" "def") is made up of several cons cells.

       car              cdr                         car             cdr
+----------------+----------------+         +----------------+----------------+
|     "abc"      |       ------------------>|      "def"     |      nil       |
+----------------+----------------+         +----------------+----------------+

In Emacs Lisp, ‘("abc" "def") is equivalent to (cons "abc" (cons "def" nil)), and it’s not the same as (cons "abc" "def"). Here’s something that shows the differences:

(cdr '("abc" . "def"))  ;; Returns "def", which is a string
(cdr '("abc" "def"))    ;; Returns ("def"), which is a list

If the function you’re calling expects a string instead of a list, or the other way around, you’ll run into errors. That’s why you have to be careful about whether something uses dots or not. A good way to find out is by reading other people’s configuration and seeing how they use that variable.

Because lists are made up of cons cells, you’ll sometimes see people add to lists like this:

(setq load-path (cons "~/elisp" load-path))

This adds ~/elisp to the beginning of the load-path list. It does this by using cons to create a new cons cell that has ~/elisp at the beginning and a pointer to the rest of the values in load-path, and then storing that in load-path. It’s the same as (add-to-list 'load-path "~/elisp"), assuming load-path does not already have that directory. If it does, cons adds it anyway, but add-to-list does not.

Lists can also contain lists. For example, here’s some code that saves backup files (the ones that end in ~) to ~/.emacs.d/backups.

(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))

This is how the second argument breaks down:

( ;; a list with one item
 ("." . "~/.emacs.d/backups") ;; a cons cell with a car of "." and a cdr of "~/.emacs.d/backups"
)

If you want to learn more about cons cells, see the Emacs Lisp Reference.

Advanced: Backquotes or backticks (`) are special. They quote the expression that follows them, but they also allow you to substitute values or evaluate expressions. Backquotes are useful for more complex structures or when you’re working with macros. They do basically the same thing as ‘ for lists, but anything preceded by a comma (,) is evaluated. They’re less common, but if you do come across them, note that ` is not the same as ‘. See the Emacs Lisp Reference for more information. Here’s a quick example:

(setq backup-directory-alist `((".*" . ,temporary-file-directory)))

This stores backup files in the directory specified by temporary-file-directory.

Review

Look for Emacs configuration code that you would like to understand further. Use C-h f (describe-function) to learn more about functions and C-h v (describe-variable) to learn more about variables in the code. Can you figure out what the code does and how you might modify it slightly to fit your needs even better?

Weekly review: Week ending June 13, 2014

June 14, 2014 - Categories: review, weekly

I’ve been taking it easy. Lots of gardening, walking, and even reading comic books or playing video games… =) Good progress on work projects, though! Oh, and some time spent coding – fun!

Blog posts

Sketches

Probably a few, but I haven’t scanned them yet. =)

Link round-up

Focus areas and time review

  • Business (32.8h – 19%)
    • Earn (18.0h – 54% of Business)
      • Earn: E1: 2.5-3.5 days of consulting
      • E1: BW homepage
      • Earn: E1: 2.5-3.5 days of consulting
    • Build (8.3h – 25% of Business)
      • Add percentage as a review option
      • Work on a 4clojure problem
      • Work on a 4clojure problem
      • Drawing (1.1h)
      • Delegation (0.0h)
        • Reflect on delegation challenges
      • Packaging (0.0h)
      • Paperwork (1.8h)
        • Follow up on misdirected mail
        • File payroll return
    • Connect (6.5h – 19% of Business)
  • Relationships (9.7h – 5%)
    • Attend Hacklab meeting
    • Research real estate
    • Check progress for F2
  • Discretionary – Productive (15.6h – 9%)
    • Emacs (4.1h – 2% of all)
      • Take notes on people who are interested in taking course, process course steps
      • Review transcript for Christopher Wellons
      • Review transcript for Bozhidar Batsov
      • Prep for call with Mickey Petersen
      • Chat with Tom and Neil about Clojure
      • Chat with Doug regarding sketchnoting
      • Pay invoices
      • Take notes on people who are interested in taking course, process course steps
    • [#C] Track cat data
    • Add compost to back garden
    • Writing (2.1h)
      • Realistic expectations, ruthless elimination, and rapid exploration
  • Discretionary – Play (14.1h – 8%)
  • Personal routines (27.9h – 16%)
  • Unpaid work (9.0h – 5%)
  • Sleep (58.8h – 34% – average of 8.4 per day)

In the garden

June 15, 2014 - Categories: gardening

The garden is doing pretty well. We have salad every other day or so, and I’m constantly thinking of recipes to use the herbs before they totally take over the garden. =)

  • Various leafy greens, with tomatoes and peas in the background

    Various leafy greens, with tomatoes and peas in the background

  • The strawberries are tiny

    The strawberries are tiny

  • Garlic, other herbs

    Garlic, oregano, mint

  • The cilantro towers over the other herbs

    The cilantro towers over the other herbs in this planter

  • Thai basil is pretty dense

    Thai basil is pretty dense

  • The sweet basil is quite happy, too

    The sweet basil is quite happy, too

Realistic expectations, ruthless elimination, and rapid exploration

June 16, 2014 - Categories: productivity

“You’re pretty organized, right? Do you have a system for productivity that I could use?” someone said to me. She sounded frustrated by her lack of progress on some long-standing projects. I shrugged, unsure how to help.

I don’t consider myself super-productive. I am, however, less stressed than many people seem to be. I’ve been learning to keep realistic expectations, get rid of less-important tasks, and work in quick, small, useful chunks.

Realistic expectations: We tend to overestimate how much we can do, particularly if we’re looking a week or two ahead. Even if last week was derailed by interruptions, we hope next week will be a smooth ride. I’m guilty of this myself. I compensate by expecting little of myself – just one to three important tasks each day, moving forward a little bit at a time. If I find myself with spare time and motivation, I check my other tasks for something to work on. It’s okay if I end up procrastinating something. That usually means I spent the time on something I valued more.

Ruthless elimination: “But how do I motivate myself?” This is another thing that people often struggle with. I use different strategies depending on what I need. For example, I’m currently working on a project with a high risk of failure and a fair bit of work. For me, it helps to amplify the perceived benefits, downplay the small pieces of work that I need to do (it’s just a small task), and downplay the risks (failure isn’t all that bad). On some other projects, I might decide that my lack of motivation is a clue that I should just wrap up the project, get rid of specific tasks, delegate work, or transform those tasks into things I might enjoy more.

Rapid exploration: After I adjust for realistic expectations and get rid of tasks through ruthless elimination, I think of tiny tasks that will help me move towards my goals. That way, I can explore and get feedback faster. Then I try to get as much value as I can from those steps, usually ending up with blog post ideas and lessons learned in addition to the thing itself. This also means that I can squeeze work into 15- to 2-hour chunks instead of waiting for a 4-hour span of uninterrupted, energetic time.

There are a bunch of other things that help me out (keeping outlines of projects and tasks in Org Mode, documenting as much as I can, knowing my tools well), but those three behaviours above seem to be different from the way many people around me work. Hope that helps!

Summarizing the last meeting dates in Org Contacts

June 17, 2014 - Categories: emacs, org

Steffan Heilmann wanted to be able to quickly see the last time he interacted with someone if he tracked interactions in org-contacts. That is, given something like this:

* John Smith
** DONE Conversation
[2014-01-20]
** DONE E-mail
[2014-01-15]
* Jane Smith
** DONE Conversation
[2014-01-07]

… we want to see the latest timestamps for each contact entry.

Here’s the code that I came up with. It scans backward for timestamps or headings. Whenever it finds a timestamp, it compares the timestamp with the one that it has previously stored and keeps the later timestamp. Whenever it encounters a level-1 heading, it sets the property and clears the stored timestamp.

(defun sacha/org-update-with-last-meeting ()
  "Update each level 1 heading with the LASTMEETING property."
  (interactive)
  (goto-char (point-max))
  (let (last-meeting)
    (while (re-search-backward
            (concat "\\(" org-outline-regexp "\\)\\|\\("
                    org-maybe-keyword-time-regexp "\\)") nil t)
      (cond
       ((and (match-string 1)
             (= (nth 1 (save-match-data (org-heading-components))) 1)
             last-meeting)
        ;; heading
        (save-excursion (org-set-property "LASTMEETING" last-meeting))
        (setq last-meeting nil))
       ((and (match-string 2))
        (if (or (null last-meeting) (string< last-meeting (match-string 2)))
            (setq last-meeting (match-string 2))))))))

Scanning backwards works well here because that makes it easy to add information to the top-level heading we’re interested in. If we scanned it the other way around (say, with org-map-entries), we might need to backtrack in order to set the property on the top-level heading.

The result is something like this:

* John Smith
  :PROPERTIES:
  :LASTMEETING: [2014-01-20]
  :END:
** DONE E-mail
[2014-01-15]
** DONE Conversation
[2014-01-20]
* Someone without a meeting
* Jane Smith
  :PROPERTIES:
  :LASTMEETING: [2014-01-07]
  :END:
** DONE Conversation
[2014-01-07]

You can then use something like:

#+COLUMNS: %25ITEM %LASTMEETING %TAGS %PRIORITY %TODO
#+BEGIN: columnview :maxlevel 1
| ITEM                        | LASTMEETING  | TAGS | PRIORITY | TODO |
|-----------------------------+--------------+------+----------+------|
| * John Smith                | [2014-01-20] |      |          |      |
| * Someone without a meeting |              |      |          |      |
| * Jane Smith                | <2014-01-07> |      |          |      |
#+END:

… or even use M-x org-sort to sort the entries by the LASTMEETING property (R will reverse-sort by property).

Baby steps towards investing

June 18, 2014 - Categories: finance

When you’re learning something complex, it can help to break it down into small steps and figure out what sequence is right for you–especially if there are lots of other people who want to influence your decision.

Let’s take investing, for example. There are all sorts of businesses built around making you want to earn more, all sorts of complex instruments that seem to enrich advisors more than clients, and all sorts of decisions that you can make that can either help you or screw up your life. Me, I’m trying to learn slowly.

I’m a simple investor. I don’t need to beat the market. In fact, I’d like to stay as close to average as I can. I don’t need to be smarter than other people who are buying and selling. Even if I have plenty of time, I don’t want to spend that time and attention on tracking financial news. Baby steps – one lesson at a time.

I started by saving up. Then I opened up an investing account with TD and started with their e-series funds, since those had low management expense ratios and no commissions. After years of annually stashing money into TD e-series index funds, I’m now relatively confident about my ability to not panic based on the ups and downs of the market. The stock market has been practically all up since I started, actually. I’ve been investing at the rate I previously set for myself. I haven’t figured out the best way of transferring larger amounts from the corporation yet, but that can wait. In the meantime, it’s a good buffer for emergencies, and it means I can think of corrections as a good thing.

Over the past two years, I’ve gradually learned to think of my TFSA + RRSP + locked-in RRSP + non-registered investments as one big bucket to manage instead of having multiple allocations in multiple accounts. I sold some units (for the first time!) in order to shuffle my allocation around, simplifying my paperwork a little. I still have some duplicates because there’s only so much each account can hold, but ah well. I’ve only ever sold units within tax-sheltered accounts, so I still haven’t gone through the exercise of calculating my adjusted cost base for the e-funds in my non-registered account.

I briefly considered real estate, but I don’t think real estate is the right fit for me (yet? at all?). It’s a big commitment that I don’t know enough about. Sure, there are probably upsides, but there are also scary downsides–especially with Ontario’s tenant laws, which make it difficult to evict people if there are problems.

I’ve also thought about ETFs. After crunching the numbers, I don’t think my portfolio size is large enough to justify switching. I’d probably save a little in fees, but it adds complexity.

For me, the next step is probably to sell a token amount from my non-registered holdings so that I can practice calculating the adjusted cost basis (and so that any tax penalties are also pretty small in case I totally mess up). Slowly leveling up!

Read Lisp Tweak Emacs (Beginner 3/4): How can I make things more convenient?

June 19, 2014 - Categories: emacs
This entry is part 3 of 4 in the series Read Lisp, Tweak Emacs

“How can I customize Emacs to make things more convenient?”

After this module, you’ll be able to:

  • define your own keyboard shortcuts so that you can call functions more easily
  • work with custom functions that other people have defined in their configurations
  • copy and use anonymous functions

Keyboard shortcuts

The default keyboard shortcuts (or “keybindings”) can be difficult to remember, and many useful functions don’t have any keyboard shortcuts at all. People often set up their own keyboard shortcuts to make other commands easier to use. There are different ways to assign keys depending on where you want the keybinding to be available.

Setting keybindings in all buffers

You can assign a key to a function globally, which means that it will be available in buffers of any type if there are no mode maps or local keybindings that override it. (Mode maps are set by major modes like emacs-lisp-mode or minor modes like auto-fill-mode.) Setting a global keybinding is usually done with global-set-key, although sometimes you’ll see it done with define-key and global-map.

You can use global-set-key interactively by calling it with M-x global-set-key. Type the keyboard shortcut you would like to set, then specify the name of the function you would like Emacs to call. Note that the function must be interactive – that is, it must be something you can call with M-x and it should include (interactive ...) in its definition. For example, try M-x global-set-key, then press <f10>, and assign it to save-buffer. After you do that, you should be able to press <f10> to save the current buffer.

If you like a keybinding that you’ve interactively set, use C-x ESC ESC (repeat-complex-command) to see the Emacs Lisp code for it. You can copy and paste that into your configuration. For example, setting the keybinding above will result in:

(global-set-key [f10] (quote save-buffer))

You can also write keybindings from scratch. For example, the code below redefines the Return key (or the Enter key) so that it calls the newline-and-indent function by default.

(global-set-key (kbd "RET") 'newline-and-indent)

Remember, ​'newline-and-indent and (quote newline-and-indent) are the same thing – they both refer to the name of a thing (a function, in this case) instead of its value.

(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)

These set C-+ (Ctrl and <plus>) and C-- (Ctrl and <minus>) to increase and decrease the font size when you’re running Emacs in a graphical environment.

If you want to set a keyboard shortcut only in particular modes or types of files, jump ahead to Setting keybindings in a particular mode.

What does kbd do? How can I figure out which key it sets?

If you’ve gone through the Emacs Tutorial (Help – Emacs Tutorial or C-h t), you’ll be familiar with many of the conventions used for writing keyboard shortcuts. C- stands for the Ctrl key, M- stands for the Meta key (which is probably Alt or Option on your keyboard). There are other prefixes as well. S- is for Shift, H- is for Hyper, and s- is for Super. Some people use operating system tools (such as setxkbmap for Linux) to change keys on their keyboard to Super or Hyper in order to enable even more keyboard shortcuts.

Uppercase or lowercase depends on the character in the shortcut. C-x means Control + x, while C-X is actually Control + Shift + X. You can also specify shift by adding S-, so C-X and C-S-x are the same.

In addition, there are some special characters: RET, SPC, TAB, and ESC must be written in uppercase to mean the special keys they refer to. (There’s also LFD and NUL, but you’re probably not going to encounter those as often.) You can use angle brackets to refer to some other keys, like <return>, <up>, <down>, <left>, <right>. Function keys are written like this: <f1>.

There are different ways to specify the key. Many people use (kbd ...) because it makes bindings easy to read.

(global-set-key (kbd "M-/") 'hippie-expand)

This is the same as

(global-set-key "\M-/" 'hippie-expand)

or

(global-set-key [?\M-/] 'hippie-expand)

You can use ^ to mean Control, so

(global-set-key (kbd "C-s") 'isearch-forward-regexp)

is the same as either of these lines:

(global-set-key "\C-s" 'isearch-forward-regexp)
(global-set-key (kbd "^s") 'isearch-forward-regexp)

but C- is probably easier to read.

When you use kbd, whitespace doesn’t usually matter, but it’s easier to read if you use space to separate the keys to type. For more information about the syntax used by kbd, see C-h f (describe-function) for kbd, then follow the link to the documentation for edmacro-mode.

In general, you can use C-h k (describe-key) followed by a keyboard shortcut to see if it’s already bound, and if so, what function it calls. If you type C-h k and the key you’re interested in, and Emacs is still waiting for another key, then you’re probably looking at a prefix key. For example, C-x is a prefix key that’s used in keyboard shortcuts like C-x C-e (eval-last-sexp).

Multi-key shortcuts

You can set up keybindings that use more than one key combination. This is a popular technique since you can only have so many short keybindings. For example, the following code changes C-x C-b to call ibuffer, which lists your buffers and makes it easy to jump to another buffer.

(global-set-key (kbd "C-x C-b") 'ibuffer)

You don’t have to start with C-c or C-x. Consider using one of your function keys like <f9> as the start of your keyboard shortcuts. Then you can create shortcuts that don’t involve using Ctrl, Alt, or other modifier keys. For example:

(global-set-key (kbd "<f9> b") 'ibuffer)

Read other people’s configurations to get a sense of useful commands and handy keyboard shortcuts. By convention, shortcuts like C-c followed by a lowercase or uppercase letter are reserved for your use, as are the function keys <f5> to <f9>. Other keyboard shortcuts are likely to already be defined by modes. You can override them if you want.

Some people like using a function key followed by letters in order to minimize the need to press Control or Meta. For example, you might use:

(global-set-key (kbd "C-c r") 'query-replace)

or

(global-set-key (kbd "<f9> r") 'query-replace)

to make it easier to replace strings. You can even bind it to both shortcuts.

Binding keys to other keys

In addition to setting keyboard shortcuts for functions, you can also define keys to expand to a longer sequence of keystrokes. You can use this for inserting strings or calling keyboard macros. For example:

(global-set-key (kbd "<f7> e") "[email protected]")
(global-set-key (kbd "<f7> w") "http://example.com")
(global-set-key (kbd "<f7> u") (kbd "C-x C-s"))

These might be handy for quickly inserting your e-mail address or website.

Dealing with errors: “Key sequence __ starts with non-prefix key _

If you want to create a multi-key shortcut, the preceding keys must not already be assigned to functions. For example, if you want M-t l to call transpose-lines, you’ll need to get rid of M-t‘s default binding to transpose-words first. To unset a key, bind it to nil or use global-unset-key. Here’s a group of shortcuts you can try.

(global-set-key (kbd "M-t") nil) ;; Remove the old keybinding
(global-set-key (kbd "M-t c") 'transpose-chars)
(global-set-key (kbd "M-t w") 'transpose-words)
(global-set-key (kbd "M-t t") 'transpose-words)
(global-set-key (kbd "M-t M-t") 'transpose-words)
(global-set-key (kbd "M-t l") 'transpose-lines)
(global-set-key (kbd "M-t e") 'transpose-sexps)
(global-set-key (kbd "M-t s") 'transpose-sentences)
(global-set-key (kbd "M-t p") 'transpose-paragraphs)

The example above has three bindings for transpose-words. M-t w uses the mnemonic of t-ranspose w-ords. M-t t is similar to the original binding for transpose-words, which was M-t. M-t M-t may seem like overkill, but sometimes you’ll find it easier to hold the Meta key down and hit t twice quickly instead of typing M-t, releasing Meta, and then typing t. As you read other people’s keybindings, you’ll get a sense of how people have configured their keyboard shortcuts to speed up typing and minimize thinking.

Setting keybindings in a particular mode

Sometimes you want keys to do different things in different types of files. Modes are how Emacs changes behaviour based on context. For example, Java files use java-mode, Org files use org-mode, and so forth. In addition to the major mode for a buffer, you may have several minor modes that modify the behaviour. Each mode has a keybinding map (or a “keymap”). You can assign a key in a mode map, which means it will override global keybindings in buffers with that mode. You can do this with define-key if you know the name of the keymap you want to change, which is generally the name of the mode + -map. For example:

(define-key emacs-lisp-mode-map (kbd "C-c f") 'find-function)

changes the C-c f keyboard shortcut to find-function (which jumps to the definition of a function), but only in Emacs Lisp buffers.

Note that if you use define-key with a mode map, the mode must already be loaded by the time this code is run. That’s why you’ll often see this after a require (which loads the code) or inside an eval-after-load (which postpones the code until after the mode is loaded). See Adding more features to Emacs for information on loading packages and adding new functions to Emacs.

Other ways people bind keys

The bind-key package provides a function that makes it easier to see your personal keybindings, but bind-key is not part of Emacs by default. I use bind-key a lot in my configuration. The syntax is similar to global-set-key, except it automatically wraps the keyboard shortcut string in kbd. It also keeps track of which keyboard shortcuts you’ve overridden so that you can use M-x describe-personal-keybindings to review them.

(bind-key "C-+" 'text-scale-increase)
(bind-key "C--" 'text-scale-decrease)

You’ll need to install and use the bind-key package before you can use that code.

Because keybinding is something that lots of people do to customize their Emacs, you may find other ways that people have simplified writing keybindings for themselves. When in doubt, use C-h f (describe-function) to explore how something works. If the function can’t be found, see if it’s in a package somewhere, or search the Web for more information.

For more about keybindings, see the Emacs manual and this Mastering Emacs post on keybindings.

Defuns – function definitions

In addition to the functions built into Emacs or available in packages, many people define their own with the defun function.

People often distinguish custom functions by starting them with my/ or their initials. This makes it easier to tell which functions they’ve customized and which ones are part of a package. It also minimizes the risk of accidentally overriding a function defined elsewhere. You can change the name of a function as long as you make sure you change the name wherever it’s called, such as in keyboard shortcuts, hooks, or other functions.

For example, here’s a custom function from Jorgan Schaefer’s config:

(defun fc/kill-to-beginning-of-line ()
  "Kill from the beginning of the line to point."
  (interactive)
  (kill-region (point-at-bol) (point)))

This creates a function called fc/kill-to-beginning-of-line. () is the argument list. Since it doesn’t contain anything, that means this function does not take arguments. ​"Kill from the beginning of the line to point."​ is a documentation string (or docstring) that describes what the function does. Docstrings are optional, but highly recommended. (interactive) means that this can be called with M-x (execute-extended-command) or bound to a keyboard shortcut.

If a function does not have the (interactive) keyword, you won’t be able to call it with M-x or assign it to a keyboard shortcut, but you will still be able to write Emacs Lisp code that calls the function. This means M-x (execute-extended-command) lists only the commands that people will probably find useful while working directly with Emacs, skipping internal functions used by code.

Once you’ve defined a custom function, you can bind it to a keyboard shortcut if you want. The code below binds the fc/kill-to-beginning-of-line function to C-c C-u:

(global-set-key (kbd "C-c C-u") 'fc/kill-to-beginning-of-line)

You will often see custom functions added to hooks. A hook is a list of functions that’s called by some other code. Modes usually define a hook that’s called after the mode is initialized so that you can further customize its behaviours. For example, emacs-lisp-mode has an associated emacs-lisp-mode-hook which is run when a buffer is set up in Emacs Lisp Mode. You can add built-in functions or custom functions to hooks, and they’ll be run when that hook is called.

People sometimes use hook functions to set up keybindings instead of using define-key. For example, this code:

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(define-key emacs-lisp-mode-map (kbd "C-c f") 'find-function)

can also be written as:

(defun my/set-up-emacs-lisp-shortcuts ()
  "Set up some conveniences for Emacs Lisp."
  (turn-on-eldoc-mode)
  (local-set-key (kbd "C-c f") 'find-function))
(add-hook 'emacs-lisp-mode-hook 'my/set-up-emacs-lisp-shortcuts)

Lambdas – anonymous functions

Sometimes people just want to create a keyboard binding or process some data without defining a new function. lambda creates an anonymous function, which is a function that doesn’t have a name. Here’s an example:

(global-set-key (kbd "C-c e") (lambda () (interactive) (find-file "~/.emacs.d/init.el")))

This binds C-c e to an anonymous function. The () means it doesn’t take any arguments. (interactive) means it can be called through a keyboard shortcut, although since it’s anonymous, it can’t be called with M-x. The function opens the ~/.emacs.d/init.el file, which is a handy way to edit your configuration.

  1. Look for an Emacs configuration file that defines keybindings that you’re curious about. Install any packages or copy any custom functions needed. Experiment with using those keybindings. Do you like them? Do you want to tweak them further?
  2. Think about how you use Emacs. What kinds of keyboard shortcuts would make your work easier? How can you adapt some of the functions you’ve read into things that would make them even more convenient for you?
You can find the draft of the complete course at emacslife.com/how-to-read-emacs-lisp.html. Enjoy!

Dealing with the doldrums

June 20, 2014 - Categories: life

I’m not always a cheerful, energetic ray of sunshine. Sometimes I feel meh, too. Whether it’s due to the disruption of routines or momentum, frustration with uncertainty, or factors beyond my control, it happens. During these doldrums, it’s harder to work on creative tasks. It’s harder to move, even. There’s the temptation to spend the time browsing the Web or playing games instead–tempting activities that don’t require a lot of thinking and have a false sense of progress.

Instead of getting stuck–or pretending it doesn’t happen–I’d rather think about how I can hack my way around it. Sometimes it’s good to just relax into it, relying on the buffer from good relationships and good finances. After all, I don’t often give myself permission to take a long afternoon nap, or read fiction, or watch a movie. It can actually be quite satisfying to see things chugging along even if I don’t feel like I’m my usual self. We still keep the house running smoothly, the financial markets still do well. (I hope that if any “meh” periods coincide with market corrections, I’ll have the presence of mind to think, “Oh, stocks are on sale!”)

Sometimes little things I do can dislodge me enough from the Sargasso sea of suckitude. One of the things I find helpful is to think about the difference between how this feels and other ways I’ve felt before. Sure, I might feel meh at the moment, but there have also been moments when I’ve felt awesome, accomplished, productive, energetic, and even smug (in a good way =) ). Thinking about those different feelings helps me remember that meh-ness is temporary, and it also helps me figure out some things I can do that might move me closer to other feelings. For example, I feel awesome when I learn interesting technical things that help me save time or make tools. I feel accomplished when I finish a large batch of cooking or I cross off plenty of items on my TODO list. I feel energetic when I exercise and when I solve problems. I feel an extra burst of smugness when I bike, especially if it’s been raining.

It can be hard to get over that activation threshold, though. Many things that give me that positive buzz are creative in nature (programming, writing, etc.). Fortunately, there are a few activities that I can do even if my mind’s wandering. Walking is a great use of meh-brain time. I feel somewhat proud of myself because of the exercise. I went for a 1.5-hour walk the other day, and that felt much better than sitting at home playing video games. Tidying is another good use of meh-time, and paperwork is like that too. I can practise drawing, too – copying figures or slowly untangling my thoughts.

Writing this, I’m already starting to feel that usual sense of “Actually, things are pretty awesome.” =) I don’t expect myself to be 100% on, and it makes no sense to beat myself up for not being on all the time. But it’s nice to know that the occasional “meh”-ness in my life is temporary, and I can choose to either relax and enjoy it or play around with some ways to nudge myself out of it.

Weekly review: Week ending June 20, 2014

June 22, 2014 - Categories: review, weekly

Much more sleep than average; work, too. Next week, I’ll probably focus on work and exercise. Still taking it relatively easy…

Blog posts

Sketches

Still no scans.

Link round-up

Next week. =)

Focus areas and time review

  • Business (37.2h – 22%)
    • Earn: E1: 2.5-3.5 days of consulting
    • Work on a 4clojure problem
    • Earn (23.4h – 62% of Business)
    • Build (11.0h – 29% of Business)
      • Drawing (2.0h)
      • Delegation (0.0h)
      • Packaging (0.0h)
      • Paperwork (2.8h)
    • Connect (2.8h – 7% of Business)
  • Relationships (1.5h – 0%)
    • Check progress for F2
    • Research real estate
    • Send claim correction along with note to insurance company
  • Discretionary – Productive (12.5h – 7%)
    • Emacs (2.7h – 1% of all)
      • Prep for call with Mickey Petersen
      • Take notes on people who are interested in taking course, process course steps – State “DONE” from “STARTED” [2014-06-12 Thu 20:50]
      • Summarizing the last meeting dates in Org Contacts
      • Take notes on people who are interested in taking course, process course steps
    • Add compost to back garden
    • Lasagna
    • Pizza
    • Writing (4.3h)
  • Discretionary – Play (10.1h – 6%)
  • Personal routines (26.3h – 15%)
  • Unpaid work (16.8h – 10%)
  • Sleep (63.5h – 37% – average of 9.1 per day)

The garden is becoming part of my daily life

June 23, 2014 - Categories: gardening

I’m in the garden almost every day. Almost 40 hours in total since the beginning of April. It’s my new favourite transition activity before dinner. I plant, water, pick off bugs. I’m beginning to learn what leaves feel like when they haven’t gotten enough water and when they have. The oregano, mint, cilantro, basil, and lettuce are growing much better than they did in previous years. None of the snow peas have made it indoors yet, since I’ve been eating them off the vine. The tomatoes, zucchini, winter melons, and bitter melons haven’t hit their stride yet, but maybe during the hotter months.

I like filling the salad spinner with cut-and-come-again leaves. I should let some of the plants go to seed so that I can collect them for the next batch, but it’s too tempting to snip off the flowers in order to keep the current batch going. I planted a salad mix, so I have no idea what some of these are. I know bok choy, spinach, arugula. Peppery and red-veined? Probably beet greens. I’m relying on frequency here. If there’s a lot of a type of plant, it grows in a somewhat regular formation, and I don’t already conclusively know it’s a weed, it’s probably okay to eat. So far, so good.

I have salad every other day or so. Today I had three small bowls of salad all by myself (W- had the other bowl). I shook up a quick Asian-style dressing in a small mason jar and sprinkled sesame seeds on top. We don’t normally buy those boxes of salad mix, since I feel guilty about not finishing them before they have to go. If it’s still growing, I don’t mind, although I try to harvest leaves before the slugs and leaf-miners get to them.

The salad garden is doing so much better this year compared to last year. Frequent watering and frequent harvesting, that’s probably the ticket. I should make pesto this week. Maybe Wednesday. Basil likes being harvested often, too. =) I’ve been picking flowers off every day, but there are definitely enough leaves here to make a good-sized batch of pesto.

Nom nom nom nom nom…

I notice I have cyclic interests

June 24, 2014 - Categories: learning

I learn about some topics in sprints, then let them go for a bit, and then come back to them. For example, my time logs for Emacs show:

  • June 2012
  • Mid-March to mid-April 2013
  • April-June 2014

2014-06-23 20_42_29-Emacs - quantified awesome

Oh. Actually, that’s an interestingly seasonal pattern. I hadn’t realized that the months lined up like that. (Although to be fair, I probably wasn’t tracking it as a category before May 2012, and it’s only very roughly lined up.) I wonder what it is…

Anyway, I feel myself shifting temporarily to other things. I know I’ll be back, but it’s just not at the forefront of my mind.

What am I thinking about instead? What am I learning more about? What am I spending more time on? Oh, the sparklines are surprisingly useful. I can just scroll down looking for patterns. Non-Emacs coding, apparently. Learning about other things. Playing video games, relaxing. Gardening. I’m spending nowhere near as much time biking as I used to, but I do spend more time walking.

Where would I like to direct my shifting interests and attention? I want to focus on building solid habits around health and fitness. That’s probably 15-30 minutes of exercise a day and preparing even better food (salads, variety). Once I’ve internalized those, I think I might circle back to Latin (I can mostly remember the declensions now, although I still make errors), and maybe either Japanese (so I can read and listen) or Cantonese (so that I can chat with W- and with the fellow gardener up the street). There’s drawing practice, too. Time to swing non-technical or non-computer-based for a bit? Hmm…

Fortunately, taking lots of notes along the way helps. I’m sure I’ll be back to this someday!

This is the year I’m going to build an exercise habit

June 25, 2014 - Categories: life

This year, I am going to become the sort of person who exercises regularly. I’m not particularly concerned about reaching a certain weight, but I’d like to improve my strength and endurance. W- is helping me ease into the learn-to-run program he did at work. I’m also starting from the first rung on the fitness ladder from The Hacker’s Diet. Small activities like these don’t take a lot of time, and the gradual progression will help me build confidence.

I’d also like to turn more exercise activities into ones that W- and I can share. Krav maga isn’t my cup of tea, but I think I’ll like jogging and walking with W-. We can stretch or do some weight-training while watching videos. Biking is fun, too.

What does making fitness part of me mean? I think it means being in tune with how things work, paying attention to the details and the changes. It’s probably like the way daily gardening has changed my experience of the backyard compared to when I dabbled in it. I’m looking forward to trying more things and learning more.

Identity is a big factor when it comes to maintaining good habits. When you make something part of who you are, it’s easier to keep doing it, and it’s harder to neglect it. Here are some of the other identity changes I’ve gone through:

  • I changed from someone who takes transit all the time to someone who bikes whenever she can.
  • I changed from someone who hated writing for school to someone who enjoys writing for this blog.
  • I changed from someone who grew up around household staff (cook, maids) to someone who cooks practically all her meals and takes care of her own chores.

I have the time, space, and support I need, and it’s good for me. I can see the results of good habits and the consequences of poor ones. And I’m going to do it without gym memberships or other things like that. We already have all the tools I need, so I just have to do it. =)

Read Lisp, Tweak Emacs (Beginner 4/4): “How can I add more features? How do I deal with errors?”

June 26, 2014 - Categories: emacs
This entry is part 4 of 4 in the series Read Lisp, Tweak Emacs

Previous module: “How can I make things more convenient?”

Some conventions we’ll use:

  • Inline code will be boxed and monospace in the HTML version and generally surrounded by equal signs in plain text.
  • Code samples will be monospace and in boxes in the HTML version, and enclosed in #+begin_src#+end_src in plain text. Example:
    (message "Hello world")
    

After this module, you’ll be able to:

  • load libraries so that you can add new features or set configuration variables
  • install and configure packages in order to add more features to your Emacs
  • understand and fix common errors
  • learn more! =)

Adding more features to Emacs

Most Emacs libraries are not loaded automatically. This saves memory and keeps things simpler. Some of the customizations you may want to make require that other parts of Emacs are loaded first. For example, if you want to define a key for the c-mode-map (used for editing C code) or add a function to org-mode-hook (called when a buffer is set up with Org Mode), those libraries need to be loaded first. You can load libraries by using require, like this:

(require 'org)

This loads the org library. require looks for a file named after the name provided to it, loads it, and double-checks that the library includes (provide 'feature-name-goes-here). It signals a Cannot open load file error if the library is not found. If the library exists but does not provide that symbol, you’ll get a Required feature FEATURE was not provided error instead.

Note that the symbol you give to require might not be the same as the function you call. For example, c-mode is actually defined in the cc-mode library, while org-mode is defined in org. To find out what file a function is defined in, use C-h f (describe-function) followed by the name of the function. The first line will tell you what file the function is defined in, if any. For example, c-mode‘s definition starts with:

c-mode is an interactive autoloaded compiled Lisp function in
`cc-mode.el'.

The first part of the filename (before the .el or .elc) is usually what you would use with require. If you have the source installed (the .el file), you can look for the (provide ...) expression to find the actual symbol to use.

Installing packages

Emacs comes with a lot of code, but there are even more packages out there. When you read other people’s Emacs configurations, you might come across other interesting packages to try out.

Sometimes people don’t indicate which packages they use, so you have to guess the package name based on the function. For example, (global-auto-complete-mode) turns on a completion mode called auto-complete-mode in all buffers. Before you can use this, you will need to install the auto-complete package. In general, you can find package names by looking at functions that include mode in their name, removing global, turn-on, and other prefixes as needed.

The default package repository in Emacs 24 has a limited number of packages. For more choices, you may want to add another repository such as MELPA or Marmalade Here’s the code that you would run in order to add these repositories to your Emacs:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))

Note that MELPA includes many packages under active development. If you prefer to install only the packages marked as stable, replace the MELPA line with this:

(add-to-list 'package-archives '("melpa-stable" . "http://hiddencameras.milkbox.net/packages/"))

If you’re connected to the Internet, use M-x package-refresh-contents to update the list of packages. Use M-x package-list-packages to list the available packages. RET displays the package’s description. i marks the current package for installation, and x actually performs the operations. If you know the name of the package you want to install, you can skip the list and use M-x package-install instead.

A lightweight list of the key functions defined by packages is loaded after your init.el is run. You can start that initialization earlier by adding (package-initialize), which is useful if you want to call functions that are defined in packages.

Sometimes people want to install some packages on one computer but not on another. Here’s some code that runs some configuration if the miniedit package can be loaded, but silently continues if the package has not been installed.

(when (require 'miniedit nil t)
   (miniedit-install)
   (define-key minibuffer-local-map (kbd "C-c e") 'miniedit))

If you use C-h f (describe-function) on require, you’ll see that it has one required argument (feature) and two optional arguments (filename, noerror). require returns non-nil (or true) if the library was loaded, so if the library exists, then the rest of the code inside the when expression gets called.

Along those lines, you may come across code that looks like this:

(eval-after-load "dash" 
  '(dash-enable-font-lock))

This runs (dash-enable-font-lock) only after dash is loaded. It does not automatically load dash. You’ll see this when people have configuration that they want to run only if something is loaded, which can make sense for performance reasons. When you’re starting out, you may want to use require instead of eval-after-load, since the argument to eval-after-load has to be quoted.

Other Emacs Lisp files

Some files are not yet available as packages. If you search for the function, you’ll probably find a webpage with an .el file. You can save those to your computer and load them with:

(load "/path/to/file")

You can also use this technique to split up your Emacs configuration file into smaller files. For example, you might have an org-config.el file, a programming-config.el file, and so forth. If you would like to load a host-specific file only if it exists, you can take advantage of the optional NOERROR argument for load like this:

(load (concat "~/.emacs.d/" (system-name) ".el") t)

Want to find out what that filename is? Position your cursor after the ​".el") and use C-x C-e (eval-last-sexp) to see the value in the buffer.

Use C-h f (describe-function) to learn more about the load function, including other arguments you can pass to it.

If you would like to use the require syntax to load files only if they haven’t already been loaded, you can do that as long as they include the (provide ...) expression somewhere. First, you’ll need to add your downloaded Emacs Lisp file to the load-path with something like this.

(add-to-list 'load-path "/path/to/dir/with/el/files")

Then you can use require to load the Emacs Lisp code if it exists.

(require 'feature-name)

“Oh no! I have an error!”

Part of learning Emacs is having the confidence to experiment, which you can develop by learning how to recognize and deal with different errors.

If you’ve already added the code to your ~/.emacs.d/init.el, you can start Emacs with emacs --debug-init to display debugging messages, or you can start Emacs with emacs -q to skip your personal configuration. Before reporting a bug with Emacs or with a package, use emacs -q (or emacs -Q, which skips site-wide configuration as well) to see if it works as intended without your personal configuration.

To make it easier to find errors while Emacs is running, use M-x toggle-debug-on-error, then do whatever you did to trigger the error. You will probably see a detailed list of functions called in the *Messages* buffer. If you find this useful, you can enable this by default in your ~/.emacs.d/init.el. Add:

(setq debug-on-error t)

If you have code that takes a while, you might find the debug-on-quit variable or the M-x toggle-debug-on-quit function useful as well. You can quit a long-running operation by using C-g (keyboard-quit).

You can narrow down the source of the problem by progressively commenting out more and more of the code. Make sure you comment out balanced sets of parentheses. To comment a region, select it and use M-x comment-region. You can use M-x uncomment-region to uncomment it. M-x comment-dwim (do what I mean) guesses whether you want to comment or uncomment something, and has the handy keyboard shortcut M-;.

Here are some common error messages and how you can try fixing them. If you don’t see the error you’re struggling with here, ask the relevant mailing list, help-gnu-emacs, the #emacs channel on irc.freenode.net, or StackOverflow for help. Good luck!

Scan error: “Unbalanced parentheses” or “Containing expression ends prematurely”

You may have pasted in something that has a “(” but no matching “)“, which results in unbalanced parentheses. Alternatively, you may have pasted in something that has “)” but no “(“, which results in a premature end. You can use M-x check-parens to quickly check for mismatched parentheses, or try reading the code carefully in order to find the mismatched pair. You can also use C-M-f (forward-sexp) and C-M-b (backward-sexp) to navigate by complete expressions until you find the specific one that causes the error.

Cannot open load file: …

The code is trying to require or load a file that Emacs can’t find.

  • Have you installed the appropriate package? Use M-x list-packages to see if it has been packaged into a form that’s easy to install. You may need to add other sources to your package-archives to see a wider range of packages.
  • Have you downloaded it manually and added it to your load-path? See the notes on load-path for more details.
  • If you’re using load, does the file exist?

Lisp error: (void-function …)

The code calls a function that has not been defined.

  • Have you installed the appropriate package? Look at the function name and try to guess the name of the package. People usually start the function name with the package name in order to make the function names unique. Use M-x list-packages to see the available packages. You may need to add other sources to your package-archives to see a wider range of packages.
  • If you downloaded the library manually, load or require it.
  • If you’re copying some code that isn’t packaged in a library, check if there are any defun (define function) expressions that you forgot to copy. Make sure to include and evaluate those.

Symbol’s value as variable is void: _

The code is trying to get the value of a variable that has not yet been set. See if there’s other code that you need to evaluate first in order to set up those variables. If the expression involves add-to-list or add-hook, you may need to use require to load the library that defines that list or hook first.

You might also get this if you’re using C-x C-e (eval-last-sexp) to evaluate an expression that’s inside let or other things that create variables. When you’re starting out, make sure you use C-x C-e (eval-last-sexp) after the outermost set of parentheses.

I’m using C-x C-e (eval-last-sexp) and I don’t get the results I expected

Make sure you call C-x C-e after the outermost ) for the expression you want to evaluate.

(ido-mode 1)
            ^
            |
            +---- Your cursor should be here

If the code you’re looking at has multiple expressions, you’ll need to call C-x C-e after each of them. It might be easier to select the region and use M-x eval-region, or evaluate the entire buffer with M-x eval-buffer. Alternatively, use M-x ielm to evaluate the code instead.

Again, if you don’t see the error you’re struggling with here, ask the relevant mailing list, help-gnu-emacs, the #emacs channel on irc.freenode.net, or StackOverflow for help. Good luck!

Wrapping up the beginner course

I hope that this course has helped you become more comfortable with reading and tweaking Emacs Lisp configuration code from blog posts, wiki pages, and other resources. There’s much more to learn, of course. With describe-function, describe-variable, and the ability to quickly experiment with Emacs Lisp code without restarting Emacs all the time, I’m sure you’ll get the hang of it! If you’d like to review or refer to this course, you can get it as one page at http://emacslife.com/how-to-read-emacs-lisp.html .

Check out An Introduction to Programming in Emacs Lisp, and delve into the Emacs Lisp Reference Manual for more details. Both are available within Emacs as Info manuals, which you can read with C-h i (info). Look for the Emacs Lisp Intro and Elisp entries, and browse through those manuals for more details. To search the current info manuals, type s (Info-search). To search all info manuals, use M-x info-apropos.

If you liked this or you have other questions, please get in touch – [email protected]. I’d love to hear from you, and I’m happy to help with other Emacs questions you may have. Good luck and have fun!

More links:

A long, long weekend

June 28, 2014 - Categories: life

How do I want to spend my leisure time? I’ve been thinking about that a bit because we have a long weekend, and I have much more discretionary time during the week than most people do.

W- and I are both homebodies. During normal weekends, we typically spend a day focused on cooking, cleaning, washing clothes, and taking care of other little things around the house. That still leaves some time for walks, gardening, reading, writing, and watching the videos that we borrow from the library. During long weekends, we usually take advantage of the extra time and energy by working on household projects or doing a deeper clean. W- tends to work long hours, so when he’s not busy with work or gym classes, I prefer to spend the time with him instead of hanging out with other friends. Life is short, after all.

I also have some time during the week, when most people are busy working. I’ve been using that time to read, learn, exercise, and explore. From time to time, I hang out with friends. Last Friday, two of my friends were hanging out at a park, so I decided to join them. It was a leisurely afternoon of sunshine, idle conversation, and ice cream. In the evening, we watched a movie which turned out to be free because of projector issues.

I’m not always keen on conversation, so I don’t particularly like scheduling things and I can be reluctant to meet up or chat. If I can guiltlessly change plans – to wander in and out as I want – I feel much better about it.

Then there’s discretionary time when I’m alone, too. I usually spend this reading, coding, writing, or drawing. I’ve been feeling a little scattered lately. It’s hard to latch onto a question and follow it. Focusing on building habits around exercise and gardening seems to be helping, and exploring recipes is fun too. Fortunately, there’s a lot to keep making slow progress on while cultivating curiosity…

Weekly review: Week ending June 27, 2014

June 29, 2014 - Categories: review, weekly

Blog posts

Sketches

I’m getting quite dreadful at this scanning-in thing. It’s probably because it’s so sunny out that I rarely want to go down to the basement these days… Perhaps tomorrow!

Link round-up

Focus areas and time review

  • Business (26.6h – 15%)
    • Earn (16.0h – 60% of Business)
      • E1: Attend meeting
      • Earn: E1: 2.5-3.5 days of consulting
    • Build (6.2h – 23% of Business)
      • Work on a 4clojure problem
      • Work on a 4clojure problem
      • Drawing (3.2h)
      • Delegation (0.0h)
      • Packaging (0.0h)
      • Paperwork (0.0h)
    • Connect (4.3h – 16% of Business)
  • Relationships (11.9h – 7%)
    • Pick up lead testing kit
    • Send claim correction along with note to insurance company
  • Discretionary – Productive (8.5h – 5%)
    • Emacs (0.0h – 0% of all)
      • Take notes on people who are interested in taking course, process course steps
    • Harvest more greens; clear out a square
    • Writing (3.5h)
  • Discretionary – Play (6.6h – 3%)
  • Personal routines (34.1h – 20%)
  • Unpaid work (9.5h – 5%)
  • Sleep (70.9h – 42% – average of 10.1 per day)

Reflections on Aristotle, ends, and leisure

June 30, 2014 - Categories: life, reflection

What are the ends I pursue, and how do I pursue them?

I agree with Aristotle in that my ultimate end is happiness. For me, happiness is more along the lines of equanimity or tranquility: being able to appreciate the good parts and being confident that I can weather the tough parts. From stoicism, I understand that things aren’t good or bad in themselves; it’s more about my responses to those things. So for me, a good life is one where I can respond as I want to and as I should.

More specifically, what would that good life look like, and what are the goals I want to strive towards?

One easy goal to plan for is a good financial foundation. It’s easier to act freely when you’re not worried about food or shelter. I also work on keeping frugal, moderate tastes and a detachment from things. “It’s just stuff,” W- and I say as we drop things off for donation or resist buying more things.

I value learning, too. I like feeling concepts click together, learning how to build more complex things. I particularly like it when I can use what I’m learning to save time, especially when I help other people avoid repetitive, mechanical work.

I enjoy learning and working the most when I can create something distinctive that takes advantage of an unusual combination of skills or experiences. For example, I like the social business consulting that I do because it’s uncommon for people to be interested in large organizations, collaboration, workflow, change management, data visualization, programming, and design. I enjoy working on Emacs or on self-tracking because both lend themselves well to idiosyncratic questions and personal curiosities.

I’ve been self-consciously writing about leisure for what feels like too many days now. I’m trying to figure out how I want to spend my time, since that’s a decision I’m going to make repeatedly over decades. My answers will change over the years, too, but if I think about it a little, I might be able to make better decisions.

Most of the time, we think of relaxation and recreation as ways to recharge ourselves so that we can get back to work with more energy. Aristotle prizes the contemplative life, where you use your leisure time not just to amuse yourself, but to improve.

What does that mean to me, though? For example, I could spend some time learning languages, or developing my drawing skills, or picking up a new technology. There’s so much more to learn about all sorts of other subjects. An easy answer to the question “What shall I do with my time?” might be to volunteer, but I would also want to do that with deliberation. What will help me grow, and what’s just a nice-to-have?

Let’s say that I don’t know enough to choose those topics from the beginning. How can I get better at observing myself and learning from how I use my leisure time? What would make a difference when I look back over a long life?

One of the things that has helped me a lot and that I’d like to get very good at is the ability to notice (as the Less Wrong community phrases it) that I am confused, and to explore that confusion. Reading helps me notice the gaps and find words to describe things, and writing helps me start to untangle the knots. If I keep getting better at this, then when I’m much more experienced, I might be able to spot opportunities for growth, catch myself before I make mistakes, and also help friends think through their own lives.

Learning various skills (tech, DIY, cooking) helps improve my self-efficacy. I can make more things myself, and I can imagine more things too. Besides, it’s fun, and occasionally economically useful.

I’m still not as keen on conversation and friendship as I probably should be, at least according to Aristotle. I enjoy conversations with W- most of all. I like the mix of practicality, growth, and whimsical puns. On occasion, I enjoy conversations with other people, especially those I think well of and want to support. Other times, I talk to people for variety and social exercise. I’m comfortable with that because I’m not trying to be popular, entertaining, or entertained. I don’t mind taking my time with the slow collection of interesting people I can learn from and help.

I can use my leisure time to learn how to prefer things that are good for me. For example, I’m working on that exercise habit. I’m sure that once I’ve gotten into the swing of things, I’ll be able to enjoy it – I just have to stick it out until then. I have much to learn about music, art, design, and literature, too.

I think a good life is one where I have the space, awareness, and control to respond to life the way I want to, and that I’ve learned to want what’s good for me. I’d like to be able to say, looking back, that I’ve deliberated on how I wanted to live and that I’ve lived pretty darn close to what I decided. We’ll just have to see how it all works out!