• Non ci sono risultati.

Environnements et Outils de Développement Cours 2 — Text editing with Emacs

N/A
N/A
Protected

Academic year: 2021

Condividi "Environnements et Outils de Développement Cours 2 — Text editing with Emacs"

Copied!
14
0
0

Testo completo

(1)

Environnements et Outils de Développement Cours 2 — Text editing with Emacs

Stefano Zacchiroli

zack@pps.univ-paris-diderot.fr

Laboratoire PPS, Université Paris Diderot

2013–2014

URL http://upsilon.cc/zack/teaching/1314/ed6/

Copyright © 2012–2014 Stefano Zacchiroli

License Creative Commons Attribution-ShareAlike 4.0 International License http://creativecommons.org/licenses/by-sa/4.0/deed.en_US

(2)

It’s all about. . .

Which tool, as programmer, will you use the most ?

A text editor.

coding debugging

searching / reading

writing documentation

configuration files

(textual) program data

. . .

(3)

It’s all about text

Which tool, as programmer, will you use the most ? A text editor.

coding debugging

searching / reading

writing documentation

configuration files

(textual) program data

. . .

(4)

One editor to rule them all

complex software projects are often written using multiple (programming) languages

ñ

system language for the engine

+ application language for business logic

ñ

DSL

ñ

separation logic / presentation

ñ

documentation

you’ll work on several development projects at the “same time”

You’ll change many languages ; changing your editor at each change wouldn’t be wise.

Most programmers choose one editor and use it for every text

editing task, no matter the language.

(5)

Which editor ?

Doesn’t matter, really, . . . as long as it is flexible enough to adapt to your changing needs.

Two popular choices in the UNIX / Free Software world :

Vim modal editor ; the editor responds differently to the same keys, depending on the editor state

simple key strokes, to be concatenated like video game “combos”

traditionally small and fast

used with many instances at a time Emacs non-modal

key combinations and modifier keys (Ctrl+Alt+. . . ) traditionally highly customizable, using Emacs Lisp use with a single instance running + clients

Biased !

See http://en.wikipedia.org/wiki/Editor_war

(6)

Choosing Emacs

For this class we got to choose (time constraints. . . ).

And we’ve chosen Emacs.

Feel free to choose the one you like, really.

learn to learn how to use your editor compare

pick the one that makes you most efficient

Editing concepts, as well as coordination of other development

utilities from your editor, are portable.

(7)

Learning Emacs

We’ll follow the excellent tutorial “Being productive with Emacs”, by Phil Sung : http://web.psung.name/emacs/

Part 1 : Introduction

http://web.psung.name/emacs/2009/part1.html Part 2 : Emacs lisp

http://web.psung.name/emacs/2009/part2.html

ñ

no time today to complete this ; follow the tutorial at the above

link as an exercise !

(8)

Tutorial

(9)

Programming major modes

major modes to edit code in a specific programming language available for most (un)known programming languages

auto-loaded based on file name extensions manually toggled by M-x lang-mode

ñ

c-mode

ñ

java-mode

ñ

caml-mode

ñ

python-mode

ñ

latex-mode

ñ

etc.

(10)

Common tasks

Most programming major modes support a common set of tasks, via a common interface.

indenting : <TAB> is bound to (re-)indent the current line ; you’ll use it a lot. . .

commenting : M-x comment-region, M-x uncomment-region reformat paragraph : M-q, mostly for text modes, but very useful in comments

completion : M-/, trigger (word-based) completion, extensible quickfix cycle (edit/compile/fix)

Idea : run an external compiler and parse its output to detect errors and locate them in source code

ñ

M-x compile : compile (ask for compile command)

ñ

M-x recompile : compile (silent)

ñ

C-x ‘ : go to next error

(11)

Navigating through code

Generalize the idea behind the quickfix cycle :

occur : M-x occur — navigate through occurrences in the current buffer

grep : M-x grep — navigate through occurrences, elsewhere

(12)

Rectangles

Consider point and mark, but look at the smallest rectangular area of text denoted by them

C-x r k — kill rectangle C-x r y — yank rectangle C-x r o — open rectangle

Useful / alternative / non-standard way of re-indenting several lines

at once.

(13)

Processing text with external tools

What if Emacs can’t do a specific text manipulation that an external tool—more precisely a UNIX filter—could ?

1

select the region you want to operate on

2

M-x shell-command-on-region

bound by default to M-| (mnemonic for “pipe,” as in the shell)

read-only mode (default) : pipe the text to the filter, but do not change the text in return

read-write mode : pipe the text to the filter and replace it with filter’s output

ñ

C-u M-|

(14)

Warning : Emacs in the lab

Please note that in our (UPD) student labs Emacs is configured to use cua-mode by default.

cua-mode is an Emacs minor mode that makes C-c, C-x, C-v behave as in “other applications” to do copy/cut/paste tasks.

That’s fine. But it gets in the way of learning Emacs the right way™, especially if you’re following the official Emacs documentation — which generally assumes you are not using cua-mode, or other modes that change the default key bindings.

It is recommended that you disable cua-mode by adding the following line to your ~/.emacs configuration file :

(cua-mode -1)

Riferimenti

Documenti correlati

The variant make target will try to obtain the given target (instead of the first one in the Makefile)c. With make -n we can examin the command sequence that make would execute,

Version management (or version control, revision control, etc.) keeping track of multiple version of (software) components and ensure unrelated changes do not interfere..

La pratique du génie logiciel à travers des années nous a amenés à l’utilisation d’une multitude des outils de développement. édition du code

searching / reading writing documentation configuration files (textual) program data.?. It’s all

A compiler is a computer program that transforms source code (written in some source language) into another computer language called target language?. usually, but not always,

Once more, given the library is not installed in the default library location, we need to tell the dynamic linker where to find the library before running the program. We can do

Version management (or version control, revision control, etc.) keeping track of multiple version of (software) components and ensure unrelated changes do not interfere..

Una volta terminata la ricorsione, se almeno una delle dipendenze ha richiesto esecuzione del comando associato, allora i comandi associati all’obiettivo corrente vengono eseguiti