Category Archives: org

On this page:

Emacs tweaks: Export Org checkboxes using UTF-8 symbols

UPDATE 2014-03-28: Newer versions of org have the org-html-checkbox-type variable, which you can set to unicode. Use M-x customize-variable org-html-checkbox-type to see if you have it.

This snippet turns - [X] into ☑ and - [ ] into ☐.

(defun sacha/org-html-checkbox (checkbox)
  "Format CHECKBOX into HTML."
  (case checkbox (on "<span class=\"check\">&#x2611;</span>") ; checkbox (checked)
        (off "<span class=\"checkbox\">&#x2610;</span>")
        (trans "<code>[-]</code>")
        (t "")))
(defadvice org-html-checkbox (around sacha activate)
  (setq ad-return-value (sacha/org-html-checkbox (ad-get-arg 0))))

To find this code, I searched ox-html.el for [. Eventually I found org-html-checkbox, which is directly called by org-html-format-list-item instead of being a function variable that you can change. So that meant I needed to override the behaviour of org-html-checkbox through defadvice. You can see above how I wrap advice around org-html-checkbox and replace the return value with my own function. For more about advice, read the Emacs Lisp Intro manual.

To find the hex codes for the UTF-8 characters, I searched Google for UTF-8 checkbox and found BALLOT BOX WITH CHECK. I used the hex code so that I didn’t have to worry about encoding issues. I tested it by updating one of my weekly reviews. Tada!

Inspired by Grant from Wisdom and Wonder.

Emacs, Evernote (through enscript.exe), and Org links

I’ve given myself permission to spend an hour or two tickling my brain with various technical ideas and prototypes every day. This means Emacs geekery is going to turn up on my blog more often. =) Here’s a recent hack that I put together to make my weekly reviews a little easier.

I skim a lot of blog posts on my phone using the Feedly app. (See: How to read blogs efficiently with a feed reader.) I save the posts I want to follow up on or include in my weekly round-up. I have an If This Then That recipe that monitors my saved items and stashes them in Evernote with the roundup tag. If I come across other interesting pages while browsing on my computer, I use the Evernote Web Clipper to save those pages with the roundup tag as well.

In the past, I selected a range of notes to export from Evernote, saved them to a file, and used my sacha/evernote-extract-links-for-review function to extract the titles and URLs. I opened each of the pages with C-c C-o (org-open-at-point) to refresh my memory and follow up. I deleted lines that were no longer relevant. Since IFTTT had changed to rewriting the URLs instead of leaving the source URLs alone, I copied the original URLs and replaced the links that were in Org.

This is Emacs, though, and even that can be smoothened with a little scripting. Now I can use the code below to expand URLs and to open all the URLs in the region.

Link-related convenience functions

I picked this up from http://www.emacswiki.org/emacs/AlexSchroederConfigOrientalibombus .

(defun kensanata/resolve-redirect (url)
  "Resolve shortened URL by launching `curl --head' and parsing the result."
  (let* ((curl (shell-command-to-string
                (format "curl --silent --head %s" url)))
         (location (when (and (string-match "\\`HTTP/1\.1 301" curl)
                              (string-match "^Location: \\(.*\\)" curl))
                     (match-string 1 curl))))
    (or location url)))

(defun sacha/resolve-urls-in-region (beg end)
  "Expand URLs between BEG and END."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (re-search-forward org-bracket-link-regexp nil t)
        (replace-match (save-match-data (kensanata/resolve-redirect
                                         (match-string 1))) t t nil 1))
      (goto-char (point-min))
      (while (re-search-forward org-link-re-with-space nil t)
        (replace-match (save-match-data (kensanata/resolve-redirect
                                         (match-string 0))) t t nil)))))

(defun sacha/open-urls-in-region (beg end)
  "Open URLs between BEG and END."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (re-search-forward org-plain-link-re nil t)
        (org-open-at-point)))))

Evernote-related extract

Evernote on Windows doesn’t have the same kind of scripting capabilities that Evernote on the Mac has, but it turns out you can still do a fair bit of scripting with the enscript tool.

(defun sacha/evernote-export-and-extract (start-date end-date)
  "Extract notes created on or after START-DATE and before END-DATE."
  (let ((filename "c:/sacha/tmp/Evernote.enex"))
    (call-process 
     "c:/Program Files (x86)/Evernote/Evernote/enscript.exe"
     nil t t
     "exportNotes"
     "/q" (concat
           " tag:roundup"
           " created:" (replace-regexp-in-string "-" "" start-date)
           " -created:" (replace-regexp-in-string "-" "" end-date))
     "/f" filename)
    (sacha/evernote-extract-links-for-review filename)))

(defun sacha/evernote-extract-links-for-review (filename)
  "Extract note names and URLs from FILENAME.
     The file should be an ENEX export."
  (interactive (list (read-file-name "File: ")
                     (org-read-date)
                     (org-read-date)))
  (let (list)
    (with-temp-buffer
      (insert-file-contents filename)
      (goto-char (point-min))
      (while (re-search-forward "<title>\\(.+?\\)</title>\\(.*?\n\\)*?.*?href=\"\\(.*?\\)\"" nil t)
        (setq list
              (cons
               (cons
                (match-string-no-properties 1)
                (match-string-no-properties 3)) list))))
    (setq list
          (mapconcat (lambda (x)
                       (concat "- [["
                               (kensanata/resolve-redirect (cdr x))
                               "][" (car x) "]]: ")) list "\n"))
          (if (called-interactively-p 'any)
              (insert list)
            list)))

Let’s see how this new workflow goes. =) If you’re curious, you can check out the rest of my weekly-review-related code in my Emacs configuration.

