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

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

Re: Add functions to C-mode?


From: Ph . Ivaldi
Subject: Re: Add functions to C-mode?
Date: Sat, 19 Apr 2008 15:01:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

saneman wrote :

> I would like to add/change the comment/uncomment function in the
> C-mode for emacs.
> Currently it only works when a piece of text is selected and then /*
> */ is inserted.
> I would like to change the function to just insert // even though some
> text might not be selected.

I use this code but one can certainly do better:
8<------8<------8<------8<------8<------8<------8<------8<------8<------
(defun pi-?comment ()
  (interactive)
  (save-excursion
    (if mark-active
        (let ((br (region-beginning))
              (be (region-end)))
          (comment-or-uncomment-region br be)
          (indent-region br be))
      (let ((br (progn  (back-to-indentation) (point)))
            (be (progn (end-of-line) (point))))
        (comment-or-uncomment-region br be)
        (indent-according-to-mode)))))
(global-set-key (kbd "C-%") 'pi-?comment)
8<------8<------8<------8<------8<------8<------8<------8<------8<------

-- 
   Philippe Ivaldi.
http://piprim.tuxfamily.org/


reply via email to

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