juan reyero

org-mode

Great emacs mode for note taking and publishing. Almost everything in this web is written with emacs and org-mode, and published automatically.

My org-mode configuration

Loaded from .emacs.

(add-to-list 'load-path "~/lib/emacs-lisp/org-mode/lisp")
(add-to-list 'load-path "~/lib/emacs-lisp/org-mode/contrib/lisp")
(require 'org-install)


(require 'org-babel-init)
(require 'org-babel-R)
(require 'org-babel-python)
(org-babel-load-library-of-babel)

(require 'org-crypt)
(setq org-crypt-key "Juan Reyero")
(add-hook 'before-save-hook 'org-encrypt-entries)
(global-set-key "\C-ce" 'org-decrypt-entry)

(setq org-export-htmlize-output-type 'css)

(require 'org-jekyll)
(require 'org-mac-message)
;;; Links to mail messages
;;; (add-to-list 'org-modules 'org-mac-message)
(global-set-key (read-kbd-macro "C-c C-x m") 'org-mac-message-insert-selected)


(setq org-ctags-path-to-ctags "/usr/local/bin/ctags")
(add-hook 'org-mode-hook
          (lambda ()
            (define-key org-mode-map "\C-co" 'org-ctags-find-tag-interactive)))
(require 'org-ctags)
(global-set-key (kbd "<M-kp-multiply>") 'pop-tag-mark)

;;;(add-to-list 'load-path "/Users/juanre/lib/emacs-lisp/org-mac-protocol")
;;;(require 'org-mac-protocol)
;;;(server-start)

;;; where to find latex and dvipng
(setq exec-path 
      (append (list "/usr/local/texlive/2008/bin/universal-darwin/") exec-path))

(setq org-directory "~/cjr/"
      org-default-notes-file (concat org-directory "cjr.org")
      org-attach-directory "~/hp/doc/"
      org-attach-method 'mv)

(setq org-ellipsis "..."
      org-hide-leading-stars t
      org-odd-levels-only t
      org-fontify-done-headline t
      org-fontify-emphasized-text t)

(setq org-link-abbrev-alist
       '(("prg" . "file:~/hp/prg/design.org::%s")
         ("google"   . "http://www.google.com/search?q=")))

(add-to-list 'load-path "~/lib/emacs-lisp/remember")
(require 'remember)
(org-remember-insinuate)

(define-key global-map "\C-cr" 'org-remember)
(setq org-remember-templates
      '(("Jac" ?c 
         "* %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %x" 
         "~/cjr/jac/jac.org" date-tree)
        ("Jr" ?r 
         "* %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %x" 
         "~/cjr/jr/blog/jr.org" date-tree)
        ("Note" ?n 
         "* %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %x" 
         nil date-tree)
        ("Todo" ?t 
         "* TODO %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %a" 
         nil date-tree)
        ("HP note" ?h 
         "* %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %x" 
         "~/hp/hp.org" date-tree)
        ("HP Todo" ?j 
         "* TODO %^{Title}\n  :PROPERTIES:\n  :on: %T\n  :END:\n  %?\n  %a" 
         "~/hp/hp.org" date-tree)
        ("Bookmark" ?b "* [[%^{URL}][%^{Description}]]\n" nil "Bookmarks")
        ;;("AppleScript remember" ?y "* %?\n\n  Source: %u, %c\n\n  %i" 
        ;; nil "Remember")
        ;;("AppleScript note" ?z "* %?\n\n  Date: %u\n" nil "Notes")
        ))

(setq org-archive-location ".archive/%s::")

;;; org-mtags allows you to use <quote></quote>, <src
;;; lang="python"></src>, and other convenient tags.
(require 'org-mtags)

;;; htmlize is used to fontify the exports of source code as in an
;;; emacs buffer
(require 'htmlize)

(setq org-refile-targets '((org-agenda-files . (:maxlevel . 5))))
(setq org-refile-use-outline-path t)

(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)

(add-hook 'org-mode-hook 'turn-on-font-lock)
(setq org-log-done t
      org-use-fast-todo-selection t)
(setq org-use-tag-inheritance t
      org-use-property-inheritance t)

;;; Clocking
(setq org-log-into-drawer t
      org-clock-modeline-total 'today
      org-clock-persist 'history)
(org-clock-persistence-insinuate)

(setq org-todo-keywords
      '((sequence "TODO(t)" "|" "DONE(d)" "CANCELLED(c)")
        (sequence "TASK(f)" "|" "DONE(d)")
        (sequence "MAYBE(m)" "|" "CANCELLED(c)")))

(setq org-todo-keyword-faces
      '(("TODO" . (:foreground "DarkOrange1" :weight bold))
        ("MAYBE" . (:foreground "sea green"))
        ("DONE" . (:foreground "light sea green"))
        ("CANCELLED" . (:foreground "forest green"))
        ("TASK" . (:foreground "blue"))))

(setq org-agenda-todo-ignore-scheduled t
      org-agenda-tags-todo-honor-ignore-options t
      org-agenda-todo-list-sublevels nil)

;;; This marks projects
(setq org-tags-exclude-from-inheritance '("prj")
      org-stuck-projects '("+prj/-MAYBE-DONE" ("TODO" "TASK") ())
      org-sec-me "juanre")

;;; Make an entry change state when its children change.  Only works
;;; when the entry has a statistics cookie ([/] or [%]).  Does not
;;; understand it as started until one of the sub-tasks has started.
(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

(require 'org-secretary)

(defun org-sec-stuck-cjr (par)
  "Select stuck projects with label cjr."
  (let ((org-stuck-projects 
         `(,(concat "+prj+cjr" 
                    "/-MAYBE-DONE")
           ("TODO" "TASK") ())))
    (org-agenda-list-stuck-projects)))

(setq org-agenda-custom-commands
      '(("h" "HP todos" tags-todo "-cjr-doat={.+}-dowith={.+}/!-TASK"
         ((org-agenda-todo-ignore-scheduled t)))
        ("H" "All HP todos" tags-todo "-cjr/!-TASK-MAYBE"
         ((org-agenda-todo-ignore-scheduled nil)))
        ("A" "HP todos with doat or dowith" tags-todo 
         "-cjr+doat={.+}|dowith={.+}/!-TASK"
         ((org-agenda-todo-ignore-scheduled nil)))
        ("c" "Cjr todos" ((tags-todo "cjr/!-TASK-MAYBE")
                          (org-sec-stuck-cjr "STUCK cjr"))
         ((org-agenda-todo-ignore-scheduled t)))
        ("j" "TODO dowith and TASK with"
         ((org-sec-with-view "TODO dowith")
          (org-sec-where-view "TODO doat")
          (org-sec-assigned-with-view "TASK with")
          (org-sec-stuck-with-view "STUCK with")))
        ("J" "Interactive TODO dowith and TASK with"
         ((org-sec-who-view "TODO dowith")))
        ("p" "Agenda for a particular person or tag"
         ((agenda ""
                  ((this-tag
                    (read-string 
                     "Build agenda for user/tag: " org-sec-with "" 
                     org-sec-with))
                   (org-agenda-skip-function '(my-keep-by-tags this-tag))))))
        ("P" "Program tasks"
         ((org-sec-prg-view "TASKS program")))
        ;;("f" "Tasks assigned to org-jr-with" 
        ;; org-jr-assigned-with-view "TASK with")
        ("l" todo "TASK")))


;;; org-mobile
(setq org-mobile-directory "/Users/juanre/Sites/antares/www/org")
(setq org-mobile-inbox-for-pull 
      "/Users/juanre/Sites/antares/www/org/inbox-pull.org")

;;;;;;;;;;;;;; Publishing
(require 'org-publish)

(defun slurp-file-to-string (file-name)
  "Read contents of file FILE-NAME and return as a string."
  (if (file-exists-p file-name)
      (with-temp-buffer
        (insert-file-contents file-name)
        (buffer-substring (point-min) (point-max)))
    ""))

(load-if-there "~/cjr/jr/jr.el")
(load-if-there "~/src/web/unarueda/org/unarueda.el")
(load-if-there "~/cjr/jac/jac.el")
(load-if-there "~/hp/org/style/hp.el")
(load-if-there "~/src/prj/org-jekyll/test/org.el")
(load-if-there "~/src/web/gsk/gsk.el")

;;;;;;;;;;;;;; Save and backup
;;; From http://doc.norang.ca/org-mode.html
(run-at-time "00:59" 3600 'org-save-all-org-buffers)
;;; Also run a cron job to commit the changes, crontab -e:
;;; 0 * * * * ~/bin/org-git.sh >/dev/null
;;; and the script looks like:
;;;
;;;#!/bin/sh
;;;
;;;# From http://doc.norang.ca/org-mode.html
;;;
;;;# Add org file changes to the repository
;;;REPOS="hp/org cjr/note cjr/personal cjr/write"
;;;
;;;for REPO in $REPOS
;;;do
;;;    echo "Repository: $REPO"
;;;    cd ~/$REPO
;;;    # Remove deleted files
;;;    git ls-files --deleted -z | xargs -0 git rm >/dev/null 2>&1
;;;    # Add new files
;;;    git add . >/dev/null 2>&1
;;;    git commit -m "$(date)"
;;;done

Resources and cheat sheet

Org-babel

Currently there is an :exports header argument which takes the self-explanatory values of

  • none
  • code
  • results
  • both

Recent select

To do a sparse tree with entries that have an on property that contains a date later than a week ago:

=C-c / T on>"<-1d>"=

Inline images

iimage-mode

Exportar

HTML y CSS
  • Generate CSS for emacs fonts, If you copy the face definitions from org.css, you will get the default Emacs faces. If you have configured faces and want to use those, start an emacs session, display you agenda to make sure all faces have been defined, and then run the command M-x org-export-htmlize-generate-css RET

    This will create css for all faces currently defined in Emacs. The copy these definitions, or the ones you'd like to have, into your own css file.

Documento title

#+TITLE: the title

Fonts

bold, itálica, subrayada, código, verbatim y tachada.

Citing
#+BEGIN_QUOTE
Cita
#+END_QUOTE

With org-mtags installed you can use <quote>.

Source

With org-mtags <src lang="python">

Juan Reyero Barcelona, 2009-11-07
 

blog comments powered by Disqus