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: Re: Maybe we can improve this function call-process-to-string? Date: Thu, 8 Apr 2021 18:56:30 +0300 Message-ID: References: <83a6q99pnd.fsf@gnu.org> <831rbkao9z.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34672"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 08 18:08:40 2021 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 1lUXCx-0008vd-Q8 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 08 Apr 2021 18:08:39 +0200 Original-Received: from localhost ([::1]:57882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUXCw-0003YX-QA for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 08 Apr 2021 12:08:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUX59-00045x-CY for help-gnu-emacs@gnu.org; Thu, 08 Apr 2021 12:00:35 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:33113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUX55-0007cX-5L; Thu, 08 Apr 2021 12:00:34 -0400 Original-Received: from localhost ([::ffff:41.202.241.27]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001DF46.00000000606F289B.00000179; Thu, 08 Apr 2021 09:00:27 -0700 Mail-Followup-To: Eli Zaretskii , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <831rbkao9z.fsf@gnu.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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:128901 Archived-At: * Eli Zaretskii [2021-04-08 16:40]: > > Date: Thu, 8 Apr 2021 14:53:18 +0300 > > From: Jean Louis > > Cc: help-gnu-emacs@gnu.org > > > > > In general, one should avoid strings in Emacs Lisp, because buffer > > > memory is handled much more efficiently than string memory. > > > > I understand the concept, not at all how to practically run a system > > command and receive it as a string. > > Why do you need a string? The string is a means to an end, right? > What is that end? Hahaha, I am not sure if you are joking, but of course string is a mean to an end... funny. Now, I need it for example, to get widht and height from a image by using system command `identify', sometimes I will extract GPS coordinate from an image, so I call system commands from Emacs Lisp that processes bunch of images. For example, to quickly construct a Markdown hyperlink to the image below, I enter the Dired and do M-x md-image-hyperlink /home/data1/protected/public_html/gnu.support/images/1536: total used in directory 304K available 42.4 GiB -rw-r--r-- 1 173K Oct 8 2016 2016-10-08-23:12:44.jpg -rw-r--r-- 1 125K Mar 18 2017 gnu-head-large.jpg With this result: [![https://gnu.support/images/1536/gnu-head-large.jpg](https://gnu.support/images/1536/gnu-head-large.jpg =1536x1024 "https://gnu.support/images/1536/gnu-head-large.jpg")](https://gnu.support/images/1536/gnu-head-large.jpg "https://gnu.support/images/1536/gnu-head-large.jpg") That is where `shell-command-to-string' comes handy, and HTML pages meant for Discount flavor of markdown can be generated. (defun md-image-hyperlink () (interactive) (let ((files (dired-get-marked-files)) (list '())) (dolist (file files) (let* ((small-image (public-html-rest file)) (large-image (replace-regexp-in-string "/320/\\|/400/\\|/640/\\|/800/" "/1536/" small-image)) (command (format "identify -format '[![%s](%s =%%wx%%h \"%s\")](%s \"%s\")' '%s'" small-image small-image small-image large-image large-image file))) (message "%s" command) (push (shell-command-to-string command) list))) (kill-new (with-temp-buffer (dolist (item list) (insert item)) (buffer-string))))) > > Because none of `buffer-substring' nor `buffer-string' can specify the > > buffer name then I have to switch temporarily to other buffer, get > > string with `buffer-string' and return back. I was thinking there is > > some function doing that straight, like (buffer-string BUFFER), but I > > don't find such. > > I suggest to look up with-current-buffer and with-temp-buffer. I would not know how to get output from system command by using those functions without using shell-command-to-string or call-process Jean