From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Sean Richards Newsgroups: gmane.emacs.help Subject: Re: inserting comment headings Date: Tue, 20 Jan 2004 21:33:54 +1300 Organization: Xtra Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <878yk3t3wt.fsf@hugin.valhalla.net> References: <87k73o9vz2.fsf@tiger.rapttech.com.au> <400C5C69.20000@yahoo.com> <20040120002847.1ed89336.paolino.gnu@disi.unige.it> Reply-To: sean_news@myrealbox.com NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1074587485 9123 80.91.224.253 (20 Jan 2004 08:31:25 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 20 Jan 2004 08:31:25 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 20 09:31:18 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 1AirI6-0005ap-00 for ; Tue, 20 Jan 2004 09:31:18 +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 1AirHU-0005Qa-KV for geh-help-gnu-emacs@m.gmane.org; Tue, 20 Jan 2004 03:30:40 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!enews.sgi.com!news.xtra.co.nz!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:nKKGGl1vYgyBiNcRt6KY4FcdRBk= Original-Lines: 44 Original-NNTP-Posting-Host: 203.96.102.245 Original-X-Complaints-To: newsadmin@xtra.co.nz Original-X-Trace: news.xtra.co.nz 1074587353 203.96.102.245 (Tue, 20 Jan 2004 21:29:13 NZDT) Original-NNTP-Posting-Date: Tue, 20 Jan 2004 21:29:13 NZDT Original-Xref: shelby.stanford.edu gnu.emacs.help:120248 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:16192 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16192 Brad Collins writes: > 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)) Well I'm pretty green with elisp as well but I think it is a bit nicer to solve the problem as shown below .... --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<---------------------------------------------------------------------- Sean -- "Hver sin smak", sa vintapperen, han drakk mens de andre sloss.