all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: help-gnu-emacs@gnu.org
Subject: Re: enum.el
Date: Sun, 15 Jan 2023 21:52:24 +0300	[thread overview]
Message-ID: <Y8RLaIixVZ0tnTlP@protected.localdomain> (raw)
In-Reply-To: <87fscdmqbo.fsf@dataswamp.org>

* Emanuel Berg <incal@dataswamp.org> [2023-01-15 15:42]:
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;;   https://dataswamp.org/~incal/emacs-init/enum.el
> 
> (require 'cl-lib)
> (require 'subr-x)
> 
> (defun enum (&optional beg end suf)
>   "Enumerate each line from BEG to END, counting from one.
> Use SUF as a suffix to the digits inserted.
> BEG defaults to the beginning of the buffer,
> END defaults to the end of the buffer,
> SUF defaults to \". \""
>   (interactive
>    `(,@(if (use-region-p)
>            (list (region-beginning) (region-end))
>          (list nil nil) )
>      ,(when current-prefix-arg
>         (read-string "suffix: ") )))
>   (or beg (setq beg (point-min)))
>   (or end (setq end (point-max)))
>   (or suf (setq suf ". "))
>   (goto-char beg)
>   (let*((lines   (count-lines beg end))
>         (pad-len (length (number-to-string lines))) )
>     (cl-loop
>       for line from 1 to lines
>       do (goto-char (line-beginning-position))
>          (insert
>            (format "%s%s"
>                    (string-pad (number-to-string line) pad-len nil t) suf) )
>          (forward-line) )))

Looks sophisticated.

When there is bunch of pictures in Dired, freshly downloaded, then I
sometimes need to enumerate such files.

(defun renumber-files (&optional files)
  "This function works within Dired or Directory Editor in GNU
  Emacs. It will rename bunch of files and renumber them
  automatically by date and number of the file. It is useful when
  you are renaming less important images or bunch of files with
  irrelevant file names."
  (interactive)
  (let* ((files (or files (dired-get-marked-files)))
	 (count 1))
    (dolist (file files)
      (let* ((extension (file-name-extension file))
	     (filename (format "%s-%06.f.%s" (format-time-string "%F") count extension)))
	(rename-file file filename)
	(setq count (+ count 1))))))

-- 
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:[~2023-01-15 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14  9:13 enum.el Emanuel Berg
2023-01-15 18:52 ` Jean Louis [this message]

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=Y8RLaIixVZ0tnTlP@protected.localdomain \
    --to=bugs@gnu.support \
    --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.