27
18.06.22 - Page 1 Département Office Emacs, a performant IDE for Perl Tutorial for YAPC.:EU:::2009, Lisbon [email protected] Département Office

Emacs, a performant IDE for Perl

  • Upload
    ldami

  • View
    5.363

  • Download
    5

Embed Size (px)

DESCRIPTION

Emacs is much more than a source code editor : it provides a rich integrated development environment for Perl developers. This guided tour will show how to take advantage of Emacs basic features (modes, abbreviations, autocompletion, macros, directory editor, undo, etc.), how to run and debug within Emacs, and how to integrate with external utilities such as ctags, ack, perltidy, perlcritic, subversion.

Citation preview

Page 1: Emacs, a performant IDE for Perl

12.04.23 - Page 1

DépartementOffice

Emacs, a performant IDE for Perl

Tutorial for YAPC.:EU:::2009, Lisbon

[email protected]

DépartementOffice

Page 2: Emacs, a performant IDE for Perl

12.04.23 - Page 2

Overview

• Intended audience– Emacs newcomers– [ seasoned Emacs users … may find some additional tips ]– curious …

• Topics– Intro– Emacs concepts– General editing– Perl programming– External tools– Emacs-Perl integration : extension packages

Page 3: Emacs, a performant IDE for Perl

12.04.23 - Page 3

What is Emacs ?

• "Emacs is the extensible, customizable, self-documenting real-time display editor".

– advanced : provides much more than simple insertion and deletion. It can control subprocesses, indent programs automatically, show two or more files at once, and edit formatted text.

– self-documenting : can type C-h at any time to find out what the options are.

– customizable : thousands of variables – extensible : internal Lisp interpreter– feature-rich : thousands of commands

Page 4: Emacs, a performant IDE for Perl

12.04.23 - Page 4

Emacs history

• early 1970s : initial work on PDP computers (MIT Labs)

• 1976 : first release• 1981 : Gosling Emacs on Unix• 1986 : GNU Emacs 15.34• 1991 : XEmacs fork (formerly Lucid Emacs)• 2008: GNU Emacs 22.3

Page 5: Emacs, a performant IDE for Perl

12.04.23 - Page 5

Emacs main concepts

• buffer : basic editing unit (text being edited). Can be bound to various contents like :– file (local/remote)– computed content (listings, compilation results, shell, email, etc.)– external process

• window : screen area for displaying buffer content• frame : OS window• mode : set of options for editing some kind of content

– major mode : mutually exclusive– minor mode : additional options (plugin)

Page 6: Emacs, a performant IDE for Perl

12.04.23 - Page 6

Other concepts

• region : portion of buffer between mark and point

• rectangle : rectangular area instead of linear text

• register : memory for storing text / position / rectangle

• macro : recorded sequence of keys• desktop : saved Emacs session

Page 7: Emacs, a performant IDE for Perl

12.04.23 - Page 7

User input

• Input events– character events– modifiers : <CTRL>, <ALT>, <META>, <SUPER>– mouse, scroll, click, focus, etc.

• Key sequence– prefix key keymap. Ex:

• C-x General extended commands• C-h Help commands• C-c Mode-specific extended commands

– complete key command

• Keymap– binding key command– global / local

Page 8: Emacs, a performant IDE for Perl

12.04.23 - Page 8

Entering commands/args in minibuffer

• Auto-completion• Default argument• Editing (cut/paste/move/etc.)• Command history

Page 9: Emacs, a performant IDE for Perl

12.04.23 - Page 9

Modes may implement …

• additional commands• local implementation for generic operations

– ex: comment-region, indent-region

• syntax highlighting• local keymaps• local menus• modifications to the display (ex. status line)• hooks

Page 10: Emacs, a performant IDE for Perl

12.04.23 - Page 10

Editing

• Move– by character, word, sentence, paragraph, page

• Copy / Cut / Paste– kill ring : history of killed fragments

• Search / Replace– incremental / regex– word search (without regard to punctuation)– clever case substitutions– recursive edit

• Abbrevs• Undo

Page 11: Emacs, a performant IDE for Perl

12.04.23 - Page 11

Files

• File names / completion / disambiguation• Remote files (ange-ftp / tramp)• Archives / compressed files• Mode chosen automatically from name or

content• Bookmarks (filename / position / comment)• Shadowing (automatic replication)• Filesets

Page 12: Emacs, a performant IDE for Perl

12.04.23 - Page 12

Editing directories

• listing• create / rename / delete• bulk operations (mark / regexp )• open subdirectories in same buffer• chmod, mkdir, etc.• exec shell command on file(s)

Page 13: Emacs, a performant IDE for Perl

12.04.23 - Page 13

Shell

• Inferior process– filename completion– history ring– editing command-line– directory tracking– remote host (telnet, rlogin, etc)

• Eshell – no process, all done in Emacs

Page 14: Emacs, a performant IDE for Perl

12.04.23 - Page 14

Help

• Info (manual)• Help on

– variables– functions– keys– bindings– mode– apropos

Page 15: Emacs, a performant IDE for Perl

12.04.23 - Page 15

Programming modes : generic features

• Recognize top-level definitions– go to begin / end, set region

(C-M-h), imenu

• Indentation– clever syntax parsing; various

indent styles (K&R, BSD, Gnu, etc.)

• Balanced parentheses– begin / end, up / down, kill,

• (C-M-LEFT, C-M-UP, ..)– blink-matching

• Comments– insert, realign, comment /

uncomment region, reformat

• Syntax highlighing

• Restricting editing scope– hideshow minor mode– narrowing

• (C-x n d / w)

• Autocompletion

• Electric characters– automatic reindent / newline

• Tags support

Page 16: Emacs, a performant IDE for Perl

12.04.23 - Page 16

Cperl mode

• based on C-mode– indenting– electric parentheses– automatic expansion (if, else, while, do, foreach, …)– syntax highlighting– binding to perlinfo– menu, tools– perldb : gud bindings

• next / step• break (C-x SP)

Page 17: Emacs, a performant IDE for Perl

12.04.23 - Page 17

Compiling and testing

• Compilation– launch compiler subprocess ("perl", "gcc", "make", etc.)– mod-compile.el : additional layer

• adapt compilation command to current language / context

– parse errors and navigate to source files– usual Emacs commands for viewing results / debug logs

• GUD (Grand Unified Debugger)– shell buffer– navigate to source files

Page 18: Emacs, a performant IDE for Perl

12.04.23 - Page 18

Searching

• builtin support for "grep"• ack.el : adaptation for "ack"• navigate in matched files like for the compilation

buffer

Page 19: Emacs, a performant IDE for Perl

12.04.23 - Page 19

Autocompletion

• Static sources– Tags– Language-specific doc

• More context-aware– Emacs extensions : Sepia, PerlySense

• Dabbrev– most recent, preceding word for which this is a prefix– if none, search following words– if none, search other "friend" buffers

• Hippie-expand– ring of try functions

• try-complete-file-name• try-expand-all-abbrevs• try-expand-line• try-expand-dabbrev• try-expand-whole-kill

Page 20: Emacs, a performant IDE for Perl

12.04.23 - Page 20

External filters

• Ex: perltidy

; tidy perl code on region(defun perltidy () "run perltidy on the current region or buffer." (interactive) (shell-command-on-region (point) (mark)

"perltidy -q" nil t))

(global-set-key "\C-ct" 'perltidy)

Page 21: Emacs, a performant IDE for Perl

12.04.23 - Page 21

Version control

• generic version control (VC)• psvn.el : SVN support

– status • dired-like

– log– ediff

• similar modes for git

Page 22: Emacs, a performant IDE for Perl

12.04.23 - Page 22

Differences / patches

• ediff-mode– both versions side-by-side (horizontal or vertical)– ediff commands

• previous / next• copy A B / B A

– apply patches (multifiles OK)

Page 23: Emacs, a performant IDE for Perl

12.04.23 - Page 23

perlcritic

• mode perlcritic.el distributed with Perl::Critic– apply on buffer– apply on region– parse output

• other solution: treat as a standard compile command– must configure .perlcriticrc so that Emacs understands

filenames

verbose = %f:%l:%c: %m, %e (%p, severity %s)\n

Page 24: Emacs, a performant IDE for Perl

12.04.23 - Page 24

Emacs::EPL

• Perl-Emacs IPC integration, followup to "Perlmacs"• looks like this was very nice work

– adapted environment for running Perl under Emacs• redefine STDIN, STDOUT as hooks to Emacs minibuffer• populate ENV• …

– can write Emacs modules in Perl instead of elisp !

• last distribution dates back to 2001, using Perl 5.004

• couldn't get it to work

Page 25: Emacs, a performant IDE for Perl

12.04.23 - Page 25

Devel::PerlySense

• Perl process in the background• Lots of features

– links to doc– class hierarchy analysis and method analysis– jump to definition / class– run / debug– run tests– interact with ack– notion of "project"– file templates

• but very CPU-intensive and slow

Page 26: Emacs, a performant IDE for Perl

12.04.23 - Page 26

Sepia

• last distrib May 09• Inspired by Emacs Lisp dev. philosophy• Features

– completion on partial words, i.e. L:U List::Util– inferior Perl process with REPL loop– analyses opcodes– links to doc, to func definitions, to modules

only recognizes core modules/functions– didn't figure how to let it read perl/site/lib !

Page 27: Emacs, a performant IDE for Perl

12.04.23 - Page 27

Emacs::PDE

• last distrib July 2008• Features (pde-load)

– projects– smart compile (C-c r) / debug– tags / menus / tree view (C-c C-v TAB)– perldoc integration with browser (C-c C-v RET, C-c C-v C-p)– special indenting mode– integrate with perltidy / perlcritic– interactive perl shell

no install problems• need to learn more