From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: arthur miller Newsgroups: gmane.emacs.help Subject: RE: Expanding list into string within a command Date: Sun, 6 Dec 2020 20:07:59 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38011"; mail-complaints-to="usenet@ciao.gmane.io" To: Jean Louis , Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 06 21:08:54 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 1km0Kz-0009o9-Tp for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 21:08:54 +0100 Original-Received: from localhost ([::1]:54850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1km0Ky-00019Z-RK for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 15:08:53 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1km0KE-00017N-5q for help-gnu-emacs@gnu.org; Sun, 06 Dec 2020 15:08:06 -0500 Original-Received: from mail-vi1eur06olkn2022.outbound.protection.outlook.com ([40.92.17.22]:30561 helo=EUR06-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1km0KB-0000S5-3F for help-gnu-emacs@gnu.org; Sun, 06 Dec 2020 15:08:05 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ieF0OGnrIhWITiJLjefy0DUD35kS4l/LKSmAGkwS3cEJeF369720WPhaI+bTL3AxSBFSSuzInHwaD4yz3GiVV6HtxTpD4+kAxVS03METHYIQoVGWNavRPYDrSGO6uZxnHRF7BI19XV+JDlpRLA0jKpGA4NAA3sLGAMAlZHpC+ExyluZrjZEDsmP293PHvh+eRB/ePZ1Ii1wU2ZBO2ucahJ+GXSEJSV/BBovJsP5rNw3jKjp1rzEklljj3rDD4WsXBvInHgx+X3DdPJ/rwCBMBoPk0+GaQtN0GB13INk2V3uPIAD2ILjaXkYPrMPacAzkIS+dfg1wGzfSuUsot8x/nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UUdkwmQ+EmYd7KzVnm4sINsY1Uoejb8KbW9+1ffNpXA=; b=lNG6PuORVFfhQlyjVvIROtlbXX5EeO1lBBBdd7FgGl5cVDZlwbN/+dHUFFUBZS3T9yyQ7dKnpKfzEze661lD3GupZhXQ9Qlag9kcLcvmF3FOty9/3+AcMBF2OndvPJJYQfvtkxpe9IYiAoT+Moc7hfvyVF5gJzzRtmSWkBAFDXVl/l4hi7kkiMvqeaaDfX24vCFFED990zeQu90eYojn8br7BQljnf/8f7s4VUcMdHQMnPdIJFGKiQ2QZ9b8s9IuZrvfNLNfyLMJNVe1OYG7MnlmxZhTjns4cjmDc5PzZh3sZioBWpon3DjB+rPF3jFyZ6b6x7n8wFkuGR1t1Hyw7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UUdkwmQ+EmYd7KzVnm4sINsY1Uoejb8KbW9+1ffNpXA=; b=GXj0CWy6nWVRMpy8Fhxwbt7Cv0/tm0auFEoSjyep58umIc6tCY1nSBfnsQ3unznMJbhS0IZCdv/zHbhoroaPrDwMzvDBpf1PXiusEIuNgTMHMJFKzeXH+/fFQe1scKiGTbN1hAhxZSoM0yx6zsqJWAD4cfTkCVkZydR690muLBqxGA/LYC2f8ymjSCRVZ5jbpUIA5n4HUT1TuLx1WW2Q2Fs2any4crWfs4uKU8wASXL0uM7zpPURtHYVJZQZBvYrJi0cc4XTJhFvYFB9K2UT0IXk+0DbPn3hC4KJEHlRJ+azOGDJrhXVbmYuLAJDNl1iGGlNZ0CsMhz7bF50SHy/Sw== Original-Received: from DB8EUR06FT014.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::51) by DB8EUR06HT233.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::261) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Sun, 6 Dec 2020 20:08:00 +0000 Original-Received: from AM0PR06MB6577.eurprd06.prod.outlook.com (2a01:111:e400:fc35::4e) by DB8EUR06FT014.mail.protection.outlook.com (2a01:111:e400:fc35::116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Sun, 6 Dec 2020 20:08:00 +0000 Original-Received: from AM0PR06MB6577.eurprd06.prod.outlook.com ([fe80::9487:8c7d:da00:4993]) by AM0PR06MB6577.eurprd06.prod.outlook.com ([fe80::9487:8c7d:da00:4993%7]) with mapi id 15.20.3632.018; Sun, 6 Dec 2020 20:08:00 +0000 Thread-Topic: Expanding list into string within a command Thread-Index: AQHWzAiclv0ED4eTQUy8Fd5bzismgKnqfuyy In-Reply-To: Accept-Language: sv-SE, en-US Content-Language: sv-SE x-incomingtopheadermarker: OriginalChecksum:766AAE6C5E7B0C42AAA200E6CE97BF816140881AA0C9AFD8564F5694D9C7EEC0; UpperCasedChecksum:FBC20CCF73598AD5583DECFA8418E48DF0493DEF6D518BDECD1EFE94B3AC35AF; SizeAsReceived:6849; Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [CVjwKlNwdUXnRFZiyttK3PqBcKJoW1jy] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 85e2078e-c17f-4901-0b77-08d89a22a16e x-ms-traffictypediagnostic: DB8EUR06HT233: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ExrfSZBuEa00PApsn1v+tmAUkp1/Nz8+wquffFz9BUlrKRuEg5uDthIPcP6yTqfh2bxq1lq/1vwYgSxZyJ5qZQsa3P4io1x8YhrR5Rwu8CVVU6aDdv7OGZ1KT1LWwQcNaB1neOdxhYkp5wKrtxCt9R6NKZUVlg8EsMhMg0KZJV/w2tZAQIbAoPkKDBIrW2lOliRj9eHvj51OlJge2+EP8g== x-ms-exchange-antispam-messagedata: Do7DaHD7H+VztO/QfObvjN8K2ELbot8f8P3zWUg5f7i/E23KwST+eOoiDori89fuzCGP62xZsn1SXR+ps6IFd77jA4Fa+8zEhxxz05G5m27KOkSSwIM93B8zB8l33wigMkZ9PhBp+RJhvU7T7UwOmw== x-ms-exchange-transport-forked: True X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DB8EUR06FT014.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 85e2078e-c17f-4901-0b77-08d89a22a16e X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Dec 2020 20:08:00.0047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR06HT233 Received-SPF: pass client-ip=40.92.17.22; envelope-from=arthur.miller@live.com; helo=EUR06-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:126103 Archived-At: Maybe I was too fast, didn't show how to use macroexample: (defmacro with-command (cmdname &rest args) (dolist (arg args) .... do your thing here .... )) Now when you use it : (with-command ls -l -h -s) If you really want to parse those args or do something with them. But I thi= nk it is better to build a string and pass them that way to a command. -------- Originalmeddelande -------- Fr=E5n: Jean Louis Datum: 2020-12-06 20:47 (GMT+01:00) Till: Help GNU Emacs =C4mne: 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=3Dlatlong +datum=3DWGS84 +to +proj=3Dlatlong +datum= =3DWGS84 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=3Dlatlong +da= tum=3DWGS84 +to +proj=3Dlatlong +datum=3DWGS84") 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 fil= e 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=3D last "/") path (concat path "/"))))