I like to use OrgMode because I feel organized and in control. That is definitely an illusion, but it is a nice one.
I am still using firefox to browse the web. Mainly because w3m doesn’t work well at all outside of plain text pages and ezbl is not yet ready. This means I am generating a lot of information; history, tabs, bookmarks that are outside of my massive org collection of stuff.
When I find something I would like to read, but don’t have time for at that moment, I would like to store it in orgmode. However, copy/paste the url+title got really tedious. As with anything tedious I tend not to do it. So my firefox ‘to read later’ bookmark folder got full and without a way to prioritize them it became a morass of unused links.
Wouldn’t it be nice if emacs could pull the current url and title from firefox and put that into org for me?
Queue MozRepl stage right
MozRepl gives you a simple line oriented repl into the entire browser context. You could even use telnet if you really wanted to.
So I hacked up some quick primitive functions to ask MozRepl for the current url and title.
The function that will send a string to Firefox. The repl MUST be started already which you can do with M-x run-mozilla
(require 'moz) (defun jk/moz-get (attr) (comint-send-string (inferior-moz-process) attr) ;; try to give the repl a chance to respond (sleep-for 0 100))
The sleep-for function is there because there is no flow control on the mozrepl. If you call jk/moz-get in succession too quickly you will get whatever the last result was multiple times.
Get the current url:
(defun jk/moz-get-current-url () (interactive) (jk/moz-get "repl._workContext.content.location.href"))
Get the current title:
(defun jk/moz-get-current-title () (interactive) (jk/moz-get "repl._workContext.content.document.title"))
The repl buffer will now have the results printed as a string. Not useful. So we work a little buffer walking magic that makes too many assumptions.
(defun jk/moz-get-current (moz-fun) (funcall moz-fun) ;; doesn't work if repl takes too long to output string (save-excursion (set-buffer (process-buffer (inferior-moz-process))) (goto-char (point-max)) (previous-line) (setq jk/moz-current (buffer-substring-no-properties (+ (point-at-bol) (length moz-repl-name) 3) (- (point-at-eol) 1)))) (message "%s" jk/moz-current) jk/moz-current )
This simply calls whatever func is passed in as moz-fun and grabs the last output line of the moz repl.
The last bit for getting what we want is to put all the above together into a couple convenience functions:
(defun jk/moz-url () (interactive) (jk/moz-get-current 'jk/moz-get-current-url) ) (defun jk/moz-title () (interactive) (jk/moz-get-current 'jk/moz-get-current-title) )
Now we can run (jk/moz-url) and it returns the url in whatever window/tab is currently active, same for (jk/moz-title)
Last step is to get this into org via org-capture using org-capture-templates.
(setq org-capture-templates '(("t" "Todo" entry (file+headline "~/org/all.org" "Tasks") "* TODO %?\n %i\n %a") ("n" "Notes" entry (file+datetree "~/org/notes.org") "* %?\nEntered on %U\n %i\n %a") ("b" "Bookmark" entry (file+datetree "~/org/notes.org") "* %(concat \"[[\" (jk/moz-url) \"][\" (jk/moz-title) \"]]\")\n Entered on %U\n") ))
The orgmode capture template has %(sexp) so you can run arbitrary elisp code to generate the content of the template.
Now all I have to do is C-c c b C-c C-c and I have a ‘bookmark’ in org. I am finding this to be very useful.