Emacs
chapter 2
Emacs
GNU Emacs An extensible, customizable, free/libre text editor — and more. At its core is an interpreter for Emacs Lisp, a dialect of the Lisp programming language with extensions to support text editing. …emacs
Install packages
Install org-plus-contrib
;; add this to your Emacs init file to be able to list the Org mode archives:
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
Then M-x list-packages RET will list both the latest org and
org-plus-contrib packages.
Org-mode
Create Headers
Start with an asterisk to make Headers and two asterisks for Subheaders
Example:
* Header
** Subheader
Give a title to your page using hash (#) and plus (+) symbols
Example: #+Title: Getting started with org-mode
Hide Numbers, table of contents
Example: #+Options: num:nil toc:nil
Write #+
and press Meta-<tab>
to see the list of variables
Example:
#+AUTHOR: Vasilis Agiomyrgianakis
#+DATE: 120416
Bulleting-Quoting
Use hyphen to make bullets
-
bulleted
-
list
-
items
You can include quotations in Org mode documents like this:
#+BEGIN_QUOTE
'QUATATION'
#+END_QUOTE
QUATATION
Markups
Give emphasis to your text.
Write your text inside the below symbols:
-
2 asterics for Bold,
-
2 slashes for italics,
-
2 equals signs for
verbatim
, -
2 pluses for
strike through text
Bold, italics, verbatim
, strikethrough
Linking
Press C-c C-l
to link objects (files)
Example:
Link: https/:basmyr.net/
Then give a name to the linked text
Description: Basmyr.net
Press C-c C-o
to open the linked plain text with an external program
or a video url
Tables
Use pipes - vertical bars to make tables
Example: Start with pipes and some text:
| some | | Data |
then hit return, pipe (vertical bar), hyphen and tab to extend the table verticaly
Press tab and the arrows keys to make arrangements on the table
Some | Data |
---|---|
234 | muons |
1200 | jets |
Images & Graphics
Images
To insert an image with descriptions do the following:
Example-images
#+Caption: This is my image #+Name: Fig 1 [[./images/myimage]]
Ditaa
#+BEGIN_SRC ditaa :file image/awesome.png
_ \_ _ _ _ _ _ __ _ //_\\ \ /\ / / _ \ _|/ _ \| ' ` _ \ / _ \ / _ \ V V / /\ \ (_) | | | | | | __/ \_/ \_/\_/\_/ \___||___/\___/|_| |_| |_|\___|
#+END_SRC
C-c C-c
to evaluate lisp code inside source block
Find the path of ditaa.jar in you computer through a lisp program
(expand-file-name
"ditaa.jar"
(file-name-as-directory
(expand-file-name
"scripts"
(file-name-as-directory
(expand-file-name
"../contrib"
(file-name-directory (org-find-library-dir "org")))))))
Export to other formats
Pressing C-c C-e
popups a buffer to export markups to HTML-PDF-etc.
Example: hit h
and o
if you want to export and open as html.
Export Beamer: C-c C-e l P
(org-beamer-export-to-pdf)
Export PDF: C-c C-e l O
To export and open pdf make sure you have installed Mactex with extras no the basic version.
Export as LaTeX, and open PDF file.
Source Code
Create code blocks to insert your code.
Press C-c '
inside the SRC block to edit the current code block
in the mode of the language you want. For instance:
#+BEGIN_SRC emacs-lisp
write some lisp to make your configurations in org-mode
so as to see bullets (UTF-8 characters) when you editing Headers in org-mode instead of asterisks.
Then close the source block with:
#+END_SRC
Result
(require 'org-bullets)
(add-hook 'org-mode-hook
(lambda () (org-bullets-mode 1)))
You can customise source blocks using M-x customize-face RET
face RET
Evaluate source code. Press C-c C-c inside the block and see the results.
echo "Hello $USER! Today is `date`"
LaTeX integrator
-
Characters: α → β
-
$O(n \log n)$
\begin{align*}
q = 2 * 4 + 1 - 2 &= 7
q &=7
\end{align*}
Shortcuts Tips
write down <s
and press tab
to open src blocks,
<q
tab for Quotes,
<e
tab for Examples
<c
tab for Center
etc.
to cooment a lisp
region select a word or a region with C-M-space and then M-; to comment
For symbols such as degrees ° use the shortcut C-x 8 o
To check mapped symbols do C-x 8 C-h
For Footnotes use fn:1
##Example Footnotes## i.e. The earth is round ...[fn:1] [fn:1] It has actually been known that the Earth was round since the time of the ancient Greeks. I believe that it was Pythagoras who first proposed that the Earth was round sometime around 500 B.C.(https://starchild.gsfc.nasa.gov/docs/StarChild/questions/question54.html)
Change read-only files on emacs
M-x toggle-read-only
TO DO
type TODO to create a todo object
Move the cursor one line after the TODO item and press C-c C-s
(org-schedule)
to schedule with agenda
TODO Call John SCHEDULED:
TODO read this and that SCHEDULED:
DONE export html minted (highlight colour - syntax source blocks) SCHEDULED:
To open week-agenda window press C-ca To schedule a TODO item press C-c C-s Use shift-arrows to change dates
Github
Introduction to Environments (Github or Bitbucket) for organizing and sharing files-Git. Set up an account with Slack and Github.
Github
organize projects and share the individual processes using tools such as mass communication techniques Slack-Git.
Git:
-
Create a Repository
-
Create a Branch
-
Make a Commit
-
Push and Commit.
Https://guides.github.com/activities/hello-world/, Https://gist.github.com/davfre/8313299
install package magit and usage
Magit
Download Magit
Install Magit using MELPA
Dired to the folder you want to create the .git file and press
M-x magit-init
and press y
Then press M-x magit-remote-add
add remote rep to master or origin
Backup rep online on Github
First, create an ssh key to gain access into your repositories
Concatanate keys on terminal
ie. //cat id_rsa.pub | pbcopy
Press C-x m
to display information about the current Git repository
Press C-x g
for magit-status
s
to stage files
c-c
(write a comment) and then press C-c C-c
to commit
The next step is to push to a remote branch on Github.
Press Shift-p p
to push to a remote branch (master).
P-p
to push to remote
Pull requests
If you use more than one computers for the same repo you need to pull first and then to push to remote repo.
On magit press F
and p
to pull to master.
Then you are able to push into the location of this exact repository
from your other computer. If later you want to upadate changes in your
first computer you need to pull again and then push.
NOTE
This seems a little bit tricky but it might happen.
You might need to change the url of your repo in your first computer in case you didn't choose the same name for the folder where your project is located in your second computer. This happens, in case you first created the repo for example, in your laptop, in a folder named project1 and built your site i.e hugo, and then pull this repo into a folder with the name project2 in your other computer.
To change the repo address go to your .git folder inside your poroject
and open config
file. Then change the repo address to the new one.
i.e in config
replace the old url with the new one:
[remote "origin"]
url = git@github.com:User/project1.git
url = git@github.com:User/project2.git
After you did this you will be able to push again from your first computer.
other issues
-
Git refusing to merge unrelated histories
git cherry-pick -m 1 1234deadbeef1234deadbeef git rebase –continue
merge
Git failed…
Git refusing to merge unrelated histories
in magit press h to bring the popoup window and choose rebase -r and then -p
Install Dictionaries -emacs
Install aspell with brew
$ brew install aspell --with-lang-en --with-lang-el --with-lang-de
for English, Hellenic and Deutsch languages.
if you have problems installing aspell with the above code
just do only:
$ brew install aspell
Install aspell using downloaded packages aspell-0.60.6.1
go to terminal and type:
$ cd ~/aspell path
$ ./configure
$ make
$ make install
To install additional dictionary download the language you prefer from GNU_Available Aspell Dictionaries
i.e aspell-el-0.50-3
for Hellenic language (Greek)
and go to terminal and type:
$ cd ~/dictionary path
$ ./configure
$ make
$ install
Switch dictionary
To switch between dictionaries run:
M-x: ispell-change-dictionary
and write greek for Hellenic language auto-correct
Press F6 (fn-F6) to switch between dictionaries (british, greek, german)
If you want to use the english dictionary in a particular buffer instead, put the following on the first line of the buffer:
-*- ispell-dictionary: "english" -*-
Use flyspell instead of ispell
(setq ispell-list-command "--list")
text expansion
install YASnippet using MELPA
put the below into your init.el
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
quit emacs and open again and type
M-x yas-new-snippet
-
Give a name to your snippet
-
give the abrev
-
write your text or code you want to be expanted
-
save file C-c C-c
-
choose a table i.e prog-mode
-
give a name to your snippet (I use the abrev key as the name)
try using the abrev key and press tab to expant your text.
Searching
Press C-s
to search with I-search.
You can also try:
C-h f (or M-x describe-function) will show you the bindings for a command. C-h b (or M-x describe-bindings) will show you all bindings. C-h m (M-x describe-mode) is also handy to list bindings by mode. You might also try C-h k (M-x describe-key) to show what command is bound to a key.
See also helm swoop
There is also the projectile
. To use projectile make sure you have created a
.git repo into your project.
Press C-cpp
to open projectile
and search for projects
Export references to pdf with org-mode - bibtex
The word ,,BibTeX'' stands for a tool and a file format which are used to describe and process lists of references, mostly in conjunction with LaTeX documents_1.
Set up
First put the bellow code in your init.el ./emacs.d
;; Bibtex-latex export citation
(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))
Your next step is to create a .bib file with your citations and name it i.e: test-bib-refs
Examples of bibtex style references
[1]
@ARTICLE{2011ApJS..192....9T,
author = {{Turk}, M.~J. and {Smith}, B.~D. and {Oishi}, J.~S. and {Skory}, S. and
{Skillman}, S.~W. and {Abel}, T. and {Norman}, M.~L.},
title = "{yt: A Multi-code Analysis Toolkit for Astrophysical Simulation Data}",
journal = {The Astrophysical Journal Supplement Series},
archivePrefix = "arXiv",
eprint = {1011.3514},
primaryClass = "astro-ph.IM",
keywords = {cosmology: theory, methods: data analysis, methods: numerical },
year = 2011,
month = jan,
volume = 192,
eid = {9},
pages = {9},
doi = {10.1088/0067-0049/192/1/9},
adsurl = {http://adsabs.harvard.edu/abs/2011ApJS..192....9T},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
another example:
[2]
@InProceedings{ alejandro_weinstein-proc-scipy-2016,
author = { {A}lejandro {W}einstein and {W}ael {E}l-{D}eredy and {S}téren {C}habert and {M}yriam {F}uentes },
title = { {F}itting {H}uman {D}ecision {M}aking {M}odels using {P}ython },
booktitle = { {P}roceedings of the 15th {P}ython in {S}cience {C}onference },
pages = { 1 - 6 },
year = { 2016 },
editor = { {S}ebastian {B}enthall and {S}cott {R}ostrup }
}
then use these latex commands inside your org file
Tests in org file
Latex
Example of citation
…this toolkit\cite{2011ApJS..192….9T}.
another example
…in python\cite{alejandro_weinstein-proc-scipy-2016}.
…
\printbibliography
*Note: put
\printbibliography
at the end so as to print the references section last on your text.
Then press C–c C-e to open org export dispatcher and then press l and o to export and open the pdf.
Emacs-G++
G++ Hello_World
Create a folder hello_world. cd in this folder and create a file hello_world.cpp
copy the below code and paste it into hello_world.cpp file
/*hello_world.cpp*/
#include <iostream>
using namespace std;
int main() {
cout << "hello world!" << endl;
return 0;
}
The next step is to create a makefile.
Use the bellow code.
=hello_world: hello_world.cpp
[TAB]g++ -Wall -g hello_world.cpp -o hello_world=
then go back (M-x b) to the hello_world.cpp and press C-x c
to run the programm.
you will see a 'hello world' message.
Create and Run a programm with multiple source files
On emacs create a folder [use dired to the direction you want to create
the folder and press Shift-+
and give a name] then dired to the folder and create 5 source files:
-
main.cpp, which reffers to the main programm,
-
Point.h, which is the header file for the Point class,
-
Point.cpp, which is the implementation file for the Point class,
-
Line.h, header file for the Line class,
-
Line.cpp, which is the implementation file for the Line class.
Compiling source code
Compile its source code using the -c flag with the compiler.
i.e.
% g++ -c main.cpp
% g++ -c Point.cpp
% g++ -c Line.cpp
This process generates object files .o
The next step is to link the object files into an executable
% g++ -o main main.o Point.o Line.o
makefile
The makefile tells make
how to compile and link a program.
A makefile consists of rules with the following shape:
target … : prerequisites … recipe … …
Create a makefile
open emacs and dired to the folder with the .cpp and .o files and
create a makefile
. This file genereates the executable main
The one part is to set the variables
you need to use in a simple makefile. These are variables
which specify the C++ compiler and linker, as well as, flags
for the compiler, etc.
-
Variables
Compiler
Comp = g++
Compiler Flags
CompFL = -Wall -g
-
-Wall: This enables all the warnings about constructions that some
users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.
-
-W or -Wextra: This enables some extra warning flags that are not enabled by Wall.
-
-Werror: Make the specified warning into an error.
and the other part is to set the targets
which can be files to be
generated.
-
Targets
#Targets needed to bring the executable up to date
main: main.o Point.o Rectangle.o
[TAB] $(Comp) $(CompFL) -o main main.o Point.o Line.o
# If we haven't set the variables Comp and CompFL the code would be like
# this:
# g++ -Wall -g -o main main.o Point.o Line.o
# The main.o target can be written more simply
main.o: main.cpp Point.h Line.h
[TAB] $(Comp) $(CompFL) -c main.cpp
Point.o: Point.h
Line.o: Line.h Point.h
To comment a make file use #
After creating the makefile choose the main.cpp file and press C-x c
and then hit enter
to begin the compilation.
Clone the below repository to create a tetraedron and also to see an example of how to set up a makefile for OpenGL and GLUT framewroks.
SSH: git@github.com:Vasileios/Gpp.git
for more info see GNU makefile
cmake
-
cmake Conways's Game of Life
-
Compiling objects with g++ and SFML
-
cmake
Click the below links to download and install sfml:
You can also read the instructions of building SFML with cmake:
Clone this repository and run the famous cellular automata Conway's Game of Life.
On terminal, cd to the folder and use this command:
cmake -G"Xcode" -DSFML=/usr/local/include
Running 3d graphics g++
clone this repo
https://github.com/scanberg/particle-skinning
Requirements - glm, assimp, qt5
brew install qt5
brew install glm
brew install assimp
open main.cpp on emacs and hit C-x c
to make the program.