From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Paolo Gianrossi Newsgroups: gmane.emacs.help Subject: Re: inserting comment headings Date: 20 Jan 2004 13:46:18 +0100 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <87k73o9vz2.fsf@tiger.rapttech.com.au> <400C5C69.20000@yahoo.com> <20040120002847.1ed89336.paolino.gnu@disi.unige.it> <878yk3t3wt.fsf@hugin.valhalla.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1074603822 11541 80.91.224.253 (20 Jan 2004 13:03:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 20 Jan 2004 13:03:42 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 20 14:03:35 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AivXb-0006PL-00 for ; Tue, 20 Jan 2004 14:03:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AivWT-0007lc-OZ for geh-help-gnu-emacs@m.gmane.org; Tue, 20 Jan 2004 08:02:25 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fi.sn.net!newsfeed2.fi.sn.net!newsfeed3.funet.fi!193.166.3.20.MISMATCH!newsfeeds.funet.fi!newsfeed1.funet.fi!uio.no!quimby.gnus.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 74 Original-NNTP-Posting-Host: gnugw.disi.unige.it Original-X-Trace: quimby.gnus.org 1074602982 6707 130.251.61.179 (20 Jan 2004 12:49:42 GMT) Original-X-Complaints-To: usenet@quimby.gnus.org Original-NNTP-Posting-Date: Tue, 20 Jan 2004 12:49:42 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-Xref: shelby.stanford.edu gnu.emacs.help:120253 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:16197 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16197 Sean Richards writes: > Brad Collins 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