1 \documentclass[aspectratio=169]{beamer}
4 \defaultfontfeatures{Ligatures=TeX,Mapping=tex-text}
5 \usepackage[russian]{babel}
6 \usepackage[utf8]{inputenc}
7 \usepackage[normalem]{ulem} % для \sout
10 %\usepackage{tikz} % FIXME не уверен что все это тут надо
11 %\usetikzlibrary{chains}
13 % Цвета для гиперссылок
14 \definecolor{linkcolor}{HTML}{799B03} % цвет ссылок
15 \definecolor{urlcolor}{HTML}{6633FF} % цвет гиперссылок
17 \hypersetup{pdfstartview=FitH, linkcolor=linkcolor,urlcolor=urlcolor, colorlinks=true}
19 \title{Git and vim for PostgreSQL developers}
20 \author{Nikolay Shaplov}
23 % Добавляем подпапку к пути поиска .sty/.tex
24 \def\input@path{{./theme.nonfree}}
29 \input{elements/code.tex}
37 % FIXME introduction page
39 % FIXME QR-code link to slides
42 \begin{frame}{General topic}
44 If you want to write well, you should read a lot.
45 And you'd better read best samples you can find.
47 PostgreSQL is one of the finest C\text{-}driven project one can get.
49 In this talk we will learn how to use git and vim to read and explore PostgreSQL code right in the console.
53 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 {\setbeamertemplate{background}{
57 \node[anchor=south west, inner sep=0] at (0,0) {\includegraphics[width=\the\paperwidth, height=\the\paperheight]{theme.nonfree/bgpics/pgpro_title_bg2.png}};
58 \node[anchor=east] at(\textwidth+1cm,0.5cm) {\color{white}\tiny\insertframenumber};
61 \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
62 \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
69 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 \begin{frame}[fragile, shrink=10]{Git, fetching the source code}
73 In order to get latest snapshot of PostgreSQL code you should run command:
75 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
76 $ git clone https://git.postgresql.org/git/postgresql.git \end{lstlisting}
78 If that command does not work for you, may be you just need to install `git` package
80 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
81 $ sudo apt-get install git\end{lstlisting}
85 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 {\setbeamertemplate{background}{
89 \node[anchor=south west, inner sep=0] at (0,0) {\includegraphics[width=\the\paperwidth, height=\the\paperheight]{theme.nonfree/bgpics/pgpro_title_bg2.png}};
90 \node[anchor=east] at(\textwidth+1cm,0.5cm) {\color{white}\tiny\insertframenumber};
93 \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
94 \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
101 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 \begin{frame}[fragile, shrink=10]{Why vim?}
106 \item Masterclass is when expert shows how he works. And I work with vim
107 \item We will need complex navigation methods to browse the code, that is not provided by simple editors
108 \item If you work with the console, you are much closer to system level than in modern IDE
109 \item You may consider this as an excursion into history
110 \item Vim is actually a professional tool providing very high speed of coding
111 \item Most students find vim very useful as soon as they learn how to do basic things
115 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 {\setbeamertemplate{background}{
120 \node[anchor=south west, inner sep=0] at (0,0) {\includegraphics[width=\the\paperwidth, height=\the\paperheight]{theme.nonfree/bgpics/pgpro_title_bg2.png}};
121 \node[anchor=east] at(\textwidth+1cm,0.5cm) {\color{white}\tiny\insertframenumber};
124 \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
125 \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
132 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 \begin{frame}[fragile, shrink=10]{Vim myths}
136 \item There are two main modes in vim:
139 \item Mess everything up
142 % \emph{~~~ No, this is one mode}
144 % \item \sout{You can't quit vim}
146 % \emph{~~~ No. Vim is \underline{not} Hotel California.}
148 % \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
150 % \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
153 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
157 \begin{frame}[fragile, shrink=10]{Vim myths}
159 \item \sout{There are two main modes in vim:}
162 \item \sout{Mess everything up}
165 \emph{~~~ No, this is one mode}
167 % \item \sout{You can't quit vim}
169 % \emph{~~~ No. Vim is \underline{not} Hotel California.}
171 % \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
173 % \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
176 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
180 \begin{frame}[fragile, shrink=10]{Vim myths}
182 \item \sout{There are two main modes in vim:}
185 \item \sout{Mess everything up}
188 \emph{~~~ No, this is one mode}
190 \item You can't quit vim
192 % \emph{~~~ No. Vim is \underline{not} Hotel California.}
194 % \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
196 % \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
198 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
203 \begin{frame}[fragile, shrink=10]{Vim myths}
205 \item \sout{There are two main modes in vim:}
208 \item \sout{Mess everything up}
211 \emph{~~~ No, this is one mode}
213 \item \sout{You can't quit vim}
215 \emph{~~~ No. Vim is \underline{not} Hotel California.}
217 % \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
219 % \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
221 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
225 \begin{frame}[fragile, shrink=10]{Vim myths}
227 \item \sout{There are two main modes in vim:}
230 \item \sout{Mess everything up}
233 \emph{~~~ No, this is one mode}
235 \item \sout{You can't quit vim}
237 \emph{~~~ No. Vim is \underline{not} Hotel California.}
239 \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
241 % \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
243 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
246 \begin{frame}[fragile, shrink=10]{Vim myths}
248 \item \sout{There are two main modes in vim:}
251 \item \sout{Mess everything up}
254 \emph{~~~ No, this is one mode}
256 \item \sout{You can't quit vim}
258 \emph{~~~ No. Vim is \underline{not} Hotel California.}
260 \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
262 \item One need MIDI Foot Controller Pedal to properly work with vim
264 % \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
267 \begin{frame}[fragile, shrink=10]{Vim myths}
269 \item \sout{There are two main modes in vim:}
272 \item \sout{Mess everything up}
275 \emph{~~~ No, this is one mode}
277 \item \sout{You can't quit vim}
279 \emph{~~~ No. Vim is \underline{not} Hotel California.}
281 \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
283 \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
285 \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
288 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 \input{elements/diag.tex}
292 \begin{frame}{Vim modes}
293 \resizebox{0.8\textwidth}{!}{
294 \begin{tikzpicture}[start chain=going below, node distance=12mm and 32mm] % начало цепочки
295 \node (insert_mode)[Rectangle]{Insert mode};
296 \node (command_mode)[Rectangle]{Command mode};
297 \node (search_mode)[Rectangle]{Search mode}; % FIXME убедиться, что режим поиска -- правильное название.
299 \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
300 \end{tikzpicture} % конец блока
305 \usetikzlibrary{arrows.meta}
307 \begin{frame}{Vim modes}
308 \resizebox{0.8\textwidth}{!}{
309 \begin{tikzpicture}[start chain=going below, node distance=12mm and 32mm, >={Stealth[scale=1.5]} ] % начало цепочки
310 \node (insert_mode)[Rectangle]{Insert mode};
311 \node (command_mode)[Rectangle]{Command mode};
312 \node (search_mode)[Rectangle]{Search mode}; % FIXME убедиться, что режим поиска -- правильное название.
314 \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
316 \path[->] (normal_mode.east) edge node[midway, above, sloped, yshift=32pt]{ i / Ins } (insert_mode.west);
317 \path[->] (normal_mode.east) edge node[midway, above, sloped, yshift=32pt]{ : } (command_mode.west);
318 \path[->] (normal_mode.east) edge node[midway, below, yshift=32pt]{ / } (search_mode.west);
320 \end{tikzpicture} % конец блока
324 \begin{frame}{Vim modes}
325 \resizebox{0.8\textwidth}{!}{
326 \begin{tikzpicture}[start chain=going below, node distance=12mm and 32mm, >={Stealth[scale=1.5]} ] % начало цепочки
327 \node (insert_mode)[Rectangle]{Insert mode};
328 \node (command_mode)[Rectangle]{Command mode};
329 \node (search_mode)[Rectangle]{Search mode}; % FIXME убедиться, что режим поиска -- правильное название.
331 \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
333 \path[->] (insert_mode.west) edge node[midway, above, sloped, yshift=32pt]{ Esc } (normal_mode.east);
334 \path[->] (command_mode.west) edge node[pos=0.38, above, sloped, yshift=32pt]{ Esc / Enter } (normal_mode.east);
335 \path[->] (search_mode.west) edge node[pos=0.40, below, sloped, yshift=36pt]{ Esc / Enter } (normal_mode.east);
337 \end{tikzpicture} % конец блока
341 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 \begin{frame}[fragile, shrink=10]{Commands of the command-line mode}
346 \item \textbf{:q} --- quit vim
347 \item \textbf{:q!} --- quit without saving
348 \item \textbf{:w} --- save (\textbf{:wq} --- save and quit)
349 \item \textbf{:123} --- go to line 123
350 \item \textbf{:set number} --- show line numbers
351 \item \textbf{:set nonumber} --- hide line numbers
353 Use \textbf{up} and \textbf{down} arrows to scroll through commands history
355 \textbf{Tab} is for autocompletion
358 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 \begin{frame}[fragile, shrink=10]{Normal mode commands}
362 \item \textbf{dd} --- delete line;
363 \item \textbf{u} --- undo;
364 \item \textbf{Ctrl + r} --- redo.
367 Copy and past commands
370 \item \textbf{v} / \textbf{V} --- text selection mode
371 \item \textbf{d} --- delete selected text into buffer
372 \item \textbf{y} --- copy (yank) selected text into buffer
373 \item \textbf{p} / \textbf{P} --- insert text from buffer in/after cursor position
377 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 \begin{frame}[fragile, shrink=10]{Search mode commands}
381 \item \textbf{/abc} --- search text for substring `abc`;
382 \item \textbf{/} --- search again.
385 Use \textbf{up} and \textbf{down} arrows to scroll through search history
387 You can also use regular expressions here.
391 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 {\setbeamertemplate{background}{
396 \node[anchor=south west, inner sep=0] at (0,0) {\includegraphics[width=\the\paperwidth, height=\the\paperheight]{theme.nonfree/bgpics/pgpro_title_bg2.png}};
397 \node[anchor=east] at(\textwidth+1cm,0.5cm) {\color{white}\tiny\insertframenumber};
400 \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
401 \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
404 Navigating through code using tags in vim
408 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 \begin{frame}[fragile, shrink=10]{Tags lists}
413 Tags are an ancient way for navigating the code, for jumping from symbol's usage to it's definition.
415 In this technique you use some script for generating list of symbols defined in your project (tags) and your editor uses them for navigating through the code.
417 For C code of PostgreSQL tags are generated with `ctags` program from `exuberant-ctags` package.
421 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 \begin{frame}[fragile, shrink=10]{Building tags list}
427 To build tags list you should install `exuberant-ctags` package:
429 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
430 $ sudo apt-get install exuberant-ctags \end{lstlisting}
432 And then run \texttt{make\_ctags} script provided by PostgreSQL developers from the root of PostgreSQL source tree
434 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
435 $ src/tools/make_ctags \end{lstlisting}
437 You will get a bunch of \texttt{tags} files in each directory of source tree.
438 You can copy it to your extension dir, so you can jump to postgres code function definitions while editing your code.
442 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 \begin{frame}[fragile, shrink=10]{Using tags in vim}
446 Let's open some file from PostgreSQL source code
448 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
449 $ vim src/backend/postmaster/postmaster.c \end{lstlisting}
451 and find some symbol that most probably defined inside PosgreSQL code.
452 I found \texttt{BACKEND\_NUM\_TYPES} on 145th line.
454 You can move cursor to that symbol, and press \textbf{Ctrl + \rbrack} to jump to the place where this symbol is defined.
456 In order to go back, press \textbf{Ctrl + t}
460 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 \begin{frame}[fragile, shrink=10]{Hiding \texttt{tags} from git}
464 \texttt{tags} files are not ignored by by git version control system.
465 You can see that by running command
467 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
468 $ git status \end{lstlisting}
470 Theoretically you cat add \texttt{tags} into \texttt{.girignore} file, but you will have to track this change manually, make sure it is not committed, and so on.
471 Less known solution is to add \texttt{tags} into local .\texttt{git/info/exclude} file, that will do same trick.
475 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
476 $ git status \end{lstlisting}
478 and you will see that \texttt{tags} files are now ignored.
482 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 \begin{frame}[fragile, shrink=10]{Open file on certain position}
486 If you, for some reason need to open file on certain position, for example you get an error message from a compiler, that specify certain line number, you can specify this line number as an extra option with "plus" prefix in front of it:
488 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
489 $ vim src/backend/access/common/reloptions.c +1234 \end{lstlisting}
491 This command will open \texttt{reloptions.c} file in vim, and move cursor to line number 1234.
496 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 \begin{frame}[fragile, shrink=10]{\texttt{grep}ing for function definition}
500 If you know function name (from compiler error message) and would like to find it's definition, most probably you will try to use \texttt{grep} utility.
501 But you will not success, as multiple \texttt{tags} files will also contain this function name.
502 You should use `git grep` command instead, as it will ignore files that are not part of git repository
504 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
505 $ git grep ^tsvectorin \end{lstlisting}
507 This command uses the convention that, in a C program, the function name is specified starting from the first character of the line.
508 This allow to find only function definition, and ignore all other occurrences.
510 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
512 my_function(char * str, bool is_cool) \end{lstlisting}
518 {\setbeamertemplate{background}{
520 \node[anchor=south west, inner sep=0] at (0,0) {\includegraphics[width=\the\paperwidth, height=\the\paperheight]{theme.nonfree/bgpics/pgpro_thanks_bg.png}};
521 \node[anchor=east] at(\textwidth+1cm,0.5cm) {\color{white}\tiny\insertframenumber};