Emacs org-mode

Jerry Hsieh

Emacs org-mode

  • 寫筆記
  • 做 Todo
  • 寫文章
  • 做計畫

Youtube 影片


  • Outlines
  • bold italic verbatim, strikethrough
  • bulleted
    • list
    • items
  • links My Website
  • store link


name email address
Jerry jerry@gmail.com xxx
Tim tim@gmail.com yyy

Export to other format (C-c C-e)

source code

def fact(n)
  if n == 0
    n * fact(n - 1)

org embed youtube

(defvar yt-iframe-format
;; You may want to change your width and height.
(concat "<iframe width=\"440\""
        " height=\"335\""
        " src=\"https://www.youtube.com/embed/%s\""
        " frameborder=\"0\""
        " allowfullscreen>%s</iframe>"))

(lambda (handle)
  (concat "https://www.youtube.com/embed/"
(lambda (path desc backend)
 (cl-case backend
   (html (format yt-iframe-format
                 path (or desc "")))
   (latex (format "\href{%s}{%s}"
                  path (or desc "video"))))))

Latex integration

  • characters: α → β
  • \(O(n \log n)\)
\begin{align*} 3 * 2 + 1 &= 6 + 1 &= 7 \end{align*}

有關 Latex 中文支援 (Mac OS)

  • Mac 最小安裝

    brew tap phinze/cask
    brew install brew-cask
    brew cask install basictex
  • 加 path

    # bash/zsh 等
    export PATH=/Library/TeX/texbin/:$PATH
  • 安裝中文 CTeX

    sudo tlmgr update --self --all
    sudo tlmgr install ctex environ trimspaces zhnumber
    sudo tlmgr install wrapfig capt-of
  • 在 org file 前加入

    #+LATEX_HEADER: \usepackage{ctex}
    #+LATEX_COMPILER: xelatex
  • 加入

    (defvar use-font (cond 
      ((eq system-type 'gnu/linux) "{Noto Sans TC Regular}")
      ((eq system-type 'darwin) "{PingFang TC}")))
    (setq org-latex-classes (list (list "article" (format "
         " use-font use-font use-font))))

Literate Programming

(org-babel-load-file "~/.emacs.d/configuration.org")
(use-package org
:ensure t
:mode (("\\.org\\'" . org-mode)
("\\.txt\\'" . org-mode))
(global-set-key (kbd "\C-c l") 'org-store-link)
(global-set-key (kbd "\C-c a") 'org-agenda)
(global-set-key (kbd "\C-c c") 'org-capture)
(setq org-hide-leading-stars t)
(setq org-src-fontify-natively t)
(setq org-log-done 'time)
(setq org-agenda-files (list "~/org/todo.org"
(use-package org-download
:ensure t)
(use-package org-bullets
:ensure t
:hook (org-mode . org-bullets-mode))
(org-babel-do-load-languages 'org-babel-load-languages
                             '((shell . t)
                               (python . t)
                               (sqlite . t)
                               (perl . t)
                               (C . t)
                               (ruby . t)
                               (js . t)
                               (emacs-lisp . t)
                               (lisp . t)
                               (latex . t)
                               (java . t)))

org2blog 直接寫部落格

  • 因 xml-rpc 不相容於 unicode, 需置換 unicode support
  • emacs-lisp 的 syntax highlight 參考 https://vxlabs.com/tag/syntaxhighlighter/
    • 加入 shBrushLips.jswp-content/plugins/syntaxhighlighter
    • 修改 syntaxhighlighter.php 插入

      // ...
      wp_register_script('syntaxhighlighter-brush-lisp', plugins_url('shBrushLisp.js',__FILE__),array('syntaxhighlighter-core'),'1.0.0');
      // ...
      $this->brushes = (array) apply_filters( 'syntaxhighlighter_brushes', array(
      'as3' => 'as3',
      <bunch of other aliases>,
      'lisp' => 'lisp',
      'emacs-lisp' => 'lisp',
  • 設定

    (use-package org2blog
    :ensure t
    :requires org
    (setq org2blog/wp-blog-alist
           :url "https://jerryhsieh01.wordpress.com/xmlrpc.php"
           :username "jerryhsieh01"
           :url "https://blog.onionstudio.com.tw/xmlrpc.php"
           :username "Jerry"
     (setq org2blog/wp-use-sourcecode-shortcode t)
     (setq org2blog/wp-sourcecode-langs 
          '("sh" "cpp" "css" "js" "javascript" "perl" "php" "python" "ruby" "emacs-lisp" "lisp" "go" "lua"))


介紹 Todo


Org Capture

(setq org-default-notes-file (concat org-directory "/notes.org"))
(setq org-agenda-files (list "~/org/gtd.org"
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/org/gtd.org" "Tasks")
    "* TODO %?\n  %i\n  %a")
    ("j" "Journal" entry (file+olp+datetree "~/org/journal.org")
    "* %?\nEntered on %U\n  %i\n  %a")
    ("b" "Blog" entry (file+headline "~/org/blog.org")
    "* %?\n%T" :prepend t)
    ("a" "Appointment" entry (file "~/org/gcal.org")
    "* %?\n\n%^T\n\n:PROPERTIES:\n\n:END:\n\n")))

Sync with Google Calendar

(use-package auth-source
:ensure t
(use-package org-gcal
:ensure t
(let (credentials)
  (add-to-list 'auth-sources "~/.netrc")
  (setq credentials (auth-source-user-and-password "org-gcal"))
  (setq org-gcal-client-id (car credentials)
      org-gcal-client-secret (cadr credentials)
      org-gcal-file-alist '(("jerryhsieh01@gmail.com" . "~/org/gcal.org"))
(add-hook 'org-agenda-mode-hook (lambda () (org-gcal-sync) ))
(add-hook 'org-capture-after-finalize-hook (lambda () (org-gcal-sync) ))
  • you need to add .netrc file

    machine org-gcal client-id xxxx secret yyyy

Org Reveal

  • 做簡報

    (use-package ox-reveal
    :ensure t