the following emacs lisp code makes typing # DWIM. At the "end" of a perl code line it will automatically indent to the comment-column.
Example typing ..."huhu";#the hash... will produce this indentation:
The code is work in progress if you find bugs feel free to reply here.sub load { print "huhu"; # the hash automatically "jumped"
Plz note I also bound C-# to what normally M-; does, because it's much easier to reach on QWERTZ keyboards and IMHO more intuitive in Perl context. Additionally this command will also automatically comment/uncomment selected text.(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-sp +aces-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 ) ))
UPDATE: You have the choice between different levels of aggressiveness, ATM the command checks¹ if the hash doesn't follow a blacklist of chars (actually $). You can change this behaviour to more restrictive whitelisting by uncommenting the following line (i.e. has to follow ; { ( [)
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [emacs] automatically indent to comment-column
by LanX (Saint) on May 10, 2010 at 12:43 UTC | |
|
Re: [emacs] automatically indent to comment-column
by LanX (Saint) on May 12, 2010 at 10:23 UTC |