help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coment line - key binding


From: Rares Vernica
Subject: Re: coment line - key binding
Date: Tue, 18 Apr 2006 18:56:57 -0700
User-agent: Thunderbird 1.5 (Windows/20051201)

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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]