all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* getting output from external process in a variable
@ 2004-01-30 11:02 Daan Hoogland
  0 siblings, 0 replies; 5+ messages in thread
From: Daan Hoogland @ 2004-01-30 11:02 UTC (permalink / raw)


H all,

I'm doing some application programming in elisp. I read /etc/group with 
grep and edit the temporary buffer with results. now I end up with 
groupname:member1,member2 and I want it in a list:
(list "groupname" (list "member1" "member2"))
now I can edit the buffer to cantain the lisp expression and then 
evaluate it like:
(set 'var (list "groupname" (list "member1" "member2")))
and use var. But I was wondering wether there was somewhere maybe an 
api that can set a var to a region in the current buffer directly.

Am I understanding emacs and lisp here?
Is there maybe a better/quicker solution?

Is there such a function that could for instance read-list-from-text 
from start to end with delimiters?
Or one that can just take text and put it in a variable?

Any comment appreciated.

D.A.A.N.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: getting output from external process in a variable
       [not found] <mailman.1600.1075460572.928.help-gnu-emacs@gnu.org>
@ 2004-01-30 15:39 ` Gareth Rees
  2004-01-30 16:03 ` Stefan Monnier
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Gareth Rees @ 2004-01-30 15:39 UTC (permalink / raw)


Daan Hoogland wrote:
> I end up with [a buffer containing lines of the form]
> groupname:member1,member2 and I want it in a list:
> (list "groupname" (list "member1" "member2"))

  (require 'cl)
  (defun munge-buffer ()
    (goto-char (point-min))
    (loop while (re-search-forward "^\\(\\w+\\):\\(\\w+\\),\\(\\w+\\)$" nil t)
          collect `(,(match-string 1) (,(match-string 2) ,(match-string 3)))))

-- 
Gareth Rees

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: getting output from external process in a variable
       [not found] <mailman.1600.1075460572.928.help-gnu-emacs@gnu.org>
  2004-01-30 15:39 ` getting output from external process in a variable Gareth Rees
@ 2004-01-30 16:03 ` Stefan Monnier
  2004-01-30 21:28 ` Kevin Rodgers
  2004-02-05  8:01 ` Kai Grossjohann
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2004-01-30 16:03 UTC (permalink / raw)


>>>>> "Daan" == Daan Hoogland <emacs@onecht.net> writes:
> groupname:member1,member2 and I want it in a list:
> (list "groupname" (list "member1" "member2"))

  (when (re-search-forward ":\\([^,]*\\)," nil t)
    (list (buffer-substring (point-min) (match-beginning 0))
          (list (match-string 1)
                (buffer-substring (point) (point-max)))))

I don't recommend the above style (especially using (point) instead of
(match-end 0)), but that should get you started.


        Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: getting output from external process in a variable
       [not found] <mailman.1600.1075460572.928.help-gnu-emacs@gnu.org>
  2004-01-30 15:39 ` getting output from external process in a variable Gareth Rees
  2004-01-30 16:03 ` Stefan Monnier
@ 2004-01-30 21:28 ` Kevin Rodgers
  2004-02-05  8:01 ` Kai Grossjohann
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2004-01-30 21:28 UTC (permalink / raw)


Daan Hoogland wrote:

> H all,
> 
> I'm doing some application programming in elisp. I read /etc/group with 
> grep and edit the temporary buffer with results. now I end up with 
> groupname:member1,member2 and I want it in a list:
> (list "groupname" (list "member1" "member2"))
> now I can edit the buffer to cantain the lisp expression and then 
> evaluate it like:
> (set 'var (list "groupname" (list "member1" "member2")))
> and use var. But I was wondering wether there was somewhere maybe an api 
> that can set a var to a region in the current buffer directly.


C-h v buffer-string
C-h v buffer-substring


> Am I understanding emacs and lisp here?
> Is there maybe a better/quicker solution?

I think so:

(let ((group-members (split-string (buffer-string) ":")))
   (list (car group-members) (split-string (cadr group-members) ",")))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: getting output from external process in a variable
       [not found] <mailman.1600.1075460572.928.help-gnu-emacs@gnu.org>
                   ` (2 preceding siblings ...)
  2004-01-30 21:28 ` Kevin Rodgers
@ 2004-02-05  8:01 ` Kai Grossjohann
  3 siblings, 0 replies; 5+ messages in thread
From: Kai Grossjohann @ 2004-02-05  8:01 UTC (permalink / raw)


Daan Hoogland <emacs@onecht.net> writes:

> I'm doing some application programming in elisp. I read /etc/group
> with grep and edit the temporary buffer with results. now I end up
> with groupname:member1,member2 and I want it in a list:
> (list "groupname" (list "member1" "member2"))
> now I can edit the buffer to cantain the lisp expression and then
> evaluate it like:
> (set 'var (list "groupname" (list "member1" "member2")))
> and use var. But I was wondering wether there was somewhere maybe an
> api that can set a var to a region in the current buffer directly.

I don't know what it means to "set a var to a region in the current
buffer directly".  Maybe you mean that you want a variable that
contains a string which is a part of the current buffer?  See the
buffer-substring and buffer-substring-no-properties functions.

Maybe you mean that you want to have ("groupname" ("member1"
"member2")) in the buffer and then "directly", in some manner,
transfer this list into a Lisp variable.  In that case, investigate
the function read.  Basically, you put point in front of the open
paren, call read once, and the return value of read will be the sexp
at point.

Kai

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-02-05  8:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1600.1075460572.928.help-gnu-emacs@gnu.org>
2004-01-30 15:39 ` getting output from external process in a variable Gareth Rees
2004-01-30 16:03 ` Stefan Monnier
2004-01-30 21:28 ` Kevin Rodgers
2004-02-05  8:01 ` Kai Grossjohann
2004-01-30 11:02 Daan Hoogland

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.