Drafting a baby-steps guide to managing your tasks with Org Mode for Emacs

Org mode for Emacs is powerful and flexible, which can make it intimidating for newcomers. After helping several people with essentially the same problem–an unmanageably large heap of tasks–I thought about what might help people get the hang of the key features of Org Mode slowly.

Here are some general ideas. Start by writing your tasks down. Group them into projects. Once you get the hang of that, schedule your tasks. You might find yourself overestimating what you can do in a day, so reschedule or get rid of tasks as needed.

2014-02-08 A path toward taming your TODO list

2014-02-08 A path toward taming your TODO list

Here’s a visual overview of how you can apply that to Org, starting with simple outlines and moving on to scheduling.

2014-02-16 Org TODO basics

2014-02-16 Org TODO basics

I’ve started to put together an outline/draft for A Baby Steps Guide to Managing Your Tasks with Org Mode, which you can find at sach.ac/baby-steps-org-todo. Comments and questions welcome!

Some tips for learning Org Mode for Emacs

This entry is part 3 of 4 in the series A Visual Guide to Emacs

When I learn something new, I always find myself wishing there was some kind of map to help me figure out where to start, how to track progress, and what to learn next. So now I’m making them. Here’s one for learning Org Mode, a popular outline/TODO/everything-else mode for the Emacs text editor. You can probably figure out the relevant manual sections to read based on the keywords, but feel free to ask in the comments if you need more help.

2014-01-07 Map for learning Org Mode for Emacs

Map for Learning Org Mode for Emacs

Here’s another short guide with suggestions for evolving your Org file organization:

2014-01-09 Tips for organizing your Org-mode files

Tips for organizing your Org-mode files

And here’s the one-page cheat sheet I made before helping someone dig into tracking time with Org. It’s a great way to measure your time on specific tasks.

2014-01-06 Tracking time with Org mode

Tracking time with Org Mode

Eventually I’ll get around to writing/drawing a book on thinking with Emacs. If you want it to happen, keep asking questions! =)

(Images are shared under the Creative Commons Attribution license, so reshare/reuse/remix away! Click on the images for larger versions.)

Emacs Org Mode Customization Survey

Org Mode is an outlining and TODO tool for Emacs. Except it’s so much more than that, since people have written all sorts of code to make it do way more than an outliner (or even a text editor!) usually does. Seriously, it even has a Sudoku solver. (The code is optional, so you don’t lose memory if you don’t load it.)

If you use Emacs and you haven’t tried out Org Mode yet, check it out.

If you’ve made Org Mode a part of your life, you’ve probably customized lots of little things about it. Please help the developers by submitting the customization survey to Mike McLean!

As discussed a few days ago on this list, Carsten and the other developers are interested in what and how us users are customizing Org mode. This was first done in 2009, so a re-do of the survey is useful as is for how people are using Org now, as well as a comparison to the past.

Carsten provided the function that was used before to collect the raw data and I am working on the data collection and summarization this time around.

I have place the function on Github, https://github.com/SkydiveMike/org-customization-survey
The raw elisp is at: https://raw.github.com/SkydiveMike/org-customization-survey/master/org-customization-survey.el

All you need to do is:
1. Load and eval the function
2. Execute (interactive) org-customization-survey
3. Review the buffer, cleanse for sensitive information if any
4. Email the buffer to [email protected] (If your Emacs is configured for email, C-c C-c will send)

I’m looking forward to the results, which will most likely be posted to the Org Mode mailing list.

Curious about my Org configuration? Check out my annotated Emacs config.

When I blog with Emacs and when I blog with other tools

English: org-mode logo: http://orgmode.org/wor...

English: org-mode logo: http://orgmode.org/worg/org-faq.php#unicorn (Photo credit: Wikipedia)

I would love to be able to write all of my blog posts within Emacs. I like the outline tools and simple markup of Org Mode. Org Mode and org2blog are invaluable when I’m writing a post with lots of code or keyboard commands, because it’s easy to set up syntax highlighting or add teletype text. Here’s an interesting self-referential example of org2blog’s power that uses #INCLUDE to include the Org blog post source in the post itself.

If I expect that a post will have lots of images, I tend to use Windows Live Writer because it takes care of resizing and aligning images, linking to the original size. Because it uses my blog’s stylesheet, I can get a sense of how the text will flow around it. I can quickly draw an idea in Autodesk Sketchbook Pro, copy and paste it into Windows Live Writer, and then resize it until it feels balanced on the page. Sometimes I draft a post in Emacs and then open it in Windows Live Writer or ScribeFire so that I can add images.

Org Mode also supports images, but it’s not as easy to resize things there. If I wrote a function that used ImageMagick to save the clipboard image to a file, resize it to the appropriate dimensions, and link it to the full-size image, maybe that would do the trick. Still, that sounds like it would be a fair bit of work. Maybe someday. Hmm – any chance someone reading this blog happens to already have that snippet handy? =)

If I need to edit an existing post, I either use the WordPress web interface or I use ScribeFire. That way, I don’t have to fill in the post publishing date again.

It’s a bit of a patchwork system of different tools, but it does the job. What’s your workflow like?