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

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

Re: inserting comment headings


From: Brad Collins
Subject: Re: inserting comment headings
Date: Tue, 20 Jan 2004 13:36:25 +0700
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (windows-nt)

Paolo Gianrossi <paolino.gnu@disi.unige.it> writes:

> don't want to spoil your research :) but you might not need
> that... each mode defines comments... Won't say more if you don't
> ask, you might be having fun with this...
>

Okay teacher -- here is my homework :)

I'm just a beginner as well, but this seems to work...  Is there a
better way to do this?

(defun insert-comment-heading (comment)
  "Insert COMMENT, followed by \" ---...\".  The line will be
  commented based on which mode you are in." 
  (interactive "sComment: ")
  (insert  comment " " (make-string (- (window-width)
                                             (+ (length comment) 5)
                                             10)
                                          ?-))
  (previous-line 1)
  (let ((line-start (point)))
    (forward-paragraph 1)
    (when comment-start
      (comment-region line-start (point))))
  (newline))

I tried it in a couple different modes:

> message mode ---------------------------------------------------
;; lisp-mode --------------------------------------------------------
# yaml mode --------------------------------------------------------
/* css mode --------------------------------------------------------- */
@Comment bibtex mode ------------------------------------------------------
@c texinfo mode -----------------------------------------------------

Cool, this is a useful little snippet, thanks everyone!

b/

--
Brad Collins
Chenla Labs
Bangkok, Thailand





reply via email to

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