all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Expanding list into string within a command
Date: Sun, 06 Dec 2020 22:46:26 +0300	[thread overview]
Message-ID: <courier.000000005FCD3514.00001EBA@static.rcdrun.com> (raw)


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 "/"))))



             reply	other threads:[~2020-12-06 19:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06 19:46 Jean Louis [this message]
2020-12-06 19:57 ` Expanding list into string within a command arthur miller
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

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

  git send-email \
    --in-reply-to=courier.000000005FCD3514.00001EBA@static.rcdrun.com \
    --to=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.
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.