(defun my-indent-for-comment (arg) "dwim indent-for-comment V0.03" (interactive "p") (cperl-update-syntaxification (point) (point)) (if (and (not (memq (preceding-char) '(?$) )) ;; (memq (preceding-char) '( ?\; ?{ ?\( ?\[ ) ) (memq (get-text-property (point) 'face) '(cperl-my-trailing-spaces-face nil)) (looking-at "[[:space:]]*$") ) (cperl-indent-for-comment) (insert "#")) ) (add-hook 'cperl-mode-hook (lambda () (local-set-key (kbd "C-#") 'comment-dwim) (local-set-key (kbd "#") 'my-indent-for-comment) (set-variable 'cperl-comment-column 45 ) ))