You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [[https://github.com/ess-intro/presentation-ess-customization/blob/main/tutorial/ess-customization.pdf][Tutorial in PDF format]]
14
14
- [[https://github.com/ess-intro/presentation-ess-customization/blob/main/tutorial/slides-ess-customization.pdf][Tutorial as beamer slides]] (superceded by the above PDF tutorial)
[[https://github.com/ess-intro/presentation-ess-customization/blob/main/tutorial/ess-init.el][A minimal init file]] for some possible customization of ESS is also provided. It should be adapted [[https://github.com/ess-intro/presentation-ess-customization/blob/4b4e388ce0b496b396d090f0121e3fb4785d640a/tutorial/ess-init.el#L127][(in particular for ~yasnippet~)]] according to your own setup and habits.
Copy file name to clipboardExpand all lines: tutorial/ess-customization.tex
+39-39Lines changed: 39 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
% Created 2021-02-25 jeu. 11:07
1
+
% Created 2021-03-31 mer. 09:27
2
2
% Intended LaTeX compiler: pdflatex
3
3
\documentclass[11pt]{article}
4
4
\usepackage[utf8]{inputenc}
@@ -51,7 +51,7 @@
51
51
pdftitle={Customizing and extending Emacs Speaks Statistics},
52
52
pdfkeywords={},
53
53
pdfsubject={},
54
-
pdfcreator={Emacs 27.1 (Org mode 9.4.4)},
54
+
pdfcreator={Emacs 27.1 (Org mode 9.4.5)},
55
55
pdflang={English}}
56
56
\begin{document}
57
57
@@ -60,44 +60,44 @@
60
60
61
61
62
62
\section{Introductory words}
63
-
\label{sec:org01f47bc}
63
+
\label{sec:org795d064}
64
64
\subsection{A short tutorial for customizing ESS}
65
-
\label{sec:org38c3ffc}
65
+
\label{sec:orgf7080c5}
66
66
This document is a part of the ESS-Intro tutorial series. A full list of tutorials is available online at \url{https://github.com/ess-intro}.
67
67
68
68
If you are are totally new to Emacs, you should probably begin with the tutorial ``\href{https://github.com/ess-intro/presentation-first-steps}{First steps with Emacs}'' by Dirk Eddelbuettel.
69
69
70
70
\subsubsection{Target audience}
71
-
\label{sec:org8ad5028}
71
+
\label{sec:org45650b4}
72
72
This tutorial is for R-users beginning to use Emacs Speaks Statistics (ESS). We only assume that you have mild familiarity with Emacs, and that you know how to customize Emacs by filling your \texttt{.emacs} or \texttt{init.el} file.
73
73
74
74
\subsubsection{Goals}
75
-
\label{sec:orgae3c8f9}
75
+
\label{sec:orgec96ced}
76
76
\begin{itemize}
77
77
\item Helping newcomers and beginners to have a more friendly and efficient setup
78
78
\item Helping users migrating from other IDEs to keep behaviours and habits they are used to
79
79
\item Showcasing some other Emacs packages that play well with ESS and may improve your coding experience
80
80
\end{itemize}
81
81
82
82
\subsubsection{Video tutorial}
83
-
\label{sec:org112b66c}
83
+
\label{sec:org7d8cb0c}
84
84
This document is a written companion for the video tutorial available at:
85
85
86
86
\begin{center}
87
-
\url{http://toto}
87
+
\url{https://www.youtube.com/watch?v=Lf8qrLuvYp8}
88
88
\end{center}
89
89
90
90
91
91
\subsubsection{An opinionated tutorial?}
92
-
\label{sec:org67ea909}
92
+
\label{sec:orgaedb8ab}
93
93
Some parts of this tutorial (e.g., replacing \texttt{Flymake} by \texttt{Flycheck} for syntax checking, or using \texttt{company} instead of other solutions for auto-completion) might be seen as quite opinionated. However, when several options or approaches were available for a given task, the most widespread and efficient (I hope!) was presented.
94
94
95
95
If you prefer other approaches, or simply want to give a try to some other ones, the ESS manual remains the canonical and exhaustive documentation: \url{http://ess.r-project.org/Manual/ess.html}
96
96
97
97
Feedbacks, fixes and contributions are welcome, and can be addressed \href{https://github.com/ess-intro/presentation-ess-customization/issues}{through the Github repository}.
98
98
99
99
\subsection{A word about \texttt{use-package}}
100
-
\label{sec:org48c369a}
100
+
\label{sec:org1e31867}
101
101
In this document, several pieces of Emacs Lisp code will be proposed so that you can use them in your init file. Because it will provide a more reproducible setup in the following steps, it is assumed that you use \href{https://jwiegley.github.io/use-package/}{\texttt{use-package}} for your init file. The Emacs Lisp code can be adapted in a straightforward manner if you do not use it.
102
102
103
103
As a reminder, this is the minimal code to add in your init file so as to use \texttt{use-package}, once it has been installed:
@@ -113,9 +113,9 @@ \subsection{A word about \texttt{use-package}}
113
113
\end{minted}
114
114
115
115
\section{ESS customization}
116
-
\label{sec:org3838954}
116
+
\label{sec:org5c6aa43}
117
117
\subsection{Visibility of code evaluation}
118
-
\label{sec:orgbe9037b}
118
+
\label{sec:org0cde447}
119
119
From an R source file (i.e., an ESS[R] buffer), you can send code to the underlying R process with shortcuts like \texttt{C-c C-b} (\texttt{ess-eval-buffer}), \texttt{C-RET} (\texttt{ess-eval-region-or-line-and-step}), etc.
120
120
121
121
In the inferior R process buffer, ESS can display either both the commands sent and their results, or only the results. The choice between the two can be made through the variable \texttt{ess-eval-visibly}.
@@ -129,13 +129,13 @@ \subsection{Visibility of code evaluation}
129
129
\end{minted}
130
130
131
131
\subsection{Syntactic highlighting in ESS R source buffers}
132
-
\label{sec:org3581de8}
132
+
\label{sec:org8fa3961}
133
133
By default, ESS highlights literals, assignments, source functions and reserved words. An example of default syntactic highlighting is as follows:
\subsubsection{Navigating through matching parentheses}
188
-
\label{sec:org28c9199}
188
+
\label{sec:org6b91289}
189
189
Here are some convenient tricks for navigating through parenthetical groups (this can be useful when dealing with large paren groups, e.g. when developing a shiny UI):
190
190
191
191
\begin{table}[htbp]
@@ -207,9 +207,9 @@ \subsubsection{Navigating through matching parentheses}
207
207
For instance, when the point is over a closing parenthesis, \texttt{C-M-p} brings you to the matching opening parenthesis. Then, \texttt{C-M-k} kills to whole paren group.
208
208
209
209
\subsection{Syntax checker}
210
-
\label{sec:orgddd3478}
210
+
\label{sec:org1595182}
211
211
\subsubsection{Syntax checking: \texttt{Flycheck} vs. \texttt{Flymake}}
212
-
\label{sec:org05b6c78}
212
+
\label{sec:org20eddbe}
213
213
ESS has facilities for on-the-fly syntax checking. Instead of using \texttt{Flymake}, which is the default choice, using \href{https://www.flycheck.org/en/latest/}{\texttt{Flycheck}} appears to be a better and more stable option. The \texttt{Flycheck} documentation allows for a comparison between those two packages:
@@ -226,7 +226,7 @@ \subsubsection{Syntax checking: \texttt{Flycheck} vs. \texttt{Flymake}}
226
226
\end{minted}
227
227
228
228
\subsubsection{On-the-fly syntax checking with \texttt{Flycheck}}
229
-
\label{sec:org41ed33e}
229
+
\label{sec:orge85a15b}
230
230
Using \texttt{Flycheck} with ESS first requires you to install the R package \texttt{lintr}:
231
231
232
232
\begin{minted}[]{r}
@@ -249,18 +249,18 @@ \subsubsection{On-the-fly syntax checking with \texttt{Flycheck}}
249
249
\item unmatched parentheses
250
250
\end{itemize}
251
251
252
-
The following screenshot (Fig. \ref{fig:org4b9f253}) gives some examples of such checks. To display all syntax error in a dedicated buffer, use \texttt{M-x flycheck-list-errors} (bound to \texttt{C-c ! l} by default).
252
+
The following screenshot (Fig. \ref{fig:org50cdeac}) gives some examples of such checks. To display all syntax error in a dedicated buffer, use \texttt{M-x flycheck-list-errors} (bound to \texttt{C-c ! l} by default).
All the R objects of the current R sessions are thus listed in the Rdired buffer, and it is possible to interact with them easily. For instance, type \texttt{p} for plotting an object, \texttt{d} for deleting it, etc.
271
271
272
-
The screenshot in Figure \ref{fig:orgff7aa8b} shows the contents of an Rdired buffer for the R session associated to a small piece of code.
272
+
The screenshot in Figure \ref{fig:org065fea9} shows the contents of an Rdired buffer for the R session associated to a small piece of code.
\caption{\label{fig:orgff7aa8b}An example of Rdired buffer (bottom window).}
277
+
\caption{\label{fig:org065fea9}An example of Rdired buffer (bottom window).}
278
278
\end{figure}
279
279
280
280
Rdired buffers can be triggered manually with \texttt{M-x ess-rdired}, which might not be really convenient in practice. With the following piece of Emacs Lisp code, you will be able to use \texttt{F9} for both opening and closing the Rdired buffer, so that you can consult and display it only when necessary:
@@ -291,7 +291,7 @@ \subsubsection{Rdired buffer}
291
291
\end{minted}
292
292
293
293
\subsubsection{Window management}
294
-
\label{sec:org224d12c}
294
+
\label{sec:orgb6fd085}
295
295
Users coming from other R IDEs may be used to a given window (or \emph{pane}) configuration, e.g.:
This is only an arbitrary example, but quite a reasonable one. You will find in Figure \ref{fig:orgda5106e} a screenshot of such a window configuration. The corresponding Emacs Lisp code to add in your init file follows.
303
+
This is only an arbitrary example, but quite a reasonable one. You will find in Figure \ref{fig:orgf85260e} a screenshot of such a window configuration. The corresponding Emacs Lisp code to add in your init file follows.
As mentioned \href{https://ess.r-project.org/Manual/ess.html\#Completion}{in the ESS manual}, there are several completion frameworks for writing R code with ESS. The Emacs package \href{https://company-mode.github.io/}{\texttt{company}} is an elegant solution, which also supports many other programming languages. Here is a minimal piece of Elisp code to add in your init file to install and load \texttt{company}:
341
341
342
342
\begin{minted}[]{common-lisp}
@@ -352,10 +352,10 @@ \subsection{Completion with company}
\caption{\label{fig:orgeb11286}An example of code completion with \texttt{company}: various candidates are proposed for the arguments of the function \texttt{car::Anova()}.}
355
+
\caption{\label{fig:org7bf7e39}An example of code completion with \texttt{company}: various candidates are proposed for the arguments of the function \texttt{car::Anova()}.}
356
356
\end{figure}
357
357
358
-
\texttt{company} offers completion candidates in various contexts: function name, argument name within a function call (as in Fig. \ref{fig:orgeb11286}), object name. It may seem preferable to adopt a non-intrusive workflow. For functions or objects names, completion starts automatically after you type a few letters. For arguments names within a function call, it is suggested that you trigger manually the completion only when you need it. This can be done with \texttt{M-x company-complete}, or more conveniently, by binding this function to a convenient shortcut. For example, to bind it to \texttt{F12}, add the following to your init file:
358
+
\texttt{company} offers completion candidates in various contexts: function name, argument name within a function call (as in Fig. \ref{fig:org7bf7e39}), object name. It may seem preferable to adopt a non-intrusive workflow. For functions or objects names, completion starts automatically after you type a few letters. For arguments names within a function call, it is suggested that you trigger manually the completion only when you need it. This can be done with \texttt{M-x company-complete}, or more conveniently, by binding this function to a convenient shortcut. For example, to bind it to \texttt{F12}, add the following to your init file:
359
359
360
360
\begin{minted}[]{common-lisp}
361
361
;; Use F12 to trigger manually completion on R function args:
@@ -382,7 +382,7 @@ \subsection{Completion with company}
382
382
\end{minted}
383
383
384
384
\subsection{Documentation popups with company-quickhelp}
385
-
\label{sec:org5777fd6}
385
+
\label{sec:org1fac874}
386
386
\href{https://github.com/company-mode/company-quickhelp}{\texttt{company-quickhelp}} allows for documentation popups, e.g. to further describe function arguments.
387
387
388
388
\begin{figure}[htbp]
@@ -406,9 +406,9 @@ \subsection{Documentation popups with company-quickhelp}
406
406
By default, the documentation popup is shown automatically. You can adjust the time before the popup shows up by customizing the variable \texttt{company-quickhelp-delay}.
407
407
408
408
\subsection{Code snippets with yasnippet}
409
-
\label{sec:org9fa23ba}
409
+
\label{sec:org261b148}
410
410
\subsubsection{Key features}
411
-
\label{sec:orgf626078}
411
+
\label{sec:org94d8013}
412
412
\href{https://github.com/joaotavora/yasnippet}{\texttt{yasnippet}} is an Emacs package allowing for the expansion of whole pieces of code you often use (\emph{snippets}) from one given abbreviation.
413
413
414
414
\begin{itemize}
@@ -418,7 +418,7 @@ \subsubsection{Key features}
418
418
\end{itemize}
419
419
420
420
\subsubsection{Setting up \texttt{yasnippet}}
421
-
\label{sec:orgc310081}
421
+
\label{sec:orgfe8386b}
422
422
To set up \texttt{yasnippet}, proceed through the following steps:
423
423
424
424
\begin{enumerate}
@@ -457,7 +457,7 @@ \subsubsection{Setting up \texttt{yasnippet}}
457
457
\end{enumerate}
458
458
459
459
\subsubsection{Using \texttt{yasnippet} in an ESS[R] buffer}
460
-
\label{sec:orgbe0d91a}
460
+
\label{sec:orgcb772f3}
461
461
While you are editing an R source file with ESS, each snippet can be triggered by typing its \texttt{key} and then pressing \texttt{TAB}. You can then navigate through the placeholders of the expanded template by pressing \texttt{TAB} again.
462
462
463
463
For instance, with our previously defined snippet, typing \texttt{fun} followed by \texttt{TAB} will expand the full \texttt{function} template; you will then be able to specify easily a value for each of the three placeholders (the function's \texttt{name}, its \texttt{args} and \texttt{body}).
0 commit comments