Table of Contents

C-h t tutorial

1 Create GitHub Pages:

GitHub Pages is easy for websites for you and your projects. GitHub Pages is hosted directly from your GitHub repository.Just edit, push, and your changes are live. Tutorial of how to create studying notes pages hosted on GitHub Pages.

1.1 Create a repository

Head over to Github and create a new repository named username.github.io, where username is your username on Github.

1.2 Clone the repository

Go to the folder where you want to store your project, and clone the new repository:

git clone https://github.com/username/username.github.io

1.3 Create folder structure

[[repository name]]
├── css/
├── img/
├── index.org
├── docs/
├── CS
└── sitemap.org

1.4 Add lines in spacemacs configuration file to publish the org project

(require 'ox-publish)
(setq org-publish-project-alist
'(
("org-notes"
 :base-directory "~/repository_folder/"
 :base-extension "org"
 :publishing-directory "~/repository_folder/docs/"
 :recursive t
 :publishing-function org-html-publish-to-html
 :headline-levels 4             ; Just the default for this project.
 :auto-preamble t
 )
("org-static"
 :base-directory "~/repository_folder/"
 :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
 :publishing-directory "~/repository_folder/docs/"
 :recursive t
 :publishing-function org-publish-attachment
 )
))

1.5 Publish personal html files

  • copy html and attachment folders under the main folder.
  • insert the link in the sitemap org file.
  • publish all.
  • copy html and attachment folder under the docs folder.

1.6 Attach markdown files in the org file.

1.7 Publish ipython file directly.

1.8 Insert file links in sitemap.org

[[file:remember.org][remember]]

1.9 The export options template

1.9.1 Insert basic information using C-c C-e # default

#+TITLE: filename with the extension omitted
#+DATE: <2013-06-04 Tue>
#+AUTHOR: Your name
#+EMAIL: Your email address
#+OPTIONS: ':t *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline author:t c:nil
#+OPTIONS: creator:comment d:(not LOGBOOK) date:t e:t email:nil f:t inline:t
#+OPTIONS: num:t p:nil pri:nil stat:t tags:t tasks:t tex:t timestamp:t toc:t
#+OPTIONS: todo:t |:t
#+CREATOR: Emacs 24.3.50.3 (Org mode 8.0.3)
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export

1.9.2 Add export templates configuration files

Create the following files under the org-configuration directory

  1. level-0.org

    :#+STYLE: <link rel="stylesheet" type="text/css" href="stylesheet.css" />

  2. level-1.org

    :#+STYLE: <link rel="stylesheet" type="text/css" href="../stylesheet.css" />

2 Basic operations in Emacs

2.1 special syntax

Insert file link: Press [[, file: file link, ], backspace, [, [alias, ], ].

2.2 insert table box

name1 name2
row1 value
   
| name 1 | name 2|,
|- tab,
enter,
|
  • Creation and conversion

C-c | (org-table-create-or-convert-from-region) Convert the active region to a table. If every line contains at least one TAB character, the function assumes that the material is tab separated. If every line contains a comma, comma-separated values (CSV) are assumed. If not, lines are split at whitespace into fields. You can use a prefix argument to force a specific separator: C-u forces CSV, C-u C-u forces TAB, C-u C-u C-u will prompt for a regular expression to match the separator, and a numeric argument N indicates that at least N consecutive spaces, or alternatively a TAB will be the separator.

  • Initial visibility

Show all shortcut: C-u C-u <TAB>, shirt+<TAB>

Or change the start-up configuration.

#+STARTUP: overview
#+STARTUP: content
#+STARTUP: showall
#+STARTUP: showeverything

2.3 shortcut :

获取帮助

  • C-h k 寻找快捷键的帮助信息: after the command enter the key combination.
  • C-h v 寻找变量的帮助信息
  • C-h f 寻找函数的帮助信息
  • C-l move the current cursor to the center of the screen.
  • <s, press tab to get the src box.
  • switch to the previous/next buffer

C-x <left>/<right>

  • define keyboard macro.

C-x ( or <f3> start defining a keyboard macro

C-x ) or <f4> stop defining the keyboard macro

And here is how to execute a keyboard macro you’ve defined: C-x e or f4 – execute the keyboard macro.

Here’s how to execute the macro 37 times (you use ‘C-u’ to provide the 37): C-u 37 C-x e

  • open a python buffer:

C-c C-p

  • open clipboard list:

C-;

  • project file view:

M-m p h

  • kill project buffer:

M-m k

命令 说明
M-a 定位到一行的开头
M-e 定位到一行的结尾
M-f 向前移动一个单词
M-b 向后移动一个单词
C-M-a 定位到函数头部
C-M-a 定位到函数结尾
C-M-h 选中整个函数
  • indent a block by number of space

C-u 4 C-x TAB C-M-\

  • dired jump, folder jump:

M-m f j

  • reload .emacs init.el without restart:

move to the end of the sexp C-x C-e or load the init.el file M-x load-file

3 ORG Mode

3.1 Structure editing

  • C-s C-w

emacs searches the next occurrence of the word.

  • M-s .

isearch-forward-symbol-at-point

  • C-h k

describe key combination

  • C-c C-x C-i

Clock in C-c C-x C-o Clock out C-c C-x C-x Clock back to the last task M-<RET> (org-insert-heading) Insert a new heading/item with the same level as the one at point. If the command is used at the beginning of a line, and if there is a heading or a plain list item (see Plain lists) at point, the new heading/item is created before the current line. When used at the beginning of a regular line of text, turn that line into a heading.

When this command is used in the middle of a line, the line is split and the rest of the line becomes the new item or headline. If you do not want the line to be split, customize org-M-RET-may-split-line.

Calling the command with a C-u prefix unconditionally inserts a new heading at the end of the current subtree, thus preserving its contents. With a double C-u C-u prefix, the new heading is created at the end of the parent subtree instead.

C-<RET> (org-insert-heading-respect-content) Insert a new heading at the end of the current subtree.

M-S-<RET> (org-insert-todo-heading) Insert new TODO entry with same level as current heading. See also the variable org-treat-insert-todo-heading-as-state-change.

C-S-<RET> (org-insert-todo-heading-respect-content) Insert new TODO entry with same level as current heading. Like C-<RET>, the new headline will be inserted after the current subtree.

<TAB> (org-cycle) In a new entry with no text yet, the first <TAB> demotes the entry to become a child of the previous one. The next <TAB> makes it a parent, and so on, all the way to top level. Yet another <TAB>, and you are back to the initial level.

M-<left> (org-do-promote) Promote current heading by one level.

M-<right> (org-do-demote) Demote current heading by one level.

M-S-<left> (org-promote-subtree) Promote the current subtree by one level.

M-S-<right> (org-demote-subtree) Demote the current subtree by one level.

M-S-<up> (org-move-subtree-up) Move subtree up (swap with previous subtree of same level).

M-S-<down> (org-move-subtree-down) Move subtree down (swap with next subtree of same level).

M-h (org-mark-element) Mark the element at point. Hitting repeatedly will mark subsequent elements of the one just marked. E.g., hitting <M-h> on a paragraph will mark it, hitting <M-h> immediately again will mark the next one.

C-c @ (org-mark-subtree) Mark the subtree at point. Hitting repeatedly will mark subsequent subtrees of the same level than the marked subtree.

C-c C-x C-w (org-cut-subtree) Kill subtree, i.e., remove it from buffer but save in kill ring. With a numeric prefix argument N, kill N sequential subtrees.

C-c C-x M-w (org-copy-subtree) Copy subtree to kill ring. With a numeric prefix argument N, copy the N sequential subtrees.

C-c C-x C-y (org-paste-subtree) Yank subtree from kill ring. This does modify the level of the subtree to make sure the tree fits in nicely at the yank position. The yank level can also be specified with a numeric prefix argument, or by yanking after a headline marker like ‘****’.

C-y (org-yank) Depending on the options org-yank-adjusted-subtrees and org-yank-folded-subtrees, Org's internal yank command will paste subtrees folded and in a clever way, using the same command as C-c C-x C-y. With the default settings, no level adjustment will take place, but the yanked tree will be folded unless doing so would swallow text previously visible. Any prefix argument to this command will force a normal yank to be executed, with the prefix passed along. A good way to force a normal yank is C-u C-y. If you use yank-pop after a yank, it will yank previous kill items plainly, without adjustment and folding.

C-c C-x c (org-clone-subtree-with-time-shift) Clone a subtree by making a number of sibling copies of it. You will be prompted for the number of copies to make, and you can also specify if any timestamps in the entry should be shifted. This can be useful, for example, to create a number of tasks related to a series of lectures to prepare. For more details, see the docstring of the command org-clone-subtree-with-time-shift.

C-c C-w (org-refile) Refile entry or region to a different location. See Refile and copy.

C-c ^ (org-sort) Sort same-level entries. When there is an active region, all entries in the region will be sorted. Otherwise the children of the current headline are sorted. The command prompts for the sorting method, which can be alphabetically, numerically, by time (first timestamp with active preferred, creation time, scheduled time, deadline time), by priority, by TODO keyword (in the sequence the keywords have been defined in the setup) or by the value of a property. Reverse sorting is possible as well. You can also supply your own function to extract the sorting key. With a C-u prefix, sorting will be case-sensitive.

C-x n s (org-narrow-to-subtree) Narrow buffer to current subtree.

C-x n b (org-narrow-to-block) Narrow buffer to current block.

C-x n w (widen) Widen buffer to remove narrowing.

C-c * (org-toggle-heading) Turn a normal line or plain list item into a headline (so that it becomes a subheading at its location). Also turn a headline into a normal line by removing the stars. If there is an active region, turn all lines in the region into headlines. If the first line in the region was an item, turn only the item lines into headlines. Finally, if the first line is a headline, remove the stars from all headlines in the region.

M-c capitalize the first letter of the word.

M-u Uppercase for the whole word.

M-d delete the whole word.

C-x C-u upcase-region.

c-x C-d downcase-region.

3.2 Latex

3.2.1 disable underscore to subscript

^:nil

3.2.2 Greeks:

\[\alpha, \beta, \gamma\]

3.2.3 Superscript, subscript

\[R_{sun} = 6.96 x 10^8 m\]

3.2.4 Derivatives, Limits, Sums and Integrals

\[\frac{du}{dt}\]

\frac{du}{dt}

the Heat Equation$$\[ \frac{\partial u}{\partial t} = h^2 \left( \frac{\partial^2 u}{\partial x^2}

  • \frac{\partial^2 u}{\partial y^2}
  • \frac{\partial^2 u}{\partial z^2} \right) \]$$
\[ \frac{\partial u}{\partial t}
   = h^2 \left( \frac{\partial^2 u}{\partial x^2}
      + \frac{\partial^2 u}{\partial y^2}
      + \frac{\partial^2 u}{\partial z^2} \right) \]

\[\lim_{x \to +\infty}, \inf_{x > s}\]

\lim_{x \to +\infty}, \inf_{x > s}

\[\[ \sum_{k=1}^n k^2 = \frac{1}{2} n (n+1).\] \]

\[ \sum_{k=1}^n k^2 = \frac{1}{2} n (n+1).\]

\[\[ \int_a^b f(x)\,dx.\] \]

\[ \int_a^b f(x)\,dx.\]

\[\[ \int_0^{+\infty} x^n e^{-x} \,dx = n!.\] \[ \int \cos \theta \,d\theta = \sin \theta.\] \[ \int_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy = \int_{\theta=0}^{2\pi} \int_{r=0}^R f(r\cos\theta,r\sin\theta) r\,dr\,d\theta.\] \]

\[ \int_0^{+\infty} x^n e^{-x} \,dx = n!.\]
\[ \int \cos \theta \,d\theta = \sin \theta.\]
\[ \int_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy
   = \int_{\theta=0}^{2\pi} \int_{r=0}^R
      f(r\cos\theta,r\sin\theta) r\,dr\,d\theta.\]

\[\[ \int \!\!\! \int_D f(x,y)\,dx\,dy.\] \]

\[ \int \!\!\! \int_D f(x,y)\,dx\,dy.\]

3.3 Insert image into org file

#+CAPTION: fiture title
./images/xxx.png
=C-c C-x C-v= to display toggled images.

3.4 ditaa figures

3.4.1 Connected elements with colors

ditaa-seqboxes.png

3.5 UML diagrams with PlantUML

3.5.1 Class diagrams

clientmodel.png

3.5.2 Sequences diagrams

3.6 export org to html using styles

3.7 graphviz

some_filename.png

3.8 output results:

#+RESULT:
:  output

3.9 setting tags:

Tags can simply be typed into the buffer at the end of a headline. After a colon, M-TAB offers completion on tags. There is also a special command for inserting tags:

C-c C-q Enter new tags for the current headline. Org mode will either offer completion or a special single-key interface for setting tags, see below. After pressing RET, the tags will be inserted and aligned to org-tags-column. When called with a C-u prefix, all tags in the current buffer will be aligned to that column, just to make things look nice.

C-c C-c When the cursor is in a headline, this does the same as C-c C-q.

4 emacs python workflow.

4.1 install elpy, jedi

4.1.1 elpy (Emacs Lisp Python Environment)

  • Automatic Indentation,
  • Syntax Highlighting,
  • Auto-Completion,
  • Syntax Checking,
  • Python REPL Integration,
  • Virtual Environment Support, and
sudo pip install jedi epc pylint flake8 ipython==5.3 yaft

install package jedi elpy magit

4.2 Keybinding

Keybinding Description
C-M-i anaconda-mode-complete
M-. anaconda-mode-find-definitions
M-, anaconda-mode-find-assignments
M-r anaconda-mode-find-references
M-* anaconda-mode-go-back
M-? anaconda-mode-show-doc
C-c M-l clear ipython debug buffer

4.3 upgrade git

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git -y
git --version

4.4 reinstall EMACS

Check emacs version.
$ emacs --version
Download the same emacs version you have installed in the past.
$ wget https://ftp.gnu.org/gnu/emacs/emacs-$VERSION.tar.xz
Extract tarball.
$ tar xJvf emacs-$VERSION.tar.xz
Run ./configure to generate the make file. If you remember the option you have given when you install it, add those command line flags, too. (e.g. --with-x=no)
$ cd emacs-$VERSION
$ ./configure
Do make uninstall to uninstall.
$ sudo make uninstall

4.5 Spacemacs Dired

Keybinding Description
SPC f j 打开 dired 目录
+ 创建目录
R Rename
C copy
D delete
qq exit
--- ---
C-x 4 d To display the Dired buffer in another window
q bury the Dired buffer
u undo
x execute flagged commands

4.6 magit

workflow Keybinding Description
init, commit    
  SPC g i magit-init
  SPC g s magit-status
  s-1 goto unstaged section
  TAB view diffs(code review)
  s stage all changes
  C-c C-c commit
Commits in Action    
  c a Ammend
  r squash unpushed commits
Branching basics    
  b B create branch
  m m merge
  b b switch branch
pull, push    
  P P  
  f f/ f o fetch branch
  F pull
  s-g send pull request
Misc M-m g s view github files
stage s stage
  u unstage
  c actions
  e extend current commit HEAD
  a amend commit msg
  r reword, discard commit msg
  s discard the latest commit
login 1 short logs
  h reflog

4.7 insert images and links

#+CAPTION: future contract
[[./image.png]]
C-c C-x C-v (org-toggle-inline-mages)

4.8 anaconda mode bug:

pyenv global anaconda3-4.4.0
# then
emacs
# then change global python to 5
pyenv global anaconda3-5.0.1

py-autopep8 py-autopep8-enable-on-save

5 layers

M-x configuration-layer/create-layer

6 Python mode

  • insert date/current date from shell to python file

C-u M-! date

7 Instruction on how to use emacs org mode to orginize calendar.

  • insert current date

C-c . <2017-08-11 Fri>

  • insert current date and time

C-u C-c . <2017-08-11 Fri 16:06>

  • set deadline for an item

C-c C-d

  • show deadline items due or due within 14 days

C-c / d

  • clock log in

C-c C-x C-i

  • clock log out

C-c C-x C-o

  • clock cancle

C-c C-x C-q

  • org-mode
#+TOC: headlines 3
#+INCLUDE: "./CS/Python/python2.org" :minlevel 1
#+BEGIN_COMMENT
Each major section of this document is defined in its own file.

You can jump to each file by moving the cursor on an "#+include" line
and typing =C-c '= Note: There is *no requirement* to split, but large
org-mode files can become quite slow to edit, so separate sections help
keeping things fluid...
#+END_COMMENT
#+LINK: gh    https://github.com/
#+LINK: rfc   https://tools.ietf.org/html/
#+LINK: thing https://github.com/thi-ng/
#+LINK: wiki  https://en.wikipedia.org/wiki/

7.1 navigation

  • set mark (activates and then deactivates region)

C-SPC C-SPC

  • bound to exchange-point-and-mark

C-x C-x

  • move to previous mark

C-u C-SPC