all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joakim Hove <hove@bccs.no>
Subject: Re: regexp / replacement for variable
Date: Tue, 24 Feb 2004 15:03:10 +0100	[thread overview]
Message-ID: <4yptc4wp5t.fsf@skjellgran.ii.uib.no> (raw)
In-Reply-To: mailman.372.1077629684.340.help-gnu-emacs@gnu.org


Kevin Dziulko <weaselboy1976@yahoo.com> 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     /
  \--------------------------------------------------------------------/

       reply	other threads:[~2004-02-24 14:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.372.1077629684.340.help-gnu-emacs@gnu.org>
2004-02-24 14:03 ` Joakim Hove [this message]
2004-02-24 20:09 ` regexp / replacement for variable Floyd Davidson
     [not found] <mailman.262.1077404990.340.help-gnu-emacs@gnu.org>
2004-02-22  0:41 ` Kin Cho
2004-02-22  0:51 ` lawrence mitchell
2004-02-22 12:18   ` Jan Misol
2004-02-22 12:14 ` Floyd Davidson
2004-02-21 23:08 Jan Misol
2004-02-24 13:31 ` Kevin Dziulko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4yptc4wp5t.fsf@skjellgran.ii.uib.no \
    --to=hove@bccs.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.