From: arthur miller <arthur.miller@live.com>
To: Jean Louis <bugs@gnu.support>, Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: RE: Expanding list into string within a command
Date: Sun, 6 Dec 2020 19:57:22 +0000 [thread overview]
Message-ID: <AM0PR06MB657758210436328901DF0BB096CF0@AM0PR06MB6577.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <courier.000000005FCD3514.00001EBA@static.rcdrun.com>
"So I was thinking to use macro that will expand the list within a command."
Try smth like this:
(my-macro (command &rest list)
(dolist (item `,@list)
(dosnth with your list item here)))
Kind of, if that is what yiu want, I am not sure really what you are after here, but I use that as an idiom quite a lot.
I am not at home, just fast from my phone .....
-------- Originalmeddelande --------
Från: Jean Louis <bugs@gnu.support>
Datum: 2020-12-06 20:47 (GMT+01:00)
Till: Help GNU Emacs <help-gnu-emacs@gnu.org>
Ämne: Expanding list into string within a command
I would like to get this function to work, to convert geographical
coordinates notation from 5d15'57.76"S 35d8'22.65"E to decimal system
by using `proj' software and I wish to make generic function that will
accept any kind of format input to avoid hard coding.
This works well on command line:
$ cs2cs -f "%.6f" +proj=latlong +datum=WGS84 +to +proj=latlong +datum=WGS84
5d15'57.76"S 35d8'22.65"E
-5.266044 35.139625 0.000000
And I know how to make it when hard coded. Here I wish to expand it
maybe with macro.
This is the invocation of the function that I would like to get
working by feeding 2 strings, first being coordinates and second the
`cs2cs' format for conversions of coordinates.
(syogm-cs2cs "5d15'57.76\"S 35d8'22.65\"E" "-f \"%.6f\" +proj=latlong +datum=WGS84 +to +proj=latlong +datum=WGS84")
Error is:
"Rel. 6.1.0, May 15th, 2019
<cs2cs>:
missing argument for -f
program abnormally terminated
"
Error probably comes from lack of my knowledge how to use macro
expansion as here one could see how I have imagined that it could
expand:
(defun syogm-cs2cs (coord-string cs2cs-format)
(let* ((command "cs2cs")
(output (command-stream-in-out command coord-string `,(string-join (split-string cs2cs-format) " "))))
output))
So I was thinking to use macro that will expand the list within a
command. Is there different better way to do this?
The below functions are related only in so far to maybe make these
above working.
This function here I could improve. This one is invoked many times by
many programs and I would not like changing it. One way to solve the
issue could be that I test for ARGS if it is list or not and convert
there.
(defun command-stream-in-out (command string &rest args)
(let* ((uid (number-to-string (user-uid)))
(memory-dir (rcd-memory-dir))
(infile (concat memory-dir "command-input")))
(string-to-file-force string infile)
(with-temp-buffer
(apply 'call-process command infile (current-buffer) nil args)
(buffer-string))))
All below functions are only relevant for execution of above
functions.
(defun rcd-memory-dir ()
(let ((xdg-runtime-dir (getenv "XDG_RUNTIME_DIR")))
(if xdg-runtime-dir (slash-add xdg-runtime-dir)
(if (and (file-directory-p "/dev/shm")
(file-writable-p "/dev/shm"))
(slash-add "/dev/shm")))))
(defun string-to-file-force (string file)
"Prints string into file, matters not if file exists. Returns FILE as file name."
(with-temp-file file
(insert string))
file)
(defun slash-add (path)
"Adds slash `/` quickly on the end of string"
(let ((last (substring (reverse path) 0 1)))
(if (string= last "/") path
(concat path "/"))))
next prev parent reply other threads:[~2020-12-06 19:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-06 19:46 Expanding list into string within a command Jean Louis
2020-12-06 19:57 ` arthur miller [this message]
2020-12-06 20:30 ` Jean Louis
2020-12-06 19:57 ` [solved] " Jean Louis
2020-12-06 20:07 ` arthur miller
2020-12-06 20:34 ` dms2dd " Jean Louis
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM0PR06MB657758210436328901DF0BB096CF0@AM0PR06MB6577.eurprd06.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).