zomg, Evernote and Emacs

Update 2013-10-19: Check out https://github.com/pymander/evernote-mode for a possibly better way to do things. =)

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.

  • Jay Dugger

    Awesome! I thought I was the only person using evernote-mode. I have it working well under Linux, but not under Cygwin. Any suggestions?

    • http://sachachua.com Sacha Chua

      I got mine to work under Cygwin after following the notes in the config. I also edited the .rb script to make it go to the http address instead of https, as my Ruby doesn’t seem to have SSL support and I haven’t gotten around to fixing it yet. Hope that helps!

  • http://lamattgrind.tumblr.com Matthew Darling

    Do you suppose the generated HTML files would be compatible with OneNote’s import? A combined mode that works with both services (through SkyDrive for OneNote) would be awesome!

  • http://daveabrahams.com Dave Abrahams

    Sacha, I’ve been wondering what made you pick up Evernote, and how do you use it? Doesn’t having some stuff in Org and other things in Evernote just lead to information fragmentation?

    Thanks

  • http://sachachua.com Sacha Chua

    Dave: I mostly use Evernote for the ability to search within hand-written images, which I use for my sketchnotes. I’m also curious about the ability to easily take image and sound notes. So far, no problems with information fragmentation, even between Org and my blog and Evernote. =) I’ll probably run into that someday, but in the meantime, not stressing out about it – just keeping redundant copies of things that are particularly important to me.

  • http://jasonjohnwells.com Jason John Wells

    Hi Sacha and/or Fellow Commentator,

    I would LOVE to link up Emacs and Evernote but I also ran into a

    ‘SSL_connect SYSCALL returned=5 errno= sate=unknown state’

    Is that the same error you fixed in enclient.rb?

    I tried deleting the the ‘s’ off ‘https’ but still get that error. This is my first time trying to edit a Ruby file so any advice is much appreciated.

    Org mode is my text tool of choice and Evernote is the killer Android app for me as I live in a small Japanese town with limited Japanese ability.

    Thanks for an awesome blog.

  • http://sachachua.com Sacha Chua

    Could you try installing Cygwin and then installing ruby inside Cygwin? Maybe that makes a difference.

  • http://clair.craftyneko.com clair

    Been thinking about using Emacs and Evernote together, Sacha! XD This is something I realized I could do.

  • http://livinganawesomelife.com Sacha Chua

    Happy to help you get going with it! =D

  • vicente

    sacha. tried evernote-mode but got stuck. I tried to open a note, but after entering my pw a message reads ‘can’t convert nil into string’ any hints?

    • Tim

      I have the same issue — was this ever fixed for you?

      • http://sachachua.com sachac

        Evernote currently doesn’t support out-of-band authentication for OAUTH, so I think that means Evernote integration for Emacs is broken.

  • vicente

    ps. I’m using GNU Emacs 24.1.1 (i686-redhat-linux-gnu, GTK+ Version 2.24.13)
    of 2012-10-22 on buildvm-17.phx2.fedoraproject.org

  • http://livinganawesomelife.com Sacha Chua

    Could you M-x toggle-debug-on-error and e-mail me (or better yet, the evernote-mode maintainer) your backtrace?

    • vicente

      Debug on Error enabled globally
      Waiting for the result… [2 times]
      can’t convert nil into String

      #now using debugger (GBD)
      Waiting for the result…
      Blocking call to accept-process-output with quit inhibited!!
      can’t convert nil into String
      # this is the backltrace buffer (but I think it’s not evernote-mode related)
      Debugger entered–Lisp error: (wrong-type-argument number-or-marker-p nil)
      gdb-show-stop-p()
      (or (not (memq gud-minor-mode (quote (gdbmi pdb)))) (gdb-show-stop-p))

      this is all I can get. sorry but don’t know how to get more backtrace

  • http://sachachua.com Sacha Chua

    That sounds more like the Evernote command-line tool bundled with evernote-mode isn’t working for you. Could you ask Yusuke Kawakami, who wrote evernote-mode? https://github.com/rubbish/evernote-mode might be another variant to try. Note that you’ll need to have Ruby set up on your system.

  • http://twitter.com/GeoffreyRoman Geoffrey Roman

    Hi Sacha! I’m new to Emacs and I was excited by this evernote-mode. But evernote switched to Oauth authentification and the mode. Have you got some news about this?

    Also I like Evernote for its search capabilities, like PDF or images OCR searches. I’m in school so I have a lot of documents and switch just to Org-mode isn’t possible. Maybe you’ve got some tips to get organized with all these documents easily!

    Sorry about my english, I’m French…

    • http://sachachua.com sachac

      I’m looking forward to digging into this in February. :) Hope we can figure things out!

      • http://twitter.com/GeoffreyRoman Geoffrey Roman

        Thanks a lot! :)

    • http://sachachua.com sachac

      It turns out that Evernote doesn’t support out-of-band authentication yet (http://discussion.evernote.com/topic/26357-oauth-api-vs-useridpassword/#entry187780), so we’re out of luck for now. =|

      • netawater

        Does that mean the evernote-mode can not be used at all if Evernote always doesn’t support out-of band authentication?

        • http://duma.tumblr.com SeanG

          I just spent some time trying to get evernote-mode working in my Emacs install. I believe some semi-substantial work will need to be done to it to work with the new authentication system. Right now it seems to be set up to log in as an API consumer, and that process is onerous (you have to get an API key, and then request that Evernote make it live on the production site. Even then, who knows if it will actually work).

          • http://sachachua.com sachac

            C’est la vie. =( Even as an API consumer, it still won’t work because Evernote doesn’t currently support out-of-band authentication.

      • vicco

        is it the same problem for nixnote? I wonder if this would work as an indirect access to evernote.

  • jre

    Sacha –
    I have found more immediately useful stuff related to emacs org mode at your site than anywhere else[1], so thanks! Now that it looks as if Evernote will be a preferred format by my co-workers, I want to get evernote-mode working on Windows and Linux boxen. May I complain here about my bafflement when I get stuck?

    [1] Bernt Hansen’s place is close.

    • http://sachachua.com sachac

      Aww, thanks! Yes, you may, although it won’t be any use until Evernote supports out-of-band authentication. =( Or someone makes a web-based service that takes an Org file and Does Stuff To It…