all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@genuity.net>
Subject: Re: ** Q: HOW TO MANIPULATE STRINGS IN A FILE WITH A LISP FUNCTION **
Date: Tue, 17 Sep 2002 17:49:37 GMT	[thread overview]
Message-ID: <RWJh9.9$3R2.1483@paloalto-snr1.gtei.net> (raw)
In-Reply-To: 9e8ebeb2.0209151930.79f76ae9@posting.google.com

In article <9e8ebeb2.0209151930.79f76ae9@posting.google.com>,
gnuist <gnuist007@hotmail.com> wrote:
>My problem is very simple for an emacs guru. More than one solution is
>very welcome.
>
>I have a list of numbers in a file as follows:
>
>ABC98789
>DDE90898889
>FRE9090909
>
>that is, first three letters and then a string of numbers and nothing else.
>
>I want to write a lisp function (not a macro) that can read the first
>three letter substring into a variable and the rest of the substring into
>another variable. Then I want to use these substrings to generate my
>final string. I know that can be done using the "insert" command. The problem
>is how to put the text strings in a file into a variable? I know setq can
>do this but then if I construct the string in sexp such as:
>
>(setq letters-variable "ABC")

(defun my-function (string)
  (let ((letters (substring str 0 3))
        (numbers (substring str 3)))
    (insert (format "The letters are %s, the numbers are %s."
                    letters numbers))))

>how do I eval it? I have tried eval-last-sexp IN THE LISP FUNCTION
>and it gives some strange result in the minibuffer when the function is run.

The minibuffer will show the return value of the expression.  It would help
if you described what you expected to happen and what actually happened,
rather than the vague "some strange result".

It seems like you need to learn Lisp.  The Emacs Lisp manual should be a
good place to start.

-- 
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

      parent reply	other threads:[~2002-09-17 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-16  3:30 ** Q: HOW TO MANIPULATE STRINGS IN A FILE WITH A LISP FUNCTION ** gnuist
2002-09-16 13:07 ` D. Goel
2002-09-17 17:49 ` Barry Margolin [this message]

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='RWJh9.9$3R2.1483@paloalto-snr1.gtei.net' \
    --to=barmar@genuity.net \
    /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.