Tuesday, June 15, 2010

Emacs: Replace the standard perl-mode with cperl-mode

CPerlMode is a more advanced mode for programming Perl than the default PerlMode. To replace the standard perl-mode with cperl-mode in all cases you need the following in your ~/.emacs file (or your InitFile):

;;; cperl-mode is preferred to perl-mode
;;; "Brevity is the soul of wit"
(defalias 'perl-mode 'cperl-mode)


Alternatively, use:

(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.\\([tT]\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))


Or the more robust equivalent:

(mapc
(lambda (pair)
(if (eq (cdr pair) 'perl-mode)
(setcdr pair 'cperl-mode)))
(append auto-mode-alist interpreter-mode-alist))

No comments:

Post a Comment