Heikki @ home

Loose leaves from my tree

Note taking 2: Notes from browser window

This is the second article in the series on quick note taking using emacs. It shows an easy way of taking a note of the current browser window URL and title under OS X.

  1. Org agenda with date tree file
  2. Notes from browser window
  3. Notes from elfeed entries

OS X

I've been using a Mac laptop as my main computer for a few years now, so these instructions work only under OS X.

Interactive approach

I've installed package called org-mac-link that grabs links from open applications and pastes them to current org-buffer. Running the command M-x org-mac-grab-link RET shows a menu of available applications. An org link from the selected application gets pasted into your emacs buffer.

Linking to Chrome

After a while having to go through the menu became annoying. I am using Chrome as my only browser anyway, so I decided to ignore all the other applications. I can call the Chrome-specific function org-mac-chrome-insert-frontmost-url directly.

I bind it to C-x l l using a hydra that gives me the mnemonic "Emacs, launch link".

This is great for situations when I've researched a topic on browser and have several related tabs open. I use the org capture note defined in the previous article in this series with C-c c n, write the title and add a link for each open tab.

Immediate linking

Again, after some time I noticed this note taking could be streamlined even more. Most of time I want to take a note of just a single web page.

Since the note uses org-capture, it can be called directly from emacs lisp and combined with other commands to build a function that does everything needed.

I've bound the function my/quick-url-note to global key C-c v. Whenever I read an interesting article in Chrome, I now switch to emacs, press those keys and my note is stored.

I've recently started using use-package for configuring all my emacs packages. The clarity, scope and compactness of the code below is enough reason:

(use-package org-mac-link
  :ensure t
  :if (eq system-type 'darwin)
  :bind ("C-c v" . my/quick-url-note)
  :config
  (defun my/quick-url-note ()
    "Fastest way to capture a web page link"
    (interactive)
    (org-capture nil "n")
    (org-mac-chrome-insert-frontmost-url)
    (org-capture-finalize)))

Editing the last link

Quite often after adding a note link, I realize that I want to add a few more words of explanation to the note. This is made easier by the function that takes me the end of the latest link.

(defun my/last-captured-org-note ()
  "Move to the end of penultimate line of the last org capture note."
  (interactive)
  (find-file "~/Dropbox/org/reference.org")
  (end-of-buffer)
  (forward-line -2)
  (org-end-of-line))

I've bind that to C-c z r using my general purpose goto hydra:

(bind-key "C-c z" 'hydra-goto/body)
(defhydra hydra-goto (:color blue :hint nil)
  "
  goto   file                        info
         --------------------------------------
         _e_macs.org                 _o_rg
         _r_eference.org: last note
         _w_ork.org
      "
  ("e" (find-file "~/.emacs.d/emacs.org"))
  ("r" my/last-captured-org-note)
  ("w" (find-file "~/Dropbox/org/work.org"))
  ("o" org-info))

Linux

While the code presented here works only on OS X, it is definitely possible to do the same under Linux. If you want to explore how, here a couple of links that might help:

Comments