Emacs’s cperl-mode
has many “electric” features, but how would you turn them all at once? Here’s my implementation of cperl-toggle-hairy
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
(eval-after-load "cperl-mode" '(progn (defun cperl-toggle-hairy () (interactive) (unless (boundp 'cperl-electric-prev-alist) (set (make-local-variable 'cperl-electric-prev-alist) nil)) (cond (cperl-electric-prev-alist (dolist (pair cperl-electric-prev-alist) (set (car pair) (cdr pair))) (abbrev-mode (if abbrev-mode 1 0)) (setq cperl-electric-prev-alist nil) (message "cperl-toggle-hairy: on.") t) (t (dolist (var '(abbrev-mode cperl-auto-newline cperl-electric-keywords cperl-electric-lbrace-space cperl-electric-linefeed cperl-electric-parens cperl-hairy cperl-indent-region-fix-constructs cperl-info-on-command-no-prompt cperl-lazy-help-time)) (setq cperl-electric-prev-alist (cons (cons var (symbol-value var)) cperl-electric-prev-alist)) (set var nil)) (message "cperl-toggle-hairy: off.") nil))) (define-key cperl-mode-map "\C-c\C-l" 'cperl-toggle-hairy) (defun cperl-electric-quote (arg) (interactive "P") (self-insert-command (prefix-numeric-value arg)) (and (cperl-val 'cperl-electric-parens) (let ((properties (text-properties-at (point)))) (and (null (memq 'font-lock-string-face properties)) (null (memq 'font-lock-comment-face properties)) (save-excursion (insert last-command-event)))))) (define-key cperl-mode-map "\"" 'cperl-electric-quote) (define-key cperl-mode-map "'" 'cperl-electric-quote))) |
As you see, I put cperl-electric-quote
as a New Year’s present.