]> Untitled Git - articles.git/blob
9b2957398b61841f6ffd0829ddd230418b76e992
[articles.git] /
1 \documentclass[aspectratio=169]{beamer}
2
3 \usepackage{xltxtra}
4 \defaultfontfeatures{Ligatures=TeX,Mapping=tex-text}
5 \usepackage[russian]{babel}
6 \usepackage[utf8]{inputenc}
7 \usepackage[normalem]{ulem} % для \sout
8
9
10 %\usepackage{tikz}  % FIXME не уверен что все это тут надо
11 %\usetikzlibrary{chains}  
12
13  % Цвета для гиперссылок
14  \definecolor{linkcolor}{HTML}{799B03} % цвет ссылок
15  \definecolor{urlcolor}{HTML}{6633FF} % цвет гиперссылок
16  
17  \hypersetup{pdfstartview=FitH,  linkcolor=linkcolor,urlcolor=urlcolor, colorlinks=true}
18
19 \title{Git and vim for PostgreSQL developers}
20 \author{Nikolay Shaplov}
21
22 \makeatletter
23 % Добавляем подпапку к пути поиска .sty/.tex
24 \def\input@path{{./theme.nonfree}}
25 \makeatother
26
27
28 \usetheme{PgPro}
29 \input{elements/code.tex}
30
31 \begin{document}
32
33 \begin{frame}
34 \titlepage
35 \end{frame}
36
37 % FIXME introduction page
38
39 % FIXME QR-code link to slides
40
41
42 \begin{frame}{General topic}
43
44   If you want to write well, you should read a lot.
45   And you'd better read best samples you can find.
46
47   PostgreSQL is one of the finest C\text{-}driven project one can get.
48
49   In this talk we will learn how to use git and vim to read and explore PostgreSQL code right in the console.
50
51 \end{frame}
52
53 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55 {\setbeamertemplate{background}{
56     \begin{tikzpicture}
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};
59     \end{tikzpicture}
60     }
61     \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
62     \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
63     \begin{frame}
64         \vskip1cm
65         Git
66     \end{frame}
67 }
68
69 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70
71 \begin{frame}[fragile, shrink=10]{Git, fetching the source code}
72
73   In order to get latest snapshot of PostgreSQL code you should run command:
74
75   \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
76 $ git clone https://git.postgresql.org/git/postgresql.git  \end{lstlisting}
77
78 If that command does not work for you, may be you just need to install `git` package
79
80   \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
81 $ sudo apt-get install git\end{lstlisting}
82
83 \end{frame}
84
85 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87 {\setbeamertemplate{background}{
88     \begin{tikzpicture}
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};
91     \end{tikzpicture}
92     }
93     \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
94     \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
95     \begin{frame}
96         \vskip1cm
97         Vim
98     \end{frame}
99 }
100
101 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103
104 \begin{frame}[fragile, shrink=10]{Why vim?}
105     \begin{itemize}
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
112     \end{itemize}
113 \end{frame}
114
115 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117
118 {\setbeamertemplate{background}{
119     \begin{tikzpicture}
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};
122     \end{tikzpicture}
123     }
124     \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
125     \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
126     \begin{frame}
127         \vskip1cm
128         Vim myths
129     \end{frame}
130 }
131
132 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134 \begin{frame}[fragile, shrink=10]{Vim myths}
135     \begin{itemize}
136       \item There are two main modes in vim:
137         \begin{itemize}
138            \item Beep
139            \item Mess everything up
140         \end{itemize}
141     \end{itemize}
142 %    \emph{~~~ No, this is one mode}
143 %    \begin{itemize}
144 %      \item \sout{You can't quit vim}
145 %    \end{itemize}
146 %    \emph{~~~ No. Vim is \underline{not} Hotel California.}
147
148 %    \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
149 %    \begin{itemize}
150 %      \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
151 %    \end{itemize}
152
153 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
154 \end{frame}
155
156
157 \begin{frame}[fragile, shrink=10]{Vim myths}
158     \begin{itemize}
159       \item \sout{There are two main modes in vim:}
160         \begin{itemize}
161            \item \sout{Beep}
162            \item \sout{Mess everything up}
163         \end{itemize}
164     \end{itemize}
165     \emph{~~~ No, this is one mode}
166 %     \begin{itemize}
167 %      \item \sout{You can't quit vim}
168 %    \end{itemize}
169 %    \emph{~~~ No. Vim is \underline{not} Hotel California.}
170
171 %    \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
172 %    \begin{itemize}
173 %      \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
174 %    \end{itemize}
175
176 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
177 \end{frame}
178
179
180 \begin{frame}[fragile, shrink=10]{Vim myths}
181     \begin{itemize}
182       \item \sout{There are two main modes in vim:}
183         \begin{itemize}
184            \item \sout{Beep}
185            \item \sout{Mess everything up}
186         \end{itemize}
187     \end{itemize}
188     \emph{~~~ No, this is one mode}
189     \begin{itemize}
190       \item You can't quit vim
191     \end{itemize}
192 %    \emph{~~~ No. Vim is \underline{not} Hotel California.}
193
194 %    \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
195 %    \begin{itemize}
196 %      \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
197 %    \end{itemize}
198 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
199 \end{frame}
200
201
202
203 \begin{frame}[fragile, shrink=10]{Vim myths}
204     \begin{itemize}
205       \item \sout{There are two main modes in vim:}
206         \begin{itemize}
207            \item \sout{Beep}
208            \item \sout{Mess everything up}
209         \end{itemize}
210     \end{itemize}
211     \emph{~~~ No, this is one mode}
212     \begin{itemize}
213       \item \sout{You can't quit vim}
214     \end{itemize}
215     \emph{~~~ No. Vim is \underline{not} Hotel California.}
216
217 %    \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
218 %    \begin{itemize}
219 %      \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
220 %    \end{itemize}
221 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
222 \end{frame}
223
224
225 \begin{frame}[fragile, shrink=10]{Vim myths}
226     \begin{itemize}
227       \item \sout{There are two main modes in vim:}
228         \begin{itemize}
229            \item \sout{Beep}
230            \item \sout{Mess everything up}
231         \end{itemize}
232     \end{itemize}
233     \emph{~~~ No, this is one mode}
234     \begin{itemize}
235       \item \sout{You can't quit vim}
236     \end{itemize}
237     \emph{~~~ No. Vim is \underline{not} Hotel California.}
238
239     \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
240 %    \begin{itemize}
241 %      \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
242 %    \end{itemize}
243 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
244 \end{frame}
245
246 \begin{frame}[fragile, shrink=10]{Vim myths}
247     \begin{itemize}
248       \item \sout{There are two main modes in vim:}
249         \begin{itemize}
250            \item \sout{Beep}
251            \item \sout{Mess everything up}
252         \end{itemize}
253     \end{itemize}
254     \emph{~~~ No, this is one mode}
255     \begin{itemize}
256       \item \sout{You can't quit vim}
257     \end{itemize}
258     \emph{~~~ No. Vim is \underline{not} Hotel California.}
259
260     \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
261     \begin{itemize}
262       \item One need MIDI Foot Controller Pedal to properly work with vim
263     \end{itemize}
264 %    \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
265 \end{frame}
266
267 \begin{frame}[fragile, shrink=10]{Vim myths}
268     \begin{itemize}
269       \item \sout{There are two main modes in vim:}
270         \begin{itemize}
271            \item \sout{Beep}
272            \item \sout{Mess everything up}
273         \end{itemize}
274     \end{itemize}
275     \emph{~~~ No, this is one mode}
276     \begin{itemize}
277       \item \sout{You can't quit vim}
278     \end{itemize}
279     \emph{~~~ No. Vim is \underline{not} Hotel California.}
280
281     \emph{~~~ I may assure you, you will be expert in quitting vim when these talks are finished.}
282     \begin{itemize}
283       \item \sout{One need MIDI Foot Controller Pedal to properly work with vim}
284     \end{itemize}
285     \emph{~~~ No. MIDI Foot Pedal is for Emacs users only}
286 \end{frame}
287
288 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289
290 \input{elements/diag.tex}
291
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 убедиться, что режим поиска -- правильное название.
298
299             \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
300         \end{tikzpicture} % конец блока
301     }
302 \end{frame}
303
304
305 \usetikzlibrary{arrows.meta}
306
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 убедиться, что режим поиска -- правильное название.
313
314             \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
315
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);
319
320         \end{tikzpicture} % конец блока
321     }
322 \end{frame}
323
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 убедиться, что режим поиска -- правильное название.
330
331             \node (normal_mode)[Rectangle, left=of command_mode]{Normal mode};
332
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);
336
337         \end{tikzpicture} % конец блока
338     }
339 \end{frame}
340
341 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342
343
344 \begin{frame}[fragile, shrink=10]{Commands of the command-line mode}
345     \begin{itemize}
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
352     \end{itemize}
353     Use \textbf{up} and \textbf{down} arrows to scroll through commands history
354
355     \textbf{Tab} is for autocompletion 
356 \end{frame}
357
358 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359
360 \begin{frame}[fragile, shrink=10]{Normal mode commands}
361     \begin{itemize}
362       \item \textbf{dd} --- delete line;
363       \item \textbf{u} --- undo;
364       \item \textbf{Ctrl + r} --- redo.
365     \end{itemize}
366
367 Copy and past commands
368
369     \begin{itemize}
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
374     \end{itemize}
375 \end{frame}
376
377 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378
379 \begin{frame}[fragile, shrink=10]{Search mode commands}
380     \begin{itemize}
381       \item \textbf{/abc} --- search text for substring `abc`;
382       \item \textbf{/} --- search again.
383     \end{itemize}
384
385 Use \textbf{up} and \textbf{down} arrows to scroll through search history
386
387 You can also use regular expressions here.
388
389 \end{frame}
390
391 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392
393
394 {\setbeamertemplate{background}{
395     \begin{tikzpicture}
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};
398     \end{tikzpicture}
399     }
400     \setbeamercolor{normal text}{fg=white}\usebeamercolor*{normal text}
401     \setbeamerfont{normal text}{size*={32pt}{1},family=\sffamily}\usebeamerfont*{normal text}
402     \begin{frame}
403         \vskip1cm
404         Navigating through code using tags in vim
405     \end{frame}
406 }
407
408 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409
410
411 \begin{frame}[fragile, shrink=10]{Tags lists}
412
413 Tags are an ancient way for navigating the code, for jumping from symbol's usage to it's definition.
414
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.
416
417 For C code of PostgreSQL tags are generated with `ctags` program from `exuberant-ctags` package.
418
419 \end{frame}
420
421 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422
423
424 \begin{frame}[fragile, shrink=10]{Building tags list}
425
426
427 To build tags list you should install `exuberant-ctags` package:
428
429   \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
430 $ sudo apt-get install exuberant-ctags \end{lstlisting}
431
432 And then run \texttt{make\_ctags} script provided by PostgreSQL developers from the root of PostgreSQL source tree
433
434   \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
435 $ src/tools/make_ctags \end{lstlisting}
436
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.
439
440 \end{frame}
441
442 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443
444 \begin{frame}[fragile, shrink=10]{Using tags in vim}
445
446 Let's open some file from PostgreSQL source code
447
448   \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
449 $ vim src/backend/postmaster/postmaster.c \end{lstlisting}
450
451 and find some symbol that most probably defined inside PosgreSQL code.
452 I found \texttt{BACKEND\_NUM\_TYPES} on 145th line.
453
454 You can move cursor to that symbol, and press \textbf{Ctrl + \rbrack} to jump to the place where this symbol is defined.
455
456 In order to go back, press \textbf{Ctrl + t}
457 \end{frame}
458
459
460 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461
462 \begin{frame}[fragile, shrink=10]{Hiding \texttt{tags} from git}
463
464 \texttt{tags} files are not ignored by by git version control system.
465 You can see that by running command
466
467 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
468 $ git status \end{lstlisting}
469
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.
472
473 Run again
474
475 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
476 $ git status \end{lstlisting}
477
478 and you will see that \texttt{tags} files are now ignored.
479
480 \end{frame}
481
482 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483
484 \begin{frame}[fragile, shrink=10]{Open file on certain position}
485
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:
487
488 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
489 $ vim src/backend/access/common/reloptions.c +1234  \end{lstlisting}
490
491 This command will open \texttt{reloptions.c} file in vim, and move cursor to line number 1234.
492
493 \end{frame}
494
495
496 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497
498 \begin{frame}[fragile, shrink=10]{\texttt{grep}ing for function definition}
499
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
503
504 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
505 $ git grep ^tsvectorin \end{lstlisting}
506
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.
509
510 \begin{lstlisting}[linewidth=0.9\textwidth, literate={\$}{{\textdollar}}1]
511 int 
512 my_function(char * str, bool is_cool) \end{lstlisting}
513
514 \end{frame}
515
516
517
518 {\setbeamertemplate{background}{
519     \begin{tikzpicture}
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};
522     \end{tikzpicture}
523     }
524     \begin{frame}
525     \end{frame}
526 }
527 \end{document}