6085 comments
2357 subscribers
6224 on Twitter
Subscribe! Feed reader E-mail

Reading these posts, you can probably tell that I really, really like the Emacs text editor.

View my Emacs configuration.

Check out Planet Emacsen to read other Emacs geeks’ blogs. For all things Emacs, check out the EmacsWiki.

On this page:

zomg, Evernote and Emacs

This is totally raw and needs a lot of hacking, but look, I can dump subtrees from my Org notes into Evernote using Emacs Evernote Mode. The desktop app handles these perfectly, although the Android app does funny things to the whitespace if you edit the note. Still, great as a reference!

Mwahahahaha!

(defun sacha/org-get-subtree-region ()
  "Return the start and end of the current subtree."
  (save-excursion
    (let (beg end folded (beg0 (point)))
      (if (org-called-interactively-p 'any)
          (org-back-to-heading nil) ; take what looks like a subtree
        (org-back-to-heading t)) ; take what is really there
      (org-back-over-empty-lines)
      (setq beg (point))
      (skip-chars-forward " \t\r\n")
      (save-match-data
        (save-excursion (outline-end-of-heading)
                        (setq folded (outline-invisible-p)))
        (condition-case nil
            (org-forward-same-level (1- n) t)
          (error nil))
        (org-end-of-subtree t t))
      (org-back-over-empty-lines)
      (setq end (point))
      (list beg end))))

(defun sacha/org-post-subtree-to-evernote (&optional notebook)
  "Post the current subtree to Evernote."
  (interactive)
  (let ((title (nth 4 (org-heading-components)))
        (body (apply 'buffer-substring-no-properties (sacha/org-get-subtree-region))))
    (with-temp-buffer
      (insert body)
      (enh-command-with-auth
       (let (note-attr)
         (setq note-attr
               (enh-command-create-note (current-buffer)
                                        title
                                        notebook
                                        nil "TEXT"))
         (enh-update-note-and-new-tag-attrs note-attr))))))       

In other news, I now have book notes from 156 books in my Evernote notebook. Mwahahaha! Time to add more.

Short URL: http://sachachua.com/blog/p/23622

Transcript: Emacs chat with John Wiegley

This post is long, so if you’re reading this on the main page, go to http://sachachua.com/blog/2012/07/transcript-emacs-chat-john-wiegley/ to view the full transcript!

[Read more →]

Short URL: http://sachachua.com/blog/p/23536

Emacs: Chatting with John Wiegley about the cool things he does with Emacs

John Wiegley – June 26, 2012 from Sacha Chua on Vimeo.

Transcript: http://sachachua.com/blog/2012/07/transcript-emacs-chat-john-wiegley/

Read more context for John Wiegley’s thoughts on the GPL. Note from Sacha: The WordPress folks seem to have figured out how to earn money with premium themes, plugins, and training, so it’s not incompatible with the GPL… =)

John Wiegley is one of my Emacs heroes. =) Check out John’s Emacs configuration and other tools on Github. John occasionally posts Emacs-related things at newartisans.com. You can find him on Twitter as @jwiegley. Enjoy!

Short URL: http://sachachua.com/blog/p/23526

Making GNU Emacs play well on Microsoft Windows 7

Emacs 24 has been released, hooray! Here’s how you can download and install it on Windows 7. Bonus tip: pin it to your taskbar so that you can open Emacs easily.

Step 1. Get the Emacs zip file from http://ftp.gnu.org/pub/gnu/emacs/windows/ . You’re looking for something like emacs-24.1-bin-i386.zip, or whatever the latest version is. Download and extract the files. I like extracting it to C:\ and renaming the new emacs-24.1 directory to c:\emacs so that I can get to it easily. I’ll assume you’re renaming it too, but if you prefer to keep your Emacs installation elsewhere, just translate the rest of these instructions.

Step 2. Add Emacs to your path. This way, you can start Emacs or emacsclient from anywhere. To change your system path, click on the Windows logo, right-click on Computer, and choose Properties. Click on Advanced system settings, then click on Environment Variables.

If you see a Path variable under User variables, click on it, then click on Edit. Add c:\emacs\bin to the beginning of this path, separating it from the next item with a semicolon. Click OK.

On the other hand, if you don’t see a Path variable under User variables, click on New and add it. The variable name should be Path and the value should be c:\emacs\bin. Click OK.

Step 3. While you’re here, you might as well set your Home variable. This is what Emacs will use whenever you refer to ~, or the home directory. To set that, look under User variables and click on New. Create a variable called HOME, and set the value to whichever directory you would like to use as your home directory. For example, I’ll set mine to c:\sacha. Again, click on OK, then click OK a few more times until you’re done with the System Properties dialog box.

Step 4. All right, let’s start up Emacs! Click on the Windows icon, and type runemacs at the Run prompt. You should see runemacs in the list. If you don’t, you may need to log out and log in so that your new path settings are applied. Once you’ve sorted that out, start runemacs. You should see Emacs open, yay!

Step 5. Want to be able to start up and switch to Emacs quickly? To pin Emacs to your task bar, right-click on the Emacs icon in the task bar. Right-click on the small Emacs icon that appears, and click on Properties. Change the target to c:\emacs\bin\runemacs.exe, and change the start directory to whichever directory you prefer. You can also choose to start it maximized – handy. Once you’ve set that up, click OK. I like dragging the Emacs icon so that it’s the very first item in my task bar. That way, pressing the Windows key and the number 1 at the same time lets me switch to Emacs and away from Emacs easily.

That’s it. Check out http://planet.emacsen.org for lots of other Emacs bloggers. Happy editing!

Short URL: http://sachachua.com/blog/p/23513

Emacs braindump from John Wiegley =)

I’m going to edit and post my Skype chat with John Wiegley, but here are some quick notes:

  • Read Emacswiki and go through the package lists to find cool stuff
  • Learn the Emacs way of doing things (keybindings, etc.)
  • paredit
  • redshank
  • helm
  • ace-jump
  • color-moccur
  • use-package
  • async?

Looks like Camtasia Studio 8 grabbed the video just fine, so I’ll work on editing it tomorrow. Whee! I totally have to chat with other Emacs geeks about their config and their projects – it’s such a different experience from just reading people’s configuration files or chatting on IRC…

Short URL: http://sachachua.com/blog/p/23508

Using Emacs Org for grocery lists and batch cooking

We like preparing our meals in bulk. Buying groceries and cooking up a storm on the weekends means that we can grab quick and healthy lunches from the fridge or freezer, enjoy a variety of dinners during the week, and focus on other things that we want to do in the evenings.

I was looking for a menu planner and grocery list maker to help us plan and execute these batch cooking sessions more efficiently. In particular, I wanted something that could sort the ingredients for preparation, too. I like preparing ingredients for all the different recipes before I start cooking. If several recipes call for garlic, I might as well chop a lot of garlic in one session instead of breaking out the chopping board for each recipe.

I tried several menu planning and grocery list apps, but I wasn’t happy with any of the ones I came across. I like using Emacs for as much as possible, so I figured that I should give it a try. Here’s what I did and how it worked out.

I created an Org file for my recipes. In this plain-text outline, I created sections for my plan, shopping list, preparation tasks, and recipes. Under recipes, I created TODO items and scheduled them. Here’s an example entry:

** TODO Colorful bulgur salad
   SCHEDULED: <2012-06-19 Tue>

http://allrecipes.com/recipe/colorful-bulgur-salad/

| 1/2 cup        | bulgur wheat     |                    | [[Colorful bulgur salad]] |
| 1/2 cup        | chicken broth    |                    | [[Colorful bulgur salad]] |
| 1 small        | cucumber         | seeded and chopped | [[Colorful bulgur salad]] |
| 1              | tomato           | chopped            | [[Colorful bulgur salad]] |
| 1              | carrot           | shredded           | [[Colorful bulgur salad]] |
| 3              | green onions     | thinly sliced      | [[Colorful bulgur salad]] |
| 3 tablespoons  | fresh lime juice |                    | [[Colorful bulgur salad]] |
| 3/4 tablespoon | chili powder     |                    | [[Colorful bulgur salad]] |
| 1 pinch        | garlic powder    |                    | [[Colorful bulgur salad]] |

I reformatted each recipe to fit this format, with columns for quantity, type, preparation, and recipe link. After I chose several recipes, I copied the ingredient lists into my preparation section and my shopping section. In the shopping section, I deleted the lines for ingredients I already had or could skip. I used org-table-sort-lines to sort the table by the second column, which gave me this list:

| 1 bag              | chicken legs and thighs |                                                        | [[Arroz caldo]] |
| 2 small or 1 large | cucumber                | chopped                                                | [[Gazpacho]] |
| 1 small            | cucumber                | seeded and chopped                                     | [[Colorful bulgur salad]] |
| 3                  | green onions            | thinly sliced                                          | [[Colorful bulgur salad]] |
| 1                  | red onion               | cut into 1" pieces                                     | [[Shrimp kebabs]] |
| 1 pound            | shrimp                  | peeled and deveined                                    | [[Shrimp kebabs]] |
| 6 - 8              | tomatoes                | chopped (Roma or plum are best; Don't lose the juice!) | [[Gazpacho]] |
| 1                  | zucchini                | seeded and cut into 1" pieces                          | [[Shrimp kebabs]] |

It wasn’t sorted by aisle, but that was easy to do when I copied the list onto a recycled envelope. If I find myself using this a lot, I might write an Emacs Lisp function to gather the tables and sort the rows by aisle.

Anyway, shopping list in hand, we picked up our groceries in about ten minutes last Saturday. The next day, I looked at my prep list:

|                    | basil                                  | chopped                                                | [[Gazpacho]]              |
| 1/2 cup            | bulgur wheat                           |                                                        | [[Colorful bulgur salad]] |
| 1 tbsp             | butter                                 |                                                        | [[Bubble and squeak]]     |
| 2 tbsp             | canola or peanut oil                   |                                                        | [[Teriyaki tofu]]         |
| 1                  | carrot                                 | shredded                                               | [[Colorful bulgur salad]] |
| 1/2 cup            | chicken broth                          |                                                        | [[Colorful bulgur salad]] |
| 1 bag              | chicken legs and thighs                | separated                                              | [[Arroz caldo]]           |
| 3/4 tablespoon     | chili powder                           |                                                        | [[Colorful bulgur salad]] |
| 1/4 cup            | cider vinegar                          |                                                        | [[Teriyaki tofu]]         |
| 1 can              | corned beef                            |                                                        | [[Bubble and squeak]]     |
| 3 tbsp             | cornstarch                             |                                                        | [[Teriyaki tofu]]         |
| 1 tbsp             | cornstarch                             |                                                        | [[Teriyaki tofu]]         |
| 1 small            | cucumber                               | seeded and chopped                                     | [[Colorful bulgur salad]] |
| 2 small or 1 large | cucumber                               | chopped                                                | [[Gazpacho]]              |
| 1 lb               | firm tofu                              | drained                                                | [[Teriyaki tofu]]         |
|                    | fresh ground black pepper              |                                                        | [[Gazpacho]]              |
| 3 tablespoons      | fresh lime juice                       |                                                        | [[Colorful bulgur salad]] |
| 3 cloves           | garlic                                 | chopped                                                | [[Arroz caldo]]           |
| 1 clove            | garlic                                 | minced                                                 | [[Teriyaki tofu]]         |
| 2 cloves           | garlic                                 | diced                                                  | [[Gazpacho]]              |
| 1 tablespoon       | garlic                                 | minced                                                 | [[Shrimp kebabs]]         |
| 1 pinch            | garlic powder                          |                                                        | [[Colorful bulgur salad]] |
|                    | glutinous rice                         |                                                        | [[Arroz caldo]]           |
| 1 tsp ginger       | grated or minced                       |                                                        | [[Teriyaki tofu]]         |
|                    | green onions                           | chopped                                                | [[Arroz caldo]]           |
| 3                  | green onions                           | thinly sliced                                          | [[Colorful bulgur salad]] |
|                    | leftover vegetables (cabbage, carrots) |                                                        | [[Bubble and squeak]]     |
| 1                  | lemon                                  | juice of                                               | [[Gazpacho]]              |
| 2 teaspoons        | lemon juice                            |                                                        | [[Shrimp kebabs]]         |
| 1/4 cup            | olive oil                              |                                                        | [[Shrimp kebabs]]         |
| 1                  | onion                                  | thinly sliced                                          | [[Bubble and squeak]]     |
| 1/2 large          | onion                                  | chopped finely       (red is a nice alternative)       | [[Gazpacho]]              |
| 1/2 large          | onion                                  | chopped in 1/4 inch chunks                             | [[Gazpacho]]              |
| pinch              | parsley                                | finely chopped                                         | [[Shrimp kebabs]]         |
| 1/4 tsp            | pepper                                 |                                                        | [[Teriyaki tofu]]         |
| 1/4 teaspoon       | pepper                                 |                                                        | [[Shrimp kebabs]]         |
| 3 cups             | potatoes                               | mashed                                                 | [[Bubble and squeak]]     |
| 1                  | red onion                              | cut into 1" pieces                                     | [[Shrimp kebabs]]         |
|                    | salt (preferably sea salt)             |                                                        | [[Gazpacho]]              |
| 1 tsp              | sesame oil                             |                                                        | [[Teriyaki tofu]]         |
| 1 pound            | shrimp                                 | peeled and deveined                                    | [[Shrimp kebabs]]         |
|                    | soy sauce                              |                                                        | [[Arroz caldo]]           |
| 1/2 cup            | soy sauce                              |                                                        | [[Teriyaki tofu]]         |
| 1                  | tomato                                 | chopped                                                | [[Colorful bulgur salad]] |
| 6 - 8              | tomatoes                               | chopped (Roma or plum are best; Don't lose the juice!) | [[Gazpacho]]              |
|                    | virgin olive oil                       |                                                        | [[Gazpacho]]              |
| 1/2 cup            | white sugar                            |                                                        | [[Teriyaki tofu]]         |
| 1                  | zucchini                               | seeded and cut into 1" pieces                          | [[Shrimp kebabs]]         |

Sorting the list by ingredient made it easy to go through the groups of ingredients and prepare them all, and the links to the recipes made it easy to look up next steps. I planned the order of doing them. First, I prepared the bulgur wheat because that needed an hour to soak. I saved the chicken legs for the end because they were messy, and I saved the onions for later as well because they always make me cry. I cut and chopped and food-processed my way through stacks of vegetables, covering the kitchen table with bowls.

With all the ingredients prepared, I washed the utensils and put things away. That freed up counter space for cooking. I reordered the recipes so that it was easy to see what to work on next, and I started cooking.

The entire cooking sprint took me 5 hours and 42 minutes, which was a lot of cooking but well worth it. With that and the meals we’d prepared over the past few weeks, our freezer’s stuffed to capacity. Four tidy stacks of identical food containers, then odds and ends crammed into the spaces! By golly.

I really liked planning this batch cooking session in Emacs. Org tables made things easy to sort, and the hyperlinks let me look up recipes and notes quickly.

I could probably make this even better by:

  • rigging up my foot pedal to scroll up and down through food.org
  • copying in the recipe steps so that I can take advantage of that scrolling
  • figuring out how to use Org Babel to automatically compile the ingredient tables for the named recipes

Now if only someone would write M-x wash-dishes

Short URL: http://sachachua.com/blog/p/23504

Things that I’ve used Emacs for

Emacs can do a ton thanks to the code that people have contributed over the decades. Here’s a list of things I’ve used Emacs for, although I’m sure I’ve still missed a few!

  • Taking notes
    • Storing reference information
    • Publishing blog posts
  • Programming / coding
    • Rails
    • PHP / Drupal
    • Java
    • Javascript
    • HTML / HAML / ERB
    • CSS / Sass
    • Emacs Lisp
    • Ruby
    • Perl
    • SQL
    • Bash scripts
  • Managing my to-do list
  • Timing tasks
  • Managing my finances
  • Studying
    • Dictionary (Japanese)
    • Flashcards
      • With random fortunes displayed for correct answers
      • With random images displayed for correct answers (cute kittens!)
    • Example sentences lookup (Japanese)
    • Random example sentence added to blog posts (Japanese)
  • Brainstorming, outlining, and mindmapping
  • Handling my mail
    • Doing mail merges or file merges
    • Tracking correspondence
    • Personalizing greetings and signatures
  • Managing contacts
  • Writing research papers
  • Managing my bibliography
  • Making presentations
    • Planning presentations
    • Delivering dynamic presentations (with executable code!)
    • Using speech synthesis to remind myself about what’s coming in the next “slide”
  • Reading documentation
  • Analyzing my blog and my writing
  • Running a shell
  • Searching files
  • Cleaning up, filtering, or transforming text
    • String and regexp replacement
    • Keyboard macros
    • Custom Emacs Lisp functions
  • Editing files on a remote server
  • Editing files inside an archive
  • Reviowing and making text notes about images and other files
  • Chatting on IRC
  • Chatting on instant messengers
  • Checking the calendar
  • Playing Nethack
  • Playing dunnet and snake
  • Browsing the Web
  • Posting to Twitter and other status update sites
    • Rigging up my to-do list to automatically publish task data to an internal status update site
  • Calculating expressions
  • Using a spreadsheet
  • Exploring directories
  • Renaming, deleting, or moving files
  • Drawing ASCII art
  • Reading news
  • Comparing files or revisions
  • Typing in Japanese or Latin
  • Reviewing similar files
  • Synthesizing speech – “reading” books, technical manual, mail, etc.
  • Learning more about Emacs
    • Random symbols and commands
    • Documentation
    • Source code
  • ROT13 and Morse code encryption/decryption
  • Editing GPG-encrypted files
  • Practising typing
  • Opening spreadsheets and other files downloaded from the Web
  • Taking screenshots (mostly of Nethack games)
  • Analyzing web logs and other files
  • Calculating days between two dates
  • Sending text messages
  • Analyzing source code
  • Interacting with APIs
  • Doing weekly, monthly, and yearly reviews
  • Versioning my files
  • Expanding text snippets
  • Drafting a book
    • Tracking my progress
  • Editing files as root
  • Compiling and running programs
  • Editing text from the browser
Short URL: http://sachachua.com/blog/p/23471

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging