RROx bookclub - Text editors

Thibault Lestang
03.06.2020

  1. Text editors
    1. Primary motivation: working with code
    2. Much of your files are text files
    3. Read and edit text efficiently
    4. Using the keyboard
    5. One swiss army knife for all your editing
  2. Working with plain text
    1. Is Microsoft Word a text editor?
    2. Plain text
    3. Using plain text files/data is best practice
    4. Composing documents in plain text
  3. Common text editors
    1. Text based text editors
    2. Graphical text editors
    3. Wait but yout didnt mention RStudio?
    4. There is no “best” editor.
    5. Personnal opinion: Emacs or Vim
  4. Demo
    1. Navigation
    2. Getting help
    3. Windows, frames and buffers

Text editors

Wikipedia

A text editor is a type of computer program that edits plain text.

Primary motivation: working with code

Much of your files are text files

Read and edit text efficiently

Using the keyboard

One swiss army knife for all your editing

Automation also happens in your brain: muscle memory.

Working with plain text

Is Microsoft Word a text editor?

It is a word-processor.

Word processors deal with rich-text formats, than contain much more information
than the symbols themselves:

(Can be) useful when writing documents but not when writing code.

Plain text

Text editors deal with plain text files.

A text file is a sequence of bytes describing, a sequence of letters and symbols,
plus some invisible symbols (end of line).

Plain text is just text. Nothing more.

Using plain text files/data is best practice

Text files can be used anywhere

Using plain text ensures both longevity and portability of your data/files.
Not format, no ties to any particular software, or/and particular version.

Text files can be versioned using version control (Git, Mercurial…)

Composing documents in plain text

Tools like pandoc let you go from one format to another, and produce (compile)
your documents… including word processor formats!

Common text editors

Text based text editors

You can open them in your terminal.
Examples:

Not relying on a graphical envirionment adds an extra layer of flexibility.
Example: editing files on a server without a graphical interface.

It allows for quick-edits, you don’t have to leave your terminal.

Less is more.

Graphical text editors

Popular examples:

Often require less configuration, more fancy functionalities by default.
Some think they look nicer.
Contain buttons, menus.

Wait but yout didnt mention RStudio?

RStudio is an Integrated Development Environment (IDE) for R.
It contains a text editor, but many other things such as

Popular IDES:

Pros and cons:

There is no “best” editor.

But some are better than others.

People have strong opinions about text editors and IDEs.
It seemd to be very subjective.

Common points of discord are:

Personnal opinion: Emacs or Vim

  1. You’ll find them anywhere.
  2. Lightweight
  3. Text based: do not depend on any graphical interface.
  4. The most powerful editors
  5. They are OLD (but still WIDELY used)
  6. Highly customizable
  7. Naturally keyboard oriented
  8. Longevity

Cons

  1. Steep learning curve
  2. OLD (weird terminology)
  3. Surprising shotcuts in nowadays standards
  4. Really highly customizable

img

Demo

    #' from tidyR/R/drop-na.R
    #' @export
    drop_na <- function(data, ...) {
      ellipsis::check_dots_unnamed()
      UseMethod("drop_na")
    }
    #' @export
    drop_na.data.frame <- function(data, ...) {
      vars <- tidyselect::eval_select(expr(c(...)), data)

      if (is_empty(vars)) {
        f <- complete_cases(data)
      }  else {
        f <- complete_cases(data[vars])
      }
      out <- vec_slice(data, f)

      reconstruct_tibble(data, out)
    }

https://oracleyue.github.io/2019/09/06/emacs-editing/

Getting help

Windows, frames and buffers

In Emacs, text is always displayed inside what is called a buffer.
Typically, a buffer will display the content of a file, but it could also display other things, such as
the content of a directory (using Dired).

Buffers are contained in “windows”

Notice than deleting a window does not kill the buffer

Windows can be enlarged and shrinked