* new auto-version.el package [sneak peek]
@ 2024-07-31 1:58 Emanuel Berg
2024-08-03 22:39 ` Emanuel Berg
0 siblings, 1 reply; 2+ messages in thread
From: Emanuel Berg @ 2024-07-31 1:58 UTC (permalink / raw)
To: emacs-devel
This is going to be the mext project I push to ELPA, I hope!
No Emacs devel on the emacs-devel mailing list - I know - but
I still wanted to show you just once before I do all
documentation and extra stuff. Because now maybe you have some
feature requests and comments that I can implement and have
even in the very first official version!
When I did fun-names.el [1] there was so much updating the
version I got really annoyed by it. Here, with `auto-version'
I can bind that function to the function that saves Elisp
files and have it update automatically.
Sweet!
[1] https://dataswamp.org/~incal/elpa/fun-names.el - or -
git clone https://dataswamp.org/~incal/fun-names.git
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/auto-version.el
;;
;; try it:
;; (progn (insert "a") (delete-char -1) (auto-version))
;;
;; Version: 4.4.15
(require 'cl-lib)
(defun auto-version (&optional yz-max no-save)
(interactive)
(unless yz-max
(setq yz-max 20))
(save-mark-and-excursion
(goto-char (point-min))
(when (and (buffer-modified-p)
(re-search-forward "^;; Version: \\([0-9]+.[0-9]+.[0-9]+\\)$"))
(pcase-let ((`(,x ,y ,z) (version-to-list (match-string 1)) )
( yz-max 20 ))
(when (zerop (mod (cl-incf z) yz-max))
(when (zerop (mod (cl-incf y) yz-max))
(cl-incf x)))
(replace-match (format "%d.%d.%d" x (mod y yz-max) (mod z yz-max))
nil nil nil 1)
(unless no-save
(save-buffer))))))
(provide 'auto-version)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: new auto-version.el package [sneak peek]
2024-07-31 1:58 new auto-version.el package [sneak peek] Emanuel Berg
@ 2024-08-03 22:39 ` Emanuel Berg
0 siblings, 0 replies; 2+ messages in thread
From: Emanuel Berg @ 2024-08-03 22:39 UTC (permalink / raw)
To: emacs-devel
This is also close do done now, possibly.
BTW version 1.9.5 is 585 updates :)
;;; auto-version.el --- automatic x.y.z version -*- lexical-binding: t -*-
;;
;; Author: Emanuel Berg <incal@dataswamp.org>
;; Created: 2024-08-01
;; Keywords: convenience, lisp, tools
;; License: GPL3+
;; URL: https://dataswamp.org/~incal/elpa/auto-version.el
;; Version: 1.9.5
;;
;;; Commentary:
;;
;; __________________________________________________________
;; ^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`
;;
;; auto-version.el -- automatic x.y.z version
;;
;; __________________________________________________________
;; `^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^`^
;;
;; Automatic version number uptick.
;;
;; The version number must look like this:
;;
;; x.y.z
;;
;; To enable in Emacs Lisp buffers:
;;
;; (keymap-set emacs-lisp-mode-map "C-x C-s" #'auto-version-save)
;;
;; See the function `auto-version'.
;;
;; More:
;;
;; `auto-version-save' automate version update on save
;; `aversion--updates' how many updates is a version number?
;;
;; ----------------------------------------------------------
;;
;;; Code:
(require 'cl-lib)
(defun auto-version-save (&rest arg)
"Uptick version and save. See `auto-version'.
ARG are passed on to `save-buffer'."
(interactive "p")
(let ((ups (auto-version)))
(save-buffer arg)
(when ups
(message "Updates: %s" (aversion--updates ups)))))
(let ((yz-max-def 20))
(defun auto-version (&optional yz-max label)
"Uptick the x.y.z version number if present and in a modified buffer.
\ny and z overtick at YZ-MAX, by default 20.
\nLABEL is prepended to the version search string, it defaults
to \"^;; Version: \" in Elisp buffers and otherwise to
\"\\\\W\".
\nAlso see: `auto-version-save'"
(interactive)
(or yz-max (setq yz-max yz-max-def))
(or label (setq label (if (eq major-mode 'emacs-lisp-mode)
"^;; Version: "
"\\W")))
(when (buffer-modified-p)
(save-mark-and-excursion
(goto-char (point-min))
(when (re-search-forward
(format "%s\\([0-9]+.[0-9]+.[0-9]+\\)\\b" label)
nil t)
(pcase-let ((`(,x ,y ,z) (version-to-list (match-string 1))))
(when (zerop (setq z (mod (cl-incf z) yz-max)))
(when (zerop (setq y (mod (cl-incf y) yz-max)))
(cl-incf x)))
(let ((ver (format "%d.%d.%d" x y z)))
(replace-match ver nil nil nil 1)
ver))))))
(defun aversion--updates (ver &optional overtick)
"Translate VER into the number of updates it represents.
Overtick is OVERTICK for y and z. [default 20]
\nFor example, version 0.0.1 is the first update or update number 1;
meanwhile version 7.4.19 is already at update number 2899!
\n(+ (* 7 (expt 20 2)) (* 4 (expt 20 1)) (* 19 (expt 20 0)))"
(interactive (list
(read-string "Version: ")
(read-number "Overtick: " yz-max-def)))
(or overtick (setq overtick yz-max-def))
(let* ((vel (version-to-list ver)))
(cl-loop
with ups = 0
for i downfrom (1- (length vel))
for d in vel do
(cl-incf ups (* d (expt overtick i)))
finally return ups)))
(declare-function auto-version nil)
(declare-function aversion--updates nil))
(provide 'auto-version)
;;; auto-version.el ends here
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-03 22:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-31 1:58 new auto-version.el package [sneak peek] Emanuel Berg
2024-08-03 22:39 ` Emanuel Berg
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).