literate-dotfiles/emacs-snippets.org

633 lines
16 KiB
Org Mode

#+TITLE: Doom Emacs Configuration
#+SETUPFILE: ./setup/org-setup-file.org
#+PROPERTY: header-args :comments none :eval no :mkdir yes :results none :padline no
* LaTeX
** Coordinate
#+begin_src conf :tangle ~/.config/doom/snippets/latex/coordinate
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :coordinate
# --
\coordinate[${1:->}] (${2:name}) at (${3:pointcoordinate});
$0
#+end_src
** Draw
#+begin_src conf :tangle ~/.config/doom/snippets/latex/draw
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :draw
# --
\draw[${1:->}] (${2:point1}) -- (${3:point2});
$0
#+end_src
** Node
#+begin_src conf :tangle ~/.config/doom/snippets/latex/node
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :node
# --
node[${1:below right}] (${2:name}) {${3:label}};
$0
#+end_src
** Path
#+begin_src conf :tangle ~/.config/doom/snippets/latex/path
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :path
# --
\path[${1}] (${2:point1}) -- (${3:point2});
$0
#+end_src
* Matlab
** Clear
#+begin_src conf :tangle ~/.config/doom/snippets/matlab/clear
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :clear and close all
# --
clear; close all; clc;
$0
#+end_src
** Function
#+begin_src conf :tangle ~/.config/doom/snippets/matlab/function
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :function
# --
function [${4:outputs}] = ${1:functionName}(${2:inputs}, ${3:opts_param})
% $1 - Description
%
% Syntax: $1($2, $3)
%
% Inputs:
% - $2 -
% - $3 - Optionals parameters: structure with the following fields:
% -
%
% Outputs:
% - $4 -
%% Default value for opts
opts = struct(...
'${5:outputs}', ${6:default_value} ...
);
if exist('opts_param','var')
for opt = fieldnames($3)'
if sum(strcmp(fieldnames(opts), opt{1})) == 1
opts.(opt{1}) = $3.(opt{1});
else
warning(sprintf('%s is not a valid option.', opt{1}));
end
end
end
$0
#+end_src
* Org Mode
** Begin
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/begin
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Environment
# --
\begin{${1:equation}}
$0
\end{$1}
#+end_src
** Caption
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/]c
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Caption
# --
#+caption: $0
#+end_src
** Block
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/block
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Org-Mode Block
#key: block
# --
#+begin_${1:$$(let ((type (yas-choose-value '("src" "example" "quote" "verse" "center" "latex" "html" "ascii"))))
(if type (concat type (if (equal type "src")
(concat " " (yas-choose-value '("emacs-lisp" "latex" "python" "sh" "matlab")))))))}
$0
#+end_${1:$(car (split-string yas-text))}
#+end_src
** Custom Box
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/cbox
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Custom Box
# --
#+attr_latex: :options [$1]{${2:blue}}{${3:ams nodisplayskip}}
#+begin_cbox
$0
#+end_cbox
#+end_src
** Latex Class
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/latex-class
#name: latex-class
#key: lc
#expand-env: ((classes (mapcar 'car org-latex-classes)))
# --
#+latex_class: ${1:$$(yas-choose-value classes)}
$0
#+end_src
** Bibliography with completion
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/bib
#name: bibliography with completion
#key: bib
# --
bibliography:${1:$$(yas-choose-value (org-ref-find-bibliography))}
#+end_src
** Cite
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/cite
#name: org-ref cite link
#key: cite
# --
cite:${1:$$(completing-read
"bibtex key: "
(let ((bibtex-files (org-ref-find-bibliography)))(bibtex-global-key-alist)))}
#+end_src
** Ref
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/ref
#name: org-ref ref link with completion
#key: ref
# --
ref:${1:$$(completing-read "label: " (org-ref-get-labels))}
#+end_src
** Beamer - CBOX
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/bcbox
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Beamer Custom Box
# --
,*** ${1:@@latex:@@} :B_cbox:
,:PROPERTIES:
:BEAMER_env: cbox
:BEAMER_opt: {${2:blue}}{${3:ams nodisplayskip}}
:END:
$0
#+end_src
** HTML Details
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/details
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :details
# --
#+HTML: <details><summary>${1:Figure}</summary>
$0
#+HTML: </details>
#+end_src
** Code
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/code
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Code
# --
#+caption: ${1:Listing Caption}
#+label: lst:${2:listing_name}
,#+begin_src ${3:listing_language}
$0
,#+end_src
#+end_src
** Equation
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/equation
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Equation
# --
#+name: eq:${1:equation_name}
\begin{equation}
$0
\end{equation}
#+end_src
** Figure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/figure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Figure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:Figure caption}
[[file:${3:figs/}$1.${4:pdf}]]
$0
#+end_src
** Frac
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/frac
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Fraction
# --
\frac{$1}{$2} $0
#+end_src
** Left
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/left
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Left Right mathematical delimitations
# --
\left$1 $0 \right$2
#+end_src
** Minipage
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minipage
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :minipage
# --
#+BEGIN_EXPORT latex
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth
$0
#+BEGIN_EXPORT latex
\end{minipage}%
\hfill%
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth
#+BEGIN_EXPORT latex
\end{minipage}
\end{figure}
#+END_EXPORT
#+end_src
** Minipage Figures
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minifig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Minipage with Figures
# --
#+attr_latex: :options [t]{${3:0.5\linewidth}}
#+begin_minipage
#+name: fig:$1
#+caption: ${2:Caption}
#+attr_latex: ${4::width \linewidth} :float nil
[[file:figs/${1:figure_name}.pdf]]
#+end_minipage
\hfill
#+attr_latex: :options [t]{${7:0.5\linewidth}}
#+begin_minipage
#+name: fig:$5
#+caption: ${6:Caption}
#+attr_latex: ${8::width \linewidth} :float nil
[[file:figs/${5:figure_name}.pdf]]
#+end_minipage
$0
#+end_src
** Wrap Figure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/wrapfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap Figure
# --
,#+attr_latex: :options {${1:rl}}{${2:0.45\textwidth}}
,#+begin_wrapfigure
,#+attr_latex: :${3:width \linewidth}
[[file:figs/${4:figure_name.pdf}]]
,#+end_wrapfigure
$0
#+end_src
** Multicolumn
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/multicolumn
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Multcolumn
# --
#+attr_latex: :float multicolumn
$0
#+end_src
** Subfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/subfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Subfigure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:figure caption}
#+attr_latex: :environment subfigure :width 0.49\linewidth :align c
| file:${3:sub_fig_name}.${4:pdf} | file:${5:sub_fig_name}.${6:pdf} |
| <<fig:$3>> ${7:sub figure caption} | <<fig:$5>> ${8:sub figure caption} |
$0
#+end_src
** Table
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/table
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Table
# --
#+name: tab:${1:table_name}
#+caption: ${2:Table caption}
#+attr_latex: :environment tabularx :width ${3:\linewidth} :align ${4:lXX}
#+attr_latex: :center t :booktabs t
| $0 | | |
|---+---+---|
| | | |
#+end_src
** Tikz
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikz
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz figure
# --
,#+begin_src latex :file ${1:figure_name}.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+end_src
** Tikzfig
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikzfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Figure
# --
#+NAME: fig:${1:figure_name}
#+HEADER: :headers '("\\\\usepackage{tikz}" "\\\\usepackage{import}" "\\\\import{$HOME/Cloud/thesis/LaTeX/}{config.tex}")
#+HEADER: :imagemagick t :fit yes :iminoptions -scale 100% -density 150 :imoutoptions -quality 100
#+HEADER: :results raw replace :buffer no :eval no-export :exports both :mkdirp yes
#+HEADER: :output-dir ${2:figs}
,#+begin_src latex :file $1.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+NAME: fig:$1
#+CAPTION: ${3:Caption}
#+RESULTS: fig:$1
#+end_src
** Tikzheader
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikzheader
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Header
# --
,* ${1:Title/Description of the figure}
,#+begin_src latex :file ${2:figure_name}.pdf :tangle figs/$2.tex :exports ${3:both}
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+name: fig:$2
#+caption: $1 ([[./figs/$2.png][png]], [[./figs/$2.pdf][pdf]], [[./figs/$2.tex][tex]]).
#+RESULTS:
[[file:./figs/$2.png]]
#+end_src
** User-config
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/user-config
# -*- mode: snippet -*-
# name: user-config
# key: uc
# --
,#+begin_src emacs-lisp :tangle user-config.el
$1
,#+end_src
#+end_src
** User-init
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/user-init
# -*- mode: snippet -*-
# name: user-init
# key: ui
# --
,#+begin_src emacs-lisp :tangle user-init.el
$1
,#+end_src
#+end_Sec
** Wrap
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/wrap
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap
# --
#+attr_latex: :float wrap
$0
#+end_src
** Python Specific
*** Pfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/pfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Python-Figure
# --
,#+begin_src jupyter-python :file ${2:filename}.png :results none
# Figure - ${1:description}
plt.figure(figsize=(${3:1200}/150, ${4:800}/150), dpi=150)
plt.clf
$0
plt.savefig('figs/$2.pdf', transparent=True, bbox_inches='tight', pad_inches=0)
,#+end_src
,#+name: fig:$2
,#+caption: $1
[[file:figs/$2.png]]
#+end_src
** Matlab Specific
*** Mconfig
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mconfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Configuration-Header
# --
#+PROPERTY: header-args:matlab :session *MATLAB*
#+PROPERTY: header-args:matlab+ :tangle ${1:filename}.m
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :noweb yes
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:matlab+ :output-dir ${2:figs}
$0
#+end_src
*** Mfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Figure
# --
,#+begin_src matlab :exports none :results none
%% ${1:description}
figure;
$0
,#+end_src
,#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/${2:filename}.pdf', 'width', '${3:full}', 'height', '${4:full}');
,#+end_src
,#+name: fig:$2
,#+caption: $1
,#+RESULTS:
[[file:figs/$2.png]]
#+end_src
*** Mfunction
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfunction
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Function
# --
,* ${1:Function Name}
:PROPERTIES:
:header-args:matlab+: :tangle src/${2:matlab_file_name}.m
:header-args:matlab+: :comments none :mkdirp yes :eval no
:END:
<<sec:$2>>
This Matlab function is accessible [[file:src/$2.m][here]].
,#+begin_src matlab
function [${4:in_data}] = $2(${3:in_data})
% $2 - $0
%
% Syntax: [$4] = $2($3)
%
% Inputs:
% - $3 -
%
% Outputs:
% - $4 -
end
,#+end_src
#+end_src
*** Mheader
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mheader
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Header
# --
,* ${1:Heading Name}
:PROPERTIES:
:header-args:matlab+: :tangle matlab/${2:matlab_file_name}.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
<<sec:$2>>
,** ZIP file containing the data and matlab files :ignore:
,#+begin_src bash :exports none :results none
if [ matlab/$2.m -nt data/$2.zip ]; then
cp matlab/$2.m $2.m;
zip data/$2 \
mat/data.mat \
$2.m
rm $2.m;
fi
,#+end_src
,#+begin_note
All the files (data and Matlab scripts) are accessible [[file:data/$2.zip][here]].
,#+end_note
$0
#+end_src
*** Minit
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minit
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Init
# --
,** Matlab Init :noexport:ignore:
,#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
<<matlab-dir>>
,#+end_src
,#+begin_src matlab :exports none :results silent :noweb yes
<<matlab-init>>
,#+end_src
$0
#+end_src
*** Mtable
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mtable
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Table
# --
,#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
data2orgtable(${1:data}, {${2:'rowlabel'}}, {${3:'collabel'}}, ' %.1f ');
,#+end_src
$0
#+end_src
*** Mvalue
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mvalue
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Value
# --
,#+begin_src matlab :results value replace :exports results :tangle no
sprintf('x = %.2g', x);
,#+end_src
$0
#+end_src
** Binary
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/binary
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Binary
# --
,* =${1:binary-name}= - ${2:Description}
:PROPERTIES:
:CUSTOM_ID: $1
:END:
,#+begin_src bash :tangle ~/.local/bin/$1
$0
,#+end_src
#+end_src
* Python
** Function
#+begin_src conf :tangle ~/.config/doom/snippets/python/de
# -*- coding: utf-8 -*-
# name: de
# contributor: Orestis Markou
# contributor: Yasser González Fernández <yglez@uh.cu>
# contributor: Tibor Simko <tibor.simko@cern.ch>
# --
def ${1:name}($2):
"""
$3
${2:$
(let* ((indent
(concat "\n" (make-string (current-column) 32)))
(args
(mapconcat
'(lambda (x)
(if (not (string= (nth 0 x) ""))
(concat "@param " (nth 0 x) ": " indent
"@type " (nth 0 x) ": ")))
(mapcar
'(lambda (x)
(mapcar
'(lambda (x)
(replace-regexp-in-string "[[:blank:]]*$" ""
(replace-regexp-in-string "^[[:blank:]]*" "" x)))
x))
(mapcar '(lambda (x) (split-string x "="))
(split-string text ",")))
indent)))
(if (string= args "")
(concat indent "@return: " indent "@rtype: " indent (make-string 3 34))
(mapconcat
'identity
(list "" args "@return: " "@rtype: " (make-string 3 34))
indent)))
}
$0
#+end_src