help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to rename files to numbers in Eshell?


From: Jean Louis
Subject: Re: How to rename files to numbers in Eshell?
Date: Fri, 1 Oct 2021 00:42:31 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2021-09-30 18:48]:
> Felix E. Klee wrote:
> 
> >> Pipes may be replaced by buffers, capturing information in
> >> a buffer and processing it thereafter.
> >
> > ... which makes it super slow
> 
> But Jean is re-writing all his Bash to Elisp so he surely has
> a lot of time :)

Or maybe there is not much of Bash as my "Bash" scripts were mostly
Common Lisp, Perl, etc.

> No, seriously, Jean, while in general I absolutely cannot
> understand this idea or see the benefits, I'm sure there are
> many cases where a Lisp solution (Elisp solution from Emacs)
> is as good or even better - so when you stumble upon those
> cases in your translating efforts, by all means do show it
> to us!

I guess that is hard to believe as you are in Emacs Lisp mailing list,
it is hard to believe you cannot understand the idea of using Emacs
Lisp, you who has hundreds of Emacs Lisp scripts.

Bash is different environment to Emacs, when person works in one
environment then person tends to integrate missing peaces. Would I
work in Racket, I would most probably rewrite it all to Racket.

> Post the code here as you do, it is appreciated despite my
> style issues with your code ...

I care only if it works.

Here are few examples that invoke `yad' dialog generator from Emacs.

(defun call-process-to-string (program &optional infile display &rest args)
  (with-temp-buffer
    (apply #'call-process program infile t display args)
    (buffer-string)))

(defun rcd-command-output-from-input (program input &rest args)
  "Return output string from PROGRAM with given INPUT string and optional ARGS."
  (let* ((output (with-temp-buffer
                   (insert input)
                   (apply #'call-process-region nil nil program t t nil args)
                   (buffer-string))))
    output))


;;;; ↝ YAD DIALOGS

(defun yad-command (&rest args)
  (apply 'call-process "yad" nil nil nil args))

(defun yad-calendar-date ()
  (string-trim
   (call-process-to-string "yad" nil nil "--calendar" "--center" 
"--date-format=%Y-%m-%d")))

(defun yad-text (title text body &optional center no-buttons text-align width 
height)
  "TEXT-ALIGN can be left, center, right and full."
  (let* ((center (when center "--center"))
         (text-align (when text-align text-align))
         (no-buttons (when no-buttons "--no-buttons"))
         (width (when width (format "--width=%s" width)))
         (height (when height (format "--height=%s" height)))
         (list (delq nil (list center text-align no-buttons width height))))
    (apply 'rcd-command-output-from-input "yad" body "--text-info" "--title" 
title "--text" text "--fontname=DejaVu 18" list)))


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]