From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: the next volume of Berserk Date: Sat, 04 Sep 2021 07:44:20 +0200 Message-ID: <87eea428uj.fsf@zoho.eu> References: <87sfylhtx0.fsf@zoho.eu> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10389"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:lKRwUALGqT2hRU3Pc/KcOWiYH4Y= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 04 07:45:02 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 1mMOUA-0002Si-Gn for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Sep 2021 07:45:02 +0200 Original-Received: from localhost ([::1]:55492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMOU9-0006uD-5d for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Sep 2021 01:45:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMOTh-0006tB-TL for help-gnu-emacs@gnu.org; Sat, 04 Sep 2021 01:44:33 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:37918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMOTg-0007Eq-1R for help-gnu-emacs@gnu.org; Sat, 04 Sep 2021 01:44:33 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mMOTe-0001s3-0Q for help-gnu-emacs@gnu.org; Sat, 04 Sep 2021 07:44:30 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=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:132872 Archived-At: I wrote a better version - I think - by getting away with the string match stuff (almost) and instead unified the retrieval from the ISBN-13 string ... keep it real. ;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; https://dataswamp.org/~incal/emacs-init/bibtex/bibtex-next-volume.el ;;; ;;; uses: ;;; https://dataswamp.org/~incal/emacs-init/bibtex-incal.el ;;; https://dataswamp.org/~incal/emacs-init/isbn-verify.el ;;; ;;; To test, uncomment the below entry (named "berserk-23"), ;;; move point above it, and do ;;; ;;; M-x next-book RET RET RET RET RET RET ;;; ;;; @book{berserk-23, ;;; author = {Kentaro Miura}, ;;; isbn = {978-1-59307-864-5}, ;;; publisher = {Dark Horse}, ;;; title = {Berserk 23}, ;;; year = {2008} ;;; } ;;; ;;; This will insert the following entry, which indeed is the ;;; next book in the series: ;;; ;;; @book{berserk-24, ;;; author = {Kentaro Miura}, ;;; isbn = {978-1-59307-865-2}, ;;; publisher = {Dark Horse}, ;;; title = {Berserk 24}, ;;; year = {2008} ;;; } (require 'cl-lib) (require 'bibtex) (require 'bibtex-incal) (require 'isbn-verify) (defun title-next (title) (when (string-match "\\(.+\\) \\([[:digit:]]+\\)" title) (let*((name (match-string 1 title)) (vol (match-string 2 title)) (vol-next (read-number "Volume: " (1+ (string-to-number vol)))) ) (format "%s %s" name vol-next) ))) ;; (title-next "Berserk 23") ; Berserk 24 (defun isbn-13-bibtex-entry-get-isbn () (let ((isbn-13 (bibtex-autokey-get-field "isbn-13"))) (if (not (string= isbn-13 "")) isbn-13 (let ((isbn (bibtex-autokey-get-field "isbn"))) (unless (string= isbn "") isbn) )))) (defun isbn-13-field (isbn field &optional field-stop) (let*((beg (1- field)) (end (or field-stop field)) (sep "-") (subl (cl-subseq (split-string isbn sep) beg end)) ) (if (= 1 (length subl)) (string-to-number (car subl)) (string-join subl sep) ))) ;; (isbn-13-field "978-1-59307-864-5" 1) ; 978 ;; (isbn-13-field "978-1-59307-864-5" 1 4) ; 978-1-59307-864 (defun isbn-13-publisher (isbn) (let ((publisher (isbn-13-field isbn 3))) (read-number "Publisher: " publisher) )) ;; (isbn-13-publisher "978-1-59307-864-5") ; 59307 (defun isbn-13-publication-next (isbn) (let*((publication (isbn-13-field isbn 4)) (publication-next (1+ publication)) ) (read-number "Publication: " publication-next) )) ;; (isbn-13-publication-next "978-1-59307-864-5") ; 865 (defun isbn-13-next (isbn) (let*((but-last (format "%s-%s-%s" (isbn-13-field isbn 1 2) (isbn-13-publisher isbn) (isbn-13-publication-next isbn) )) (check-digit (read-number "Check digit: " (isbn-verify but-last))) ) (format "%s-%s" but-last check-digit) )) ;; (isbn-13-next "978-1-59307-864-5") ; 978-1-59307-865-2 (defun new-book-next () (interactive) (let ((beg (point))) (when (bibtex-next-entry) (let ((author (bibtex-autokey-get-field "author")) (isbn (isbn-13-bibtex-entry-get-isbn)) (publisher (bibtex-autokey-get-field "publisher")) (title (bibtex-autokey-get-field "title")) (year (string-to-number (bibtex-autokey-get-field "year") ))) (unless (and author isbn publisher title year) (error "Incomplete Bibtex entry") ) (let*((isbn-new (isbn-13-next isbn)) (title-new (title-next title)) (year-new (read-number "Year: " year)) ) (goto-char beg) (create-book author isbn-new publisher title-new year-new) (bibtex-insert-autokey-check-isbn) (goto-char beg) ))))) (defalias 'next-book #'new-book-next) -- underground experts united https://dataswamp.org/~incal