Org-Mode
Things You Can Do With Org-Mode
- Organize code into sections you can fold
- Use AI
- Write HTML emails
- Manage contacts
- Create custom calenders
- Simplify Latex
- Use org-tables with excelish functionality directly in emacs
- Keep and search notes
- Access notes from your phone
- Use timestamps to remind you on your phone
- Query your notes like a database
- Export to notecards for quizzing software
- Export to HTML
- Export to PDF
- Simplify Latex
- Edit Google Docs with CSS
- Manage multiple files in one document
- Track your time
- And more …
You can look at this screenshot to get an idea of what org-mode configuration headings look like:
Here’s some code:
Open Org
(use-package org
:commands
Directive
You can list commands that load the code when called.
:commands (org-mode Org-Agenda/body Org-Editor/body Org-Central/body org-agenda Org-Table/body org-capture-goto-target mu4e launch-mu4e mu4e-compose-new mu4e-compose-reply Mu4e-mail/mu4e Mu4e-mail/launch-mu4e Mu4e-mail/mu4e-compose-new Mu4e-mail/mu4e-compose-reply)
:init
Directive
Your custom themes need font faces.
:init
(require 'org-faces)
:mode
Directive
You can launch org-mode when you open org documents.
:mode ("\\.org\\'" . org-mode)
:config
Directive
:config
Default Notes
You can set directories where org can store and search files.
(setq org-default-notes-file org-notes-p)
Shorten Export Process
(setq org-export-html-postamble nil)
Set Leading Stars And Superscripts
You can make your org buffer look better.
(setq org-hide-leading-stars t)
(setq org-use-sub-superscripts '{})
Org Show Levels Functions
You can change the level of visible headings and content.
(defun org-show-two-levels ()
(interactive)
(org-content 2))
(defun org-show-three-levels ()
(interactive)
(org-content 3))
Org Add Pretty Symbols And Ellipsis
You can make your org buffer look even better.
(defun org-add-pretty-symbols ()
"make some word or string show as pretty Unicode symbols"
(setq prettify-symbols-alist
'(
("lambda" . 955) ;
("->" . 8594) ;
("=>" . 8658) ;
)))
Ellipsis
Customize what you see at the end of the heading line.
(setq org-ellipsis "...")
Fontify Heading Line
(setq org-fontify-whole-heading-line t)
Org Bullets
Make your headings look better with the org-bullets
package.
(use-package org-bullets
:after org
);end org-bullets
Toggle the Literal Or Descriptive Display of Links
You can make org links look more like links when you want to.
(defun org-toggle-link-display ()
"Toggle the literal or descriptive display of links."
(interactive)
(if org-descriptive-links
(progn (org-remove-from-invisibility-spec '(org-link))
(org-restart-font-lock)
(setq org-descriptive-links nil))
(progn (add-to-invisibility-spec '(org-link))
(org-restart-font-lock)
(setq org-descriptive-links t))))
Function Set Default Company Backends
You can set the default backends for company-mode
.
(defun poseidon-org-mode-hook ()
"company hook for org-mode"
(set (make-local-variable 'company-backends)
'((company-yasnippet company-ispell company-dabbrev))))
Org Mode Hook
You can set a hook to turn off auto-indenting, toggle on prettify symbols, toggle off eldoc (buffer reminders), and turn the bullets on.
(add-hook 'org-mode-hook (lambda ()
(electric-indent-local-mode -1)
;(global-prettify-symbols-mode 1)
(org-add-pretty-symbols)
(eldoc-mode -1)
(poseidon-org-mode-hook)
(org-bullets-mode 1)
))
Start Non-indented, Folded, With Images off
Start Emacs with folding and without indentation.
(setq org-startup-indented nil) ;; Indent according to section
(setq org-startup-with-inline-images nil) ;; Display images in-buffer by default
(setq org-startup-folded t) ;; open org files folded
(setq org-indent-mode nil)
Org Tempo
(require 'org-tempo)
Insert Four Spaces
You can program the key C-i
to insert 4 spaces, to free up the tab key.
(defun insert-four()
(interactive)
(insert (make-string 4 ?\s))
);end insert four spaces
Pulse (flash light)
Flash lights when you move through text with M-e
, M-a
, C-}
, and C-{
.
(defun jib/pulse-area (&rest _)
"Pulse +-5 chars of point."
(pulse-momentary-highlight-region (- (point) 5) (+ 5 (point))))
(defun pulse-area (&rest _)
"Pulse +-5 chars of point."
(pulse-momentary-highlight-region (- (point) 5) (+ 5 (point))))
(dolist (command '(org-forward-sentence org-backward-sentence))
(advice-add command :after #'jib/pulse-area));doesn't work with pulse-area
Org Clock Sound
(setq org-clock-sound org-clock-p)
Org Emphasis
You can highlight selected words in different colours.
(require 'org-habit nil t)
(defun org-add-my-extra-fonts ()
"Add alert and overdue fonts."
(add-to-list 'org-font-lock-extra-keywords '("\\(!\\)\\([^\n\r\t]+\\)\\(!\\)" (1 '(face org-habit-alert-face invisible t)) (2 'org-habit-alert-face t) (3 '(face org-habit-alert-face invisible t))) t)
(add-to-list 'org-font-lock-extra-keywords '("\\(%\\)\\([^\n\r\t]+\\)\\(%\\)" (1 '(face org-habit-overdue-face invisible t)) (2 'org-habit-overdue-face t) (3 '(face org-habit-overdue-face invisible t))) t)
)
(setq extraFonts 0)
(defun toggleExtraFont ()
(interactive)
(cond
((equal extraFonts 0)
(progn
(add-hook 'org-font-lock-set-keywords-hook #'org-add-my-extra-fonts)
(setq extraFonts 1)
));
((equal extraFonts 1)
(progn
(remove-hook 'org-font-lock-set-keywords-hook #'org-add-my-extra-fonts)
(setq extraFonts 0)
));
));end toggleExtraFont
Package Show Emphasis Markers
(use-package org-appear
:ensure t
:hook (org-mode . org-appear-mode)
)
Org Babel Do Languages
You can get syntax highlighting and mode functionality in code-blocks.
;org-babel languages support
(org-babel-do-load-languages
'org-babel-load-languages
'((R . t)
(ditaa . t)
; (dot . t)
(emacs-lisp . t)
(gnuplot . t)
; (haskell . nil)
(latex . t)
(ledger . t)
; (ocaml . nil)
; (html . t)
(js . t)
(python . t)
(php . t)
(css . t)
(shell . t)
; (sh . t) ; get ob-sh
(sql . nil)
; (sqlite . t)
));end org-babel-do-load-languages
(setq org-babel-R-command org-babel-R-command-p)
(setq org-confirm-babel-evaluate nil)
Org Babel Tangle Block
You can run or export the code in a code block, org will print the results into your document if you want it to.
(defun org-babel-tangle-block()
(interactive)
(let ((current-prefix-arg '(4)))
(call-interactively 'org-babel-tangle)
))
Org Babel Tangle Files Same as Block
You can run or export the code all similar blocks in a file.
(defun org-babel-tangle-files-same-as-block()
(interactive)
(let ((current-prefix-arg '(16)))
(call-interactively 'org-babel-tangle)
))
Here are some file types you manage and export from an org file.
- HTML
- CSS
- SCSS
- JavaScript
- Hugo
- Emacs
- Notes
- Invoices
- Contracts
- Scripts
- Text
- Books
- And anything else
Add Modes Inside SRC Blocks
(add-to-list 'org-src-lang-modes '(
("html" . web)
("scss" . scss)
("js" . js)
))
CSS Set Default HTML Export Styling
When you export your files to HTML, you can use some other default styling.
(setq roboto-Gray-HTML "
<meta http-equiv='X-UA-Compatible'content='IE=edge,chrome=1'>
<meta content='width=device-width,initial-scale=1, maximum-scale=1, user-scalable=no'name='viewport'>
<style>
html{
touch-action:manipulation;
-webkit-text-size-adjust:100%
}
body{
padding:0;
margin:0;
background:#f2f6fa;
color:#3c495a;
font-weight:normal;
font-size:15px;
font-family:'San Francisco','Roboto','Arial',sans-serif
}
h2,h3,h4,h5,h6{
font-family:'Trebuchet MS',Verdana,sans-serif;
color:#586b82;
padding:0;
margin:20px 0 10px 0;
font-size:1.1em}
h2{
margin:30px 0 10px 0;
font-size:1.2em}
a{
color:#3fa7ba;
text-decoration:none}
p{
margin:20px 0;
text-align:left}
ul,ol{
margin:0;
text-align:left}
ul>li>code{
color:#586b82
}
pre{
white-space:pre-wrap}
#content{
width:96%;
max-width:1000px;
margin:2% auto 6% auto;
background:white;
border-radius:2px;
border-right:1px solid #e2e9f0;
border-bottom:2px solid #e2e9f0;
padding:0 115px 150px 115px;
box-sizing:border-box}
#postamble{display:none}
h1.title{
background-color:#343C44;
color:#fff;
margin:0 -115px;
padding:60px 0;
font-weight:normal;
font-size:2em;
border-top-left-radius:2px;
border-top-right-radius:2px;
text-align:center;}
@media (max-width:1050px){
#content{
padding:0 70px 100px 70px;}
h1.title{margin:0 -70px;}
}
img{
max-width:100%;}
@media (max-width:800px){
#content{
width:100%;
margin-top:0;
margin-bottom:0;
padding:0 4% 60px 4%}
h1.title{
margin:0 -5%;
padding:40px 5%}}
pre,.verse{
box-shadow:none;
background-color:#f9fbfd;
border:1px solid #e2e9f0;
color:#586b82;
padding:10px;
font-family:monospace;
overflow:auto;margin:6px 0}
#table-of-contents{
margin-bottom:50px;
margin-top:50px}
#table-of-contents h2{
margin-bottom:5px}
#text-table-of-contents ul{
padding-left:15px}
#text-table-of-contents>ul{padding-left:0}
#text-table-of-contents li{list-style-type:none}
#text-table-of-contents a{color:#7c8ca1;font-size:0.95em;text-decoration:none}
table{border-color:#586b82;font-size:0.95em}
table thead{color:#586b82}
table tbody tr:nth-child(even){background:#f9f9f9}
table tbody tr:hover{background:#586b82!important;color:white}
table .left{text-align:left}
table .right{text-align:right}
.todo{font-family:inherit;color:inherit}
.done{color:inherit}
.tag{background:initial}
.tag>span{
background-color:#eee;
font-family:monospace;
padding-left:7px;
padding-right:7px;
border-radius:2px;
float:right;
margin-left:5px}
#text-table-of-contents .tag>span{float:none;margin-left:0}
.timestamp{color:#7c8ca1}
@media print{@page{margin-bottom:3cm;margin-top:3cm;margin-left:2cm;margin-right:2cm;font-size:10px}
#content{border:none}}
</style>")
Initialize the Code Above
(setq org-html-head roboto-Gray-HTML)
OX HTML
Enable HTML exports from within org export.
(require 'ox-html)
Additional Export Configuration
(setq org-export-allow-bind-keywords t)
Export With Smart Quotes
You can convert hyphens to dashes and straight quotes to curly quotes on export.
(setq org-export-with-smart-quotes t)
Include Default HTML Styling on Export
(setf org-html-head-include-default-style nil)
Include Scripts in HTML Export
(setq org-html-head-include-scripts nil)
Set HTML Export Doctype
(setf org-html-doctype "html5")
Auto Configuration of Tables on Export
(setq org-html-table-default-attributes
'(:border "0" :cellspacing "0" :cellpadding "6" :rules "none" :frame "none"))
Add a Viewport Meta Tag to Export
(setf my-head-extra
(concat
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, interactive-widget=resizes-visual\">\n"
))
Set Some Syntax Highlighting for Org-src Blocks
(setq org-src-fontify-natively t)
Ensure Tab Buttons Works Normally in SRC Blocks
(setq org-src-tab-acts-natively t)
Don’t Change Indentation in Org-src Blocks
(setq org-src-preserve-indentation t)
Set an Archive Directory
(setq org-archive-location org-archive-p)
Add New File When Refile
You can create a new document for some content in your document and put it there.
(setq org-refile-use-outline-path 'file)
Refile Target to Level 1
(setq org-refile-targets '((org-agenda-files :level . 1)))
Set Info Saved When Archive
(setq org-archive-save-context-info '(time file olpath category todo itags ltags itags))
Archive Every Section Marked ‘DONE’ From Agenda Files Directory
(defun org-archive-done-tasks ()
(interactive)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (org-element-property :begin (org-element-at-point))))
"/DONE" 'file))
Archive Any Timestamps Passed
You can remove expired time-stamps
(defun org-archive-passed-timestamps ()
(interactive)
(org-map-entries
(lambda ()
(org-archive-subtree 16)
(setq org-map-continue-from (org-element-property :begin (org-element-at-point))))
"/DONE" 'file))
Require the Clock And Set to Persisteant
(require 'org-clock)
(setq org-clock-persist 'history)
Set Export Timestamp Format
You can change the format of your time stamps.
(setq org-export-date-timestamp-format "%d %b %Y ")
Remove Key Bindings From Org-mode
Remove key bindings you’re using elsewhere.
(define-key org-mode-map (kbd "M-S-<right>") nil)
(define-key org-mode-map (kbd "M-S-<down>") nil)
(define-key org-mode-map (kbd "M-S-<left>") nil)
(define-key org-mode-map (kbd "M-S-<up>") nil)
(define-key org-mode-map (kbd "C-i") nil) ; remove old binding
(define-key org-mode-map (kbd "C-i") 'insert-four) ; remove old binding
(define-key org-mode-map (kbd "C-<up>") nil) ; remove old binding
(define-key org-mode-map (kbd "C-<down>") nil) ; remove old binding
:bind
Directive
You can set the tab key to cycle through folding levels.
:bind
("<tab>" . org-cycle)
Close Org-Mode
);end-use package org-mode end-org-mode