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

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

Re: inserting comment headings


From: Paolo Gianrossi
Subject: Re: inserting comment headings
Date: 20 Jan 2004 13:46:18 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Sean Richards <somebody@nowhere.com> writes:

> Brad Collins <brad@studiojungle.net> writes:
> 
> > Okay teacher -- here is my homework :)

It wasn't a teacher's attitude (I'm no lisp guru as well... :) i just thought
that if you wanted to research on your own for the fun of it, it would have
been bad to tell you...

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

Your solution is quite nice...

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



> Well I'm pretty green with elisp as well but I think it is a bit nicer
> to solve the problem as shown below ....

This looks even better to me... 

> --8<----------------------------------------------------------------------
> 
> (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)
>                                     ?-))
>   (comment-region (point-at-bol) (point-at-eol)))  
>   (newline))
> 
> --8<----------------------------------------------------------------------

For my taste, though, I'd use fill-column and dynamic comment size to find the
-line length, like:

(defun inserrt-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 (- fill-column
                       (+ (length comment) (length comment-start) 
                          (length comment-end)))       
                                    ?-))
  (comment-region (point-at-bol) (point-at-eol))
  (goto-char (point-at-eol))
  (newline)
)


cheers
paolino


reply via email to

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