\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=0.75in]{geometry}

% set up hyperlink coloring
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan
}

\setlength{\parindent}{0pt} % no indentation

% checkbox list: https://tex.stackexchange.com/questions/247681/how-to-create-checkbox-todo-list
\usepackage{enumitem,amssymb}
\newlist{boxlist}{itemize}{2}
\setlist[boxlist]{label=$\square$}

% code support: listings and fancy verbatim
\usepackage{listings}
\lstset{basicstyle=\ttfamily\footnotesize}
\usepackage{fancyvrb}

\renewcommand{\familydefault}{\sfdefault} % default to sans serif

\usepackage{xcolor}
\newcommand{\code}[1]{\colorbox{lightgray}{\texttt{#1}}}
\newcommand{\sh}[1]{\code{\$ #1}}

\usepackage{graphicx}

%%%%%%%%%%%%%%%%

\begin{document}

\title{Basic 6\\Text Editors}
\author{EECS 201 Fall 2020}
\date{}
\maketitle

\section*{Submission Instructions}
Answer the bolded text that begins with a ``\textbf{Q}''.
This assignment is an ``online assignment'' on \href{https://gradescope.com}{Gradescope},
where you fill out your answers directly.


\section*{\textit{Optional} Readings}
Previous iterations of this class included some optional readings with this week.
You may find the ideas and topics they bring up interesting.

\subsection*{Interrupting Developers and Makers vs Managers}
\medskip
\noindent
\url{http://thetomorrowlab.com/2015/01/why-developers-hate-being-interrupted/}\\
\textit{Why developers hate being interrupted}, by Derek Johnson at The Tomorrow Lab.

\noindent
\url{http://www.paulgraham.com/makersschedule.html}\\
\textit{Maker's Schedule, Manager's Schedule}, by Paul Graham, co-founder of Y~Combinator.

\subsection*{Software Engineering in the Real World}
\url{http://blogs.msdn.com/b/peterhal/archive/2006/01/04/509302.aspx}\\
\textit{What Do Programmers Really Do Anyway?}, by Peter Hallam, then-Microsoft~Developer
\begin{quote}
  \textit{
    Why is 5 times more time spent modifying code than writing new code? The
    answer is that new code becomes old code almost instantly.  Write some new
    code. Go for coffee. All of sudden you've got old code.
  }
\end{quote}

\medskip
\noindent
\url{http://www.joelonsoftware.com/articles/fog0000000069.html}\\
\textit{Things You Should Never Do, Part I}, by Joel Spolsky
\begin{quote}
  \textit{It's harder to read code than to write it.}
\end{quote}

\medskip
\noindent
\textit{When was the last time you saw a hunt-and-peck pianist?} -Jeff Atwood,
co-founder of Stack Overflow and Discourse.\\
Some extras on the
\href{http://blog.codinghorror.com/we-are-typists-first-programmers-second/}
{value of being a good typist}
and
\href{http://blog.codinghorror.com/going-commando-put-down-the-mouse/}
{ditching the mouse for the keyboard}.


\newpage
\section{Trying out fancy features}
For this question, we'll be looking at the two big terminal editors: Vim and Emacs
and exploring their capabilities.
You may choose either of them to work with for this question.
\textbf{You many only use Vim or Emacs in this part of the assignments.}

The intent of this question is to expose you to the more advanced features that other editors like
Microsoft Notepad or GNU Nano may not have as well as building competency in terminal text editors.
I encourage you play around with the editors and look into the neat features that they have.
\\\\
\textbf{If you're using Emacs, run it in non-GUI mode i.e. \code{emacs -nw} for this question}.

\bigskip
\hrule
\vspace{1em}
To start, grab a copy of this file that's full of code:
\begin{lstlisting}
# Example from http://web.mst.edu/~price/cs53/code_example.html
wget http://web.mst.edu/~price/cs53/KatsBadcode.cpp
\end{lstlisting}
\smallskip
\hrule
\bigskip

\begin{enumerate}
  \item Sometimes you will come across some ugly code. Your editor can help
        make it better. Open \code{KatsBadcode.cpp}. Among other issues, the
        really bad tabbing makes this hard to read.\\
        \textbf{Q: Describe how to automatically fix the indentation for the whole file.}
        %\vspace{10em}

        Now imagine if you are editing code and you determine you can
        remove an if block, for example removing the \code{if} on line~28 of
        \code{KatsBadcode} and running its body unconditionally. You need to
        fix the indentation level of all 20~lines of the body.\\
        \textbf{Q: Describe how to change the indentation level of a block of code.}
        %\vspace{10em}
  \item Editing one file is nice, but often it's really useful to compare
        files side-by-side (source and headers, spec and implementation).\\
        \textbf{Q: Describe the command sequence to create a window split
                (within your text editor) side-by-side with your current window,
                switch to it, and then open a file in that window.}\\
        %\vspace{10em}

        Try playing around with these two views, copy/paste code between them,
        bind them so they scroll together, resize them, add more splits.\\

  \item Editors also have pretty nice integration with compilation tools. With
        \code{KatsBadcode.cpp} open, try typing \code{:make KatsBadcode} in
        Vim or \code{M-x compile<enter>make KatsBadcode} in Emacs. \footnote{
          Descriptions of \code{Emacs} commands are usually written as
          \code{C-c} or \code{M-x}, which mean ``Ctrl+C'' or ``Meta+x''
          respectively. Meta is often mapped to the escape and/or alt key,
          \code{M-x} means press Escape and then x or hold alt and press x.
        }

        {
          \footnotesize{}
          First cool thing that happened: Yes, you can run \code{make}
          \textit{without} any Makefile anywhere. We'll cover how that happened
          during build-system week.
        }

        Building \code{KatsBadcode.cpp} will fail with several errors.\\
        \textbf{Q: Describe how to navigate between compilation errors automatically.
                Hint: Vim has the "quickfix" feature and Emacs has "Compilation Mode"}
        %\vspace{6em}
  \item While C-style languages support \code{/* block comments */}, others
        such as Python have no block comments and require you to put a \code{\#}
        at the beginning of every line.\\
        \textbf{Q: Describe how to efficiently comment out a large block of Python code.
                No, docstrings (\code{"""}) are NOT comments.}
        %\vspace{8em}
  \newpage
  \item Many times you have a repetitive task that you need to do say 10 or 20
        times. It's too short to justify writing a script or anything fancy, but
        it's annoying to type the same thing over and over again. As example,
        reformatting the staff list to a nice JSON object:
        \begin{verbatim}
                                staff = [
Boole,George                        {"first": "George", "last": "Boole"},
Lovelace,Ada                        {"first": "Ada", "last": "Lovelace"},
von Neumann,John                    {"first": "John", "last": "von Neumann"},
Hopper,Grace                        {"first": "Grace", "last": "Hopper"},
Turing,Alan                         {"first": "Alan", "last": "Turing"},
Shannon,Claude                      {"first": "Claude", "last": "Shannon"},
Dijkstra,Edsger                     {"first": "Edsger", "last": "Dijkstra"},
Hamilton,Margaret                   {"first": "Margaret", "last": "Hamilton"},
Knuth,Donald                        {"first": "Donald", "last": "Knuth"},
                                ]
        \end{verbatim}
        Editors support the record and replay of \textit{macros}. With macros, you
        can start recording, puzzle out how to turn one line into the other, and
        then simply replay it for the rest. As a general rule, do not bother
        trying to be optimal or efficient, just find anything that works.
        Try starting with the column on the left and devising a macro to turn it
        into the column on the right.\\
        \textbf{Q: Describe how to record and replay a macro.}
        \textit{\small (you do not need to include the contents of your macro; make your best attempt at trying to make a macro that works, but don't worry if you are unable to get it to work perfectly)}
        %\vspace{6em}

    \item Editors understand balanced ()'s and \{\}'s.\\
          \textbf{Q: Describe how to jump from one token to its match, such as from
            the opening \{ on line~29 of \code{KatsBadcode} to its partner \}
            on line~58.
          }
          %\vspace{8em}
    \item Sometimes it's useful to run quick little commands. For example,
          your code needs to read from a file, but you can't remember if it's
          called \code{sample\_data.txt} or \code{sampleData.txt}.\\
          \textbf{Q: Describe how to run `ls' directly from within your editor.}
          %\vspace{8em}
\end{enumerate}


\subsection*{Personalising your Editor (Ungraded but recommended)}
Similar to how \code{$\sim$/.bashrc} configures \code{bash}, a
\code{$\sim$/.vimrc} or \code{$\sim$/.emacs} file\footnote{
These files do not exist by default, you have to create them.
} can configure how your editor behaves.
\textbf{Add something useful not listed above to your editor's configuration file.\\}

%\vspace{3em}

\textbf{Q: Roughly how long did you spend on this assignment?}



\end{document}
