From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Expanding list into string within a command Date: Sun, 06 Dec 2020 22:46:26 +0300 Message-ID: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27897"; mail-complaints-to="usenet@ciao.gmane.io" To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 06 20:47:33 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1km00L-00079i-JZ for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 20:47:33 +0100 Original-Received: from localhost ([::1]:41382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1km00K-0002D8-Kx for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 14:47:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klzzs-0002Ah-4q for help-gnu-emacs@gnu.org; Sun, 06 Dec 2020 14:47:04 -0500 Original-Received: from static.rcdrun.com ([95.85.24.50]:55815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klzzq-0001XY-Ny for help-gnu-emacs@gnu.org; Sun, 06 Dec 2020 14:47:03 -0500 Original-Received: from localhost ([::ffff:197.157.0.57]) (AUTH: PLAIN admin, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by static.rcdrun.com with ESMTPSA id 00000000002C0010.000000005FCD3514.00001EBA; Sun, 06 Dec 2020 19:46:28 +0000 Received-SPF: pass client-ip=95.85.24.50; envelope-from=support1@rcdrun.com; helo=static.rcdrun.com X-Spam_score_int: 17 X-Spam_score: 1.7 X-Spam_bar: + X-Spam_report: (1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126097 Archived-At: 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 : 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 "/"))))