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: How to rename files to numbers in Eshell? Date: Mon, 13 Sep 2021 12:28:24 +0300 Message-ID: References: <87tuirckxp.fsf@inka.de> <87ee9u2neh.fsf@inka.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34217"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) To: "Felix E. Klee" , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 13 11:31:03 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 1mPiIp-0008jU-SD for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Sep 2021 11:31:03 +0200 Original-Received: from localhost ([::1]:54820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPiIn-0000Zl-Q7 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Sep 2021 05:31:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPiHw-0000ZN-M7 for help-gnu-emacs@gnu.org; Mon, 13 Sep 2021 05:30:08 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:44033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPiHu-0006OA-LE for help-gnu-emacs@gnu.org; Mon, 13 Sep 2021 05:30:08 -0400 Original-Received: from localhost ([::ffff:197.157.0.42]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000027ED2.00000000613F1A1A.000064BD; Mon, 13 Sep 2021 02:30:02 -0700 Mail-Followup-To: "Felix E. Klee" , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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:133021 Archived-At: Dear Felix, maybe you forgot to insert mailing list in your answer. > Jean Louis 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/