From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joakim Hove Newsgroups: gmane.emacs.help Subject: Re: regexp / replacement for variable Date: Tue, 24 Feb 2004 15:03:10 +0100 Organization: University of Bergen Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <4yptc4wp5t.fsf@skjellgran.ii.uib.no> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1077632336 16343 80.91.224.253 (24 Feb 2004 14:18:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 24 Feb 2004 14:18:56 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 24 15:18:50 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 1AvdOb-0004Rb-00 for ; Tue, 24 Feb 2004 15:18:49 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1AvdNZ-0006qW-GJ for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Feb 2004 09:17:45 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!darth-vader.mobilixnet.dk!feed.news.tiscali.de!uio.no!nntp.uib.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 74 Original-NNTP-Posting-Host: skjellgran.ii.uib.no Original-X-Trace: toralf.uib.no 1077630865 52887 129.177.20.52 (24 Feb 2004 13:54:25 GMT) Original-X-Complaints-To: abuse@uib.no Original-NNTP-Posting-Date: 24 Feb 2004 13:54:25 GMT User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:akNgpUeROEiqrisSXLRArFQ1yWk= Original-Xref: shelby.stanford.edu gnu.emacs.help:121184 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:17135 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:17135 Kevin Dziulko writes: > depending on the given filename. > > I put the following to my .emacs file: > > (defun new-c-header () > "Insert c-header skeleton." > (interactive "") > (progn > (setq bname (upcase(buffer-name))) > (insert > (message "#ifndef %s\n\#define %s\n\n#endif" > bname bname)))) The (progn ) construction in your code is superfluous. Suggestion: use (let ) to define variables with local scope, in your implementation the variable bname will be defined and visible for the complete remaining emacs session. (let ((bname (upcase (buffer-name))) (var2 "value for var2)) ... ... ... ) > Apart from knowing that "message" might not be the right > choice here That is right - (message ..) prints the contents in the minibuffer. Insert should do the job: (insert (format "#ifndef %s\n#define %s\n\n#endif bname bname)) > , I don't know how to modify the value of bname!? "replace-regexp" > doesn't seem to be the what I'm looking for. I don't understand what changes you want to make to bname. Maybe the (string-match ..) / (match-string ...) functions provide the functionality you are after? > (and how could the new-c-header() be invoked by creating a (add-hook 'c-mode-hook 'new-c-header) will call new-c-header *every* time you open a .c/.h file, i.e. also if it is an existing file. Maybe if you start new-c-header like this: ... (if (= (point-min) (point-max)) (let ((bname ... ... Warning - there are probably more elegant ways to check whether a file is new or not. HTH - Joakim -- /--------------------------------------------------------------------\ / Joakim Hove / hove@bccs.no / (55 5) 84076 | \ | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 | | CMU | 5231 Paradis | \ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 / \--------------------------------------------------------------------/