Difference between revisions of "Emacs and org-mode notes"

From Notes_Wiki
m
m
Line 78: Line 78:
|-
|-
| C-c C-s                        || Schedule an event (Shortcut for adding SCHEDULED: )
| C-c C-s                        || Schedule an event (Shortcut for adding SCHEDULED: )
|-
| C-c C-d                        || Mark dead-line for an event (Shortcut for adding DEADLINE: )
|-
|-
|}
|}
Line 154: Line 156:
| org-mode                          || To change to org mode. In case extension of file being edited is not .org, we may need to shift to org mode manually.  
| org-mode                          || To change to org mode. In case extension of file being edited is not .org, we may need to shift to org mode manually.  
|-
|-
| org-export-as- [pdf or html or ...] || Export current org file to given format. Many different formats including LaTeX are supported.
| org-export-as- [pdf or html or ...] || Export current org file to given format. Many different formats including LaTeX, odt (which can be converted to doc or docx using libreoffice), HTML are supported.  
|-
|-
| org-insert-export-options-template || Inserts options like Title, Date, etc. at top of file which help in exporting org files to other formats
| org-insert-export-options-template || Inserts options like Title, Date, etc. at top of file which help in exporting org files to other formats
Line 289: Line 291:
==Linking sections in org-mode==
==Linking sections in org-mode==


To link to other section or sub-section in org-mode one can refer to other section using '[[<section-name>]]' where section-name should be exactly as specified while defining the section
There are two methods of linking to sections in org-mode:
1. Through name
2. Through number
 
===Linking to another section using name===
To link to other section or sub-section using name use '[[<section-name>]]' where section-name should be exactly as specified while defining the section.  This will generate link to another section using name.
 
 
===Linking to another section using section number===
If link to another section is desired by section number instead of name then label the section using
<pre>
#+LABEL: &lt;section-label&gt;
</pre>
and then refer to section using '<tt>\ref{&lt;section-label&gt;}</tt>'
 
 
 
==Table captions and labels==
 
One can give caption and label to tables so that table appears with caption and also so that one can refer to the table using table number later on.  To give caption and label to a table use:
<pre>
#+CAPTION: &lt;Caption for table&gt;
#+LABEL:  &lt;Label for table&gt;
</pre>
Then table can be referred later using '<tt>Table\nbsp\ref{&lt;Label for table&gt;}</tt>'.  '''Note that \nbsp sequence should not be used inside tables as it causes problems with LaTeX export'''.




<yambe:breadcrumb>Emacs</yambe:breadcrumb>
<yambe:breadcrumb>Emacs</yambe:breadcrumb>

Revision as of 04:52, 17 March 2013

<yambe:breadcrumb>Emacs</yambe:breadcrumb>

Keyboard shortcuts

File related shortcuts

Shortcut Description
C-x C-s Save file
C-x d List directory contents so that we can choose which file to edit from directory listing


Editing shortcuts

Shortcut Description
C-u <number> <command> Repeat command that follows given number of times.
C-g Cancel previous command. Note that we cannot use Esc and we should use C-g to cancel previous command.
C-x u
C-_
C-/
Undo
C-k Kill from cursor position to end of line
C-@ or C-<space> Start selecting text from cursor position
C-w Cut selected text
C-y Paste text from clipboard to current location
M-y This has to be used just after using C-y. This would change the pasted text to older text that was cut or killed. Emacs remembers all the different killed texts and we can paste older text by using M-y repeatedly after we have used C-y once to restore latest killed text.
C-x C++ To increase font-size
C-x C+- To decrease font-size
M-q To wrap paragraph properly as per set fill-width value
C-s Forward incremental search
C-s C-s Repeat last incremental search
C-r Reverse incremental search


Org-mode shortcuts

Shortcut Description
<pipe><hypen> followed by tab To create a table in org mode. The same shortcut also completes a table row
M-ret To split long text within table so that it spans multiple lines.
C-c C-q Apply tag to given section, sub-section etc. Note that tags cannot be applied to bullets started with -
Tab (at heading) Change detail of display of sub-headings of current heading
Shift-tab (at first heading) Change detail of display of all sub-headings in file
C-c . Insert active date using calendar. Calendar accepts options such as . (today), +1 (tomorrow), -1 (yesterday), etc. One can also use Shift+<arrow_keys> to change selected date in displayed calendar
C-c ! Insert inactive date
C-c . <choose_date> C-c . Insert active date range
M-<left-arrow> Decrease level of sub-section or sub-sub-section heading. That is convert sub-section to section or sub-sub-section to sub-section etc.
M-<right-arrow> Increase level of section or sub-section heading. That is convert section to sub-section or sub-section to sub-sub-section etc.
C-c C-s Schedule an event (Shortcut for adding SCHEDULED: )
C-c C-d Mark dead-line for an event (Shortcut for adding DEADLINE: )


View related shortcuts

Shortcut Description
C-x 0 Delete current window
C-x 1 Expand current buffer to fullscreen and hide all other buffers
C-x 2 Split current window into two sections
C-c C-o Visit link
C-x k kill buffer
C-x b switch buffer (Press tab for auto-complete and suggestions)
C-x C-b List all buffers
C-x o Switch to other visible buffers


Help related shortcuts

Shortcut Description
C-h k <key> Gives help about key in a split window
C-h m Mode help
C-h a PATTERN Help on commands that match given pattern
C-h d PATTERN Help on functions and variables that match given pattern
C-h b List of current key bindings
C-h c Displays command run by given key sequence


Commands

Generic commands

Command Description
buffer-menu Shows list of all buffers to choose from
ispell-buffer Check text in current buffer for spelling errors. One should shift to flyspell-mode by using 'flyspell-mode' command before using ispell for correcting spelling errors. By defaul emacs uses hunspell and stores the private dictionary in '~/.hunspell_en_US' file.


Org-mode commands

Command Description
org-table-delete-column To delete column from org mode table
org-mode To change to org mode. In case extension of file being edited is not .org, we may need to shift to org mode manually.
org-export-as- [pdf or html or ...] Export current org file to given format. Many different formats including LaTeX, odt (which can be converted to doc or docx using libreoffice), HTML are supported.
org-insert-export-options-template Inserts options like Title, Date, etc. at top of file which help in exporting org files to other formats



Configuration

General configuration

Configuration option Description
(setq make-backup-files nil) Prevents emacs from creating backup files while saving
(global-visual-line-mode 1) Enables visual-line-mode in all buffers by default
(set-fill-column 60) To ensure lines wrap at 60 in text-modes. After this also change mode using auto-fill-mode command.
(setq-default fill-column 60)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Use these two enable automated form-fill for 60 columns when emacs starts
(set-face-attribute 'default nil :height 160) Unit is 1/10pt, so for 10pt font 100 should be used
(setq x-select-enable-clipboard t) Make emacs copy-paste M-w, C-y work with system copy-paste
(setq auto-save-default nil) Preventing emacs from creating auto-save files



Tips / Techniques

To do list using org mode

We can build todo lists using org-mode. For that we should create bullted list using - below a heading or a sub-heading. The hypen should be followed by [ ] empty square braces. We should also put [1/1] in front of sub-heading / heading under which we have built bulleted list. Then we can use C-c C-c shortcut to mark / unmark any item and the count gets reflected at top of list.

Pop-buffer menu using mouse click

If we use single left click while keeping control key pressed on any buffer then we get popup buffer menu for switching buffers which can be very useful to switch buffers when working on multiple files.


Linking to other files

To link to other files using org-mode syntax is:

[[URL][Title]]

where, URL can be of many different formats such as:


Tagging sections or sub-sections

To tag sections or sub-sections using org first we need to add TAGS line such as:

#+TAGS: Saurabh(b) Swetha(w) Swaroop(r) Mahesh(m) Nirmala(n)

and then use C-c C-c short-cut on TAGS line to make emacs reload the buffer. Then one can go to any section or sub-section (Note that it wont work for bulleted or numbered list) and use C-c C-q shortcut to assign a tag.


Using org-timeline

Org can prepare a time-line for sections, sub-sections etc. which have data 'SCHEDULED:' as their body. This feature is very useful to mark events which are fixed such as weekly meetings or important appointments which cannot be rescheduled or missed unless emergency. To create a weekly recurrent schedule event one can use something like:

** TODO Friday VLEAD meetings from 11:00am to 01:00pm
   SCHEDULED: <2012-12-21 Fri 11:00-13:00 +1w>

Note that in this case once the meeting date is passed, the org-timeline will still continue to show the same old date such as 2012-12-21 in above case. To make the date point to next week (+1w) one can use C-c C-t short-cut on the section title. It would generate few extra lines which can be optionally removed.

Similarly to schedule a one-time event in a to-do list one can use something like:

** To do list for [2012-12-28 Fri]
*** Select TA(s) for Virtualization course at 03:30pm
    SCHEDULED: <2012-12-28 Fri>

All such events weekly or one-time can then be viewed in a useful manner using 'org-timeline' command.


Including pictures in org-mode

To include image in org-file such that it appears properly in both HTML and LaTeX outputs use:

#+CAPTION: <caption>
#+ATTR_HTML: alt="<alt-text>"
#+LABEL:      <label>
#+ATTR_LaTeX: width=\textwidth
[[<path-to-image-file>]]

For example,

#+CAPTION: All types of files
#+ATTR_HTML: alt="All types of files" title="All types of files"
#+LABEL:      fig:all-files
#+ATTR_LaTeX: width=\textwidth
[[./all_files.png]]

Note that just specifying name of file with "file:<path>" without using [[ and ]] for linking may not work.

Learned from http://orgmode.org/manual/Images-in-LaTeX-export.html and http://orgmode.org/manual/Images-in-HTML-export.html


Recording and playing macros

Emacs supports recording of keyboard macros and later playing them to achieve desired repeatability. Various short-cuts related to recording and playing macros are:

Keyboard shortcut Description
C-x ( Start recording keyboard macro
C-x ) Stop recording keyboard macro
C-x e Play recorded macro
C-u <n> C-x e Play recorded macro n times

Note that unlike vim, emacs only supports recording of one macro at at time.


Linking sections in org-mode

There are two methods of linking to sections in org-mode: 1. Through name 2. Through number

Linking to another section using name

To link to other section or sub-section using name use '[[<section-name>]]' where section-name should be exactly as specified while defining the section. This will generate link to another section using name.


Linking to another section using section number

If link to another section is desired by section number instead of name then label the section using

#+LABEL: <section-label>

and then refer to section using '\ref{<section-label>}'


Table captions and labels

One can give caption and label to tables so that table appears with caption and also so that one can refer to the table using table number later on. To give caption and label to a table use:

#+CAPTION: <Caption for table>
#+LABEL:   <Label for table>

Then table can be referred later using 'Table\nbsp\ref{<Label for table>}'. Note that \nbsp sequence should not be used inside tables as it causes problems with LaTeX export.


<yambe:breadcrumb>Emacs</yambe:breadcrumb>