Книга: Learning GNU Emacs, 3rd Edition

9.6.1 Perl Caveats

9.6.1 Perl Caveats

A big reason we wanted to mention Perl mode here is to highlight a few caveats. Perl is an amazingly expressive language much more akin to the idioms found in human languages than just about any other computer language out there. That expressiveness can cause problems—especially when considering the expressiveness of regular expressions.

Perl supports all sorts of "funny" variable names like $' and $/. CPerl mode boasts the use of a syntax table to help understand most of Perl's odd and occasionally disruptive verbiage. The older Perl mode has no such trick up its sleeves and suffers under many circumstances in the font-lock and indentation realms. This is one of the main reasons to make the leap into CPerl mode.

Even with that syntax table, though, you'll probably find some combinations of variables and strings that give Emacs headaches. Sometimes restructuring your code will help, sometimes not. The important thing to remember is that it won't harm your program at all. It might make things a bit less readable, but the script itself should run just fine. And if it doesn't, you can always launch the debugger to find out why!

Here are some parting .emacs thoughts for you Perl programmers. These lines select cperl-mode as the default and make sure the syntax highlighting is turned on. These lines also turn on folding (outline-minor-mode in the snippet below). Folding allows you to "hide" chunks of your code, such as functions where the body of the function is "folded" into the name. That can make it easier to get a grip on everything that is going on in the file. Try it—it can become addictive!

;; Turn on highlighting globally
(global-font-lock-mode t)
;; automatically load cperl-mode for perl files
(fset 'perl-mode 'cperl-mode)
;; show only the toplevel nodes when loading a file
(add-hook 'cperl-mode-hook 'hide-body)
;; outline minor mode with cperl
(add-hook 'cperl-mode-hook 'outline-minor-mode)
;; Change the prefix for outline commands from C-c @ to C-c C-o
(setq outline-minor-mode-prefix "C-co")
(load-file "cperl-mode.el")

Оглавление книги

Оглавление статьи/книги

Генерация: 1.868. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз