Toggling “hairy” features in cperl-mode of Emacs

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.

(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.

One thought on “Toggling “hairy” features in cperl-mode of Emacs

  1. Pingback: Pasting a text literally to Emacs under terminal ¶ Exercises In Self-Indulgence

Leave a Reply

Your email address will not be published.