[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: coment line - key binding
From: |
Pascal Bourguignon |
Subject: |
Re: coment line - key binding |
Date: |
Wed, 19 Apr 2006 03:37:23 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
Rares Vernica <rvernica@gmail.com> writes:
> How can I set a global key binding to comment just one line, the
> current line the cursor is?
>
> I do not want to select the line and then M-;.
>
> Just M-; on the current line will add a comment at the end of the line.
You can write a command that will do the line selection and the
commenting for you.
(defun comment-line ()
(interactive)
(save-excursion
(comment-region (progn (beginning-of-line) (point))
(progn (end-of-line) (point)))))
Then you can call it with M-x comment-line RET from anywhere on the line.
Or, you can additionnaly bind it to a global key.
Let's say: super-;
(global-set-key (kbd "s-;") (function comment-line))
Perhaps it would be useful to make it a toggle:
(defun toggle-comment-line ()
(interactive)
(save-excursion
(funcall
(if (progn (beginning-of-line)
(looking-at (format "\\s-*%s" (regexp-quote comment-start))))
(function uncomment-region)
(function comment-region))
(progn (beginning-of-line) (point))
(progn (end-of-line) (point)))))
(global-set-key (kbd "s-;") (function toggle-comment-line))
--
__Pascal_Bourguignon__ _ Software patents are endangering
() ASCII ribbon against html email (o_ the computer industry all around
/\ 1962:DO20I=1.100 //\ the world http://lpf.ai.mit.edu/
2001:my($f)=`fortune`; V_/ http://petition.eurolinux.org/