* coment line - key binding
@ 2006-04-19 1:13 Rares Vernica
2006-04-19 1:37 ` Pascal Bourguignon
0 siblings, 1 reply; 3+ messages in thread
From: Rares Vernica @ 2006-04-19 1:13 UTC (permalink / raw)
Hi,
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.
Thanks,
Ray
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: coment line - key binding
2006-04-19 1:13 coment line - key binding Rares Vernica
@ 2006-04-19 1:37 ` Pascal Bourguignon
2006-04-19 1:56 ` Rares Vernica
0 siblings, 1 reply; 3+ messages in thread
From: Pascal Bourguignon @ 2006-04-19 1:37 UTC (permalink / raw)
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: coment line - key binding
2006-04-19 1:37 ` Pascal Bourguignon
@ 2006-04-19 1:56 ` Rares Vernica
0 siblings, 0 replies; 3+ messages in thread
From: Rares Vernica @ 2006-04-19 1:56 UTC (permalink / raw)
That works!
Thanks a lot,
Ray
Pascal Bourguignon wrote:
> 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))
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-04-19 1:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-19 1:13 coment line - key binding Rares Vernica
2006-04-19 1:37 ` Pascal Bourguignon
2006-04-19 1:56 ` Rares Vernica
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).