From 4d33a90680c3d187d5c79a88a597b57f20e67697 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 23 Apr 2023 19:14:14 +0100 Subject: Fix 9 turning into colon --- content.org | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/content.org b/content.org index 701732b..6b7aa29 100644 --- a/content.org +++ b/content.org @@ -475,20 +475,19 @@ ID, and one which will branch off of the current ID and create a parallel one. first create a simple =ymhg/incr-id= function which simply increments the last character of the ID. #+begin_src emacs-lisp - (defun ymhg/incr-id (ident) - (let* ((ident-list (append nil ident nil)) - (last-ident (last ident-list))) - (setcar last-ident (+ (car last-ident) 1)) - (concat ident-list))) + (defun ymhg/incr-id (ident) + (let ((ident-list (string-to-list ident))) + (cl-incf (car (last ident-list))) + (concat ident-list))) #+end_src -However, one problem is that if we get to an ID with a =9= at the end, it will wrap around and -generate a =0= at the end, followed by then generating an =:=, which will break the naming scheme. This -could simply be fixed by turning the last value of the ID into a number, incrementing that, and -turning it back into the original representation. However, for the current purposes we'll just -assume that manual intervention will be required sometimes. Then, to create the function that -generates an ID branching off of the current one, we just have to check if the current id ends with -a number or a character, and add a =a= or =1= accordingly. +However, one problem is that if we get to an ID with a =9=, it will stop incrementing correctly and +turn into a =:=, which will break the naming scheme. This could simply be fixed by turning the last +value of the ID into a number, incrementing that, then turning it back into the original +representation. However, for the current purpose we'll just assume that manual intervention will be +required sometimes. Then, to create the function that generates an ID branching off of the current +one, we just have to check if the current id ends with a number or a character, and add a =a= or =1= +accordingly. #+begin_src emacs-lisp (defun ymhg/branch-id (ident) -- cgit