From: Jean Louis <bugs@gnu.support>
To: Eli Zaretskii <eliz@gnu.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Maybe we can improve this function call-process-to-string?
Date: Thu, 8 Apr 2021 18:56:30 +0300 [thread overview]
Message-ID: <YG8nrnLoDW8fneI7@protected.localdomain> (raw)
In-Reply-To: <831rbkao9z.fsf@gnu.org>
* Eli Zaretskii <eliz@gnu.org> [2021-04-08 16:40]:
> > Date: Thu, 8 Apr 2021 14:53:18 +0300
> > From: Jean Louis <bugs@gnu.support>
> > 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
next prev parent reply other threads:[~2021-04-08 15:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-08 7:40 Maybe we can improve this function call-process-to-string? Jean Louis
2021-04-08 7:55 ` Eli Zaretskii
2021-04-08 11:53 ` Jean Louis
2021-04-08 13:39 ` Eli Zaretskii
2021-04-08 15:56 ` Jean Louis [this message]
2021-04-08 16:25 ` Eli Zaretskii
2021-04-08 18:17 ` Jean Louis
2021-04-08 18:36 ` Eli Zaretskii
2021-04-08 18:44 ` Jean Louis
2021-04-08 17:18 ` Arthur Miller
2021-04-08 18:32 ` Jean Louis
2021-04-08 19:41 ` Arthur Miller
2021-04-09 8:52 ` Jean Louis
2021-04-09 10:07 ` tomas
2021-04-08 13:08 ` Michael Albinus
2021-04-08 15:50 ` Jean Louis
2021-04-08 17:49 ` Stefan Monnier
2021-04-08 18:33 ` Jean Louis
2021-04-08 18:40 ` 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=YG8nrnLoDW8fneI7@protected.localdomain \
--to=bugs@gnu.support \
--cc=eliz@gnu.org \
--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).