all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: "Felix E. Klee" <felix.klee@inka.de>, help-gnu-emacs@gnu.org
Subject: Re: How to rename files to numbers in Eshell?
Date: Mon, 13 Sep 2021 12:28:24 +0300	[thread overview]
Message-ID: <YT8ZuCvvYevO37V+@protected.localdomain> (raw)
In-Reply-To: <YT5PGpeh3zfTokDC@protected.localdomain>

Dear Felix, maybe you forgot to insert mailing list in your answer.

> Jean Louis <bugs@gnu.support> writes:
> > Is there any regular expression counter replacement so that each new
> > replacement get a new number?

> Example replacement:

>     \,(1+ \#)

> This starts counting at 1.  If you want to start at 0, then simply use:

    \#

That is definitely interesting, please correct me, as I don't get it how to apply it, as following is not working:

(replace-regexp-in-string "ABC" "\#" "ABCM ABCI ABCJ ABCY ABC8")

> > I don't use Bash any more for that, I use Emacs Lisp.

> I'm not convinced so far that Elisp provides any advantage here.
> Elisp scripts look way more wordy.

I have transcribed almost anything I used to do in Bash to Emacs
Lisp. For example image resizing with external `mogrify' 

(defun image-resize (file &optional size)
  "Resizes the JPG image with default size"
  (if (rcd-which-list '("mogrify"))
      (let ((extension (file-name-extension file)))
	(when (or (equal (downcase extension) "jpg")
		  (equal (downcase extension) "png"))
	  (let* ((file (shell-double-quote file))
		 (command (format "mogrify -resize %s \"%s\"" size file)))
	    (message command)
	    (call-process-shell-command command))))
    (rcd-warning-message "RCD ERROR: `mogrify' not found in `$PATH'")))

(defun image-resize-dired ()
  "Resizes images"
  (interactive)
  (let ((files (dired-get-marked-files))
	(size (read-number "Size: " *image-default-resize-size* '*image-resize-sizes*)))
    (while files
      (image-resize (pop files) size))
    (revert-buffer)))

*image-default-resize-size* ⇒ 1536

*image-resize-sizes* ⇒ ("85" "90" "100" "200" "800" "1536" "1024" "640" "2048" 1536 1024 800 1200 640)

Of course anything like that may be written in any programming
language. To me it is very handy to mark few files and resize
them as I spend time with files mostly in Dired, not so much in Bash. 

For example image optimizing which is used for websites mostly I have
used to do with Bash and then I converted it to Emacs Lisp.

(defun optimize-image-jpg (file &optional quality)
  "Optimizes the JPG image with quality 70%"
  (if (rcd-which-list '("mogrify"))
      (let ((extension (file-name-extension file))
	    (quality (or quality "70")))
	(when (string-match "\\(?:\\(?:jpe?\\|pn\\)g\\)" (downcase extension))
	    (message "Optimizing `%s'" file)
	    (call-process "mogrify" nil  "-sampling-factor" "4:2:0" "-strip" "-interlace" "JPEG" "-colorspace" "RGB" "-format" extension "-quality" quality file)
	    (message "Optimizing FINISHED for `%s'" file)))
    (rcd-warning-message "RCD ERROR: `mogrify' not found in $PATH")))

(defun optimize-jpg-images-dired ()
  "Optimizes JPG images inside of Dired"
  (interactive)
  (let ((files (dired-get-marked-files)))
    (while files
      (optimize-image-jpg (pop files)))
    (revert-buffer)))

Of course one could do anything with Bash as main environment, but
just because it is appears so much easier, handy, simpler, more
integrated, I like to do it with Emacs as main environment. 

There are more functions available to Emacs Lisp than to Bash,
re-usability in Emacs Lisp is so much higher.

> > For pictures, I made "sort-images",

> I see you use the file modification time.  Did you consider pulling the
> date from EXIF or other meta data stored within files?

Only if there is prefix argument, I use the function `sort-images' to
sort files which come from camera or phones, those images already have
their creation time in their file names. 

> In my script I use:

>   * `exiftool`: photos
>   * `ffprobe`: videos, audio recordings

That is definitely good option, though it cannot be automated. As Exif
information cannot be trusted easily.

For my own camera pictures they have their date in their names, right?
Their exif information will be correct too, but not as reliable for
the function.

For those pictures coming from other people they may not have any exif
information, or it may be modified Exif information, but they may
still retain the date of the picture in the file name, you see? The
file name of the picture is more authoritative to the name than Exif
in most of cases from my experience.

I guess I would use Exif only when I already inspect bunch of files to
have a correct Exif information.

-- 
Jean

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

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



  reply	other threads:[~2021-09-13  9:28 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 13:15 How to rename files to numbers in Eshell? Felix E. Klee
2021-09-11 13:40 ` Jean Louis
2021-09-12  8:44   ` Felix E. Klee
2021-09-12 19:03     ` Jean Louis
2021-09-13  9:28       ` Jean Louis [this message]
2021-09-13 11:52         ` tomas
2021-09-14  7:42         ` Felix E. Klee
2021-09-14  9:17           ` Jean Louis
2021-09-14  9:32             ` tomas
2021-09-14 11:11             ` Felix E. Klee
2021-09-14 13:37               ` Jean Louis
2021-09-14 15:48                 ` Felix E. Klee
2021-09-16 22:37                   ` Michael Heerdegen
2021-09-16 22:47             ` Michael Heerdegen
2021-09-17  7:27               ` Felix E. Klee
2021-09-24  7:21         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-25 13:43           ` Jean Louis
2021-09-26  2:50             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30  6:38         ` Felix E. Klee
2021-09-30  7:37           ` Jean Louis
2021-09-30  7:50             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30 13:17             ` Felix E. Klee
2021-09-30 15:34               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30 21:42                 ` Jean Louis
2021-10-01  0:09                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-01 20:51                     ` Jean Louis
2021-10-01 21:34                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-02  7:53                         ` Lack of integration in Emacs - it was " Jean Louis
2021-10-03  8:16                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-03  9:27                             ` Jean Louis
2021-10-04  3:29                               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-04 10:15                                 ` Jean Louis
2021-10-04 11:22                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 14:46       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 14:27   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-16 12:15 ` Felix E. Klee
2021-09-16 15:11   ` Nick Dokos
2021-09-16 16:07     ` Felix E. Klee

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YT8ZuCvvYevO37V+@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=felix.klee@inka.de \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.