From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EJ4FKat3FmGdNgAAgWs5BA (envelope-from ) for ; Fri, 13 Aug 2021 15:46:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 4EEEJat3FmFJXAAA1q6Kng (envelope-from ) for ; Fri, 13 Aug 2021 13:46:19 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CE3938DFA for ; Fri, 13 Aug 2021 15:46:18 +0200 (CEST) Received: from localhost ([::1]:39156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEXVp-00011T-R9 for larch@yhetil.org; Fri, 13 Aug 2021 09:46:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEXUt-000101-On for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 09:45:22 -0400 Received: from mout01.posteo.de ([185.67.36.65]:50735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEXUp-0006dH-6M for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 09:45:19 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id EB947240029 for ; Fri, 13 Aug 2021 15:45:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1628862305; bh=oR1HiKNWJvm27Z2Nl+4dkNg4yMrotriF4C+/QgAUtIE=; h=From:To:Subject:Date:From; b=cSvmqRO5N5NNXTXFJCZ1nEDFMZMKlpBqWcMGbXzDMdQ9Lzso8pLEnlmE7VQIiQMNF 4dOR+DwqRnB31vf4oWU2XaSpwcHdc/Z+gwqsDSnfQJBd3QtzTJafCOvo8U5cevbB5i g9+MrYJavkKw3hISYnhExziMwPbtLdSOU58TCELpiPn6fxv0n8tnSdHUl21E/Y8Vz/ gjw9S8k660mqHkL4IndWaNJfwxdRrBOTopI8v0hP3yUKjywT1l3lr5FVyofsz3IjuN 5r38fG7MAiRM+ZcfHam/3vdPURT2/0H/UKRYi3b5Bs2z5pk9yhKTzZpp+vY1DZ9wOu gA6zJ6yJVbqrw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GmPv43y8jz9rxK for ; Fri, 13 Aug 2021 15:45:04 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [tip] get the verse number at point inside a verse block Date: Fri, 13 Aug 2021 13:45:03 +0000 Message-ID: <87h7ftihls.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1628862379; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=dVgF+iePpU+td46iMCs4bEyO9uLGN6bvvrHtfdiEsVk=; b=ngWFC4xebzkvslxDBy8NPMGkuCFKLepQlYDX3eGeMc868JQ7SVBJnkjKptfJ+9q5N2B8E+ 8I0Re3FFq/oomF08L35hi5cHlvlL0IQJ60dqslKMr1w9VLuuHXOGrppvnzvAXFfQRYsEBp 4zzs4jk8UtPsnGiCyL9EFi/NJgv/NflU/5LWG8qn41rb9R5W/iEW9tXwrSATSyDu0dNrMZ IfuRHYd5ui1LyCIctAFG7DMSJNJ8lX0Ebs8zo0O3IDWx7+y1lCCOdAZbpsklnjOD0oVm9d yfytLJfMSAG72C6Qhvi37rKSTMYWgVzQh/RirdNztwz2IHBh8fzhXkml+k4vPg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628862379; a=rsa-sha256; cv=none; b=Cqdft5/OxwNcjwo1E0tPPnd+iOI4vejSqe1qARVbAay+3gkD5FIqjOUQ2cOxI0Xkhe+Qk+ WlADAxpUJp/pd22w5M+bjYr1bdCcRPiAZYLFKTKoNz5NMg0RyCdMVoWl0thhCbWvbR3dOw K8lm2J0z78IccDxcg5n0aDJ6pcjK1UwgzZjr9RyKNf59hNndp1GdfDKTKMo8M71fBC8yOa ttRHRnaZKOIvKlZnVHZLet4hFfk4iRCZQsOr8IpokCnzYRD2TmiobTyoNbc413Ldk63Kra qus8VJ7orJa4CtY3AnqxeJfWBUOFQAExgv2rcPmIitiR0JYGd/xnxKn6SKgf9Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cSvmqRO5; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -3.11 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cSvmqRO5; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: CE3938DFA X-Spam-Score: -3.11 X-Migadu-Scanner: scn0.migadu.com X-TUID: dgqBfVjiVGTH Hi, We're highly unlikely to feel in our life the strange need to know the verse number at point within a verse block (verse numbers are not equal to line numbers). However, in my translation of Homer's Odyssey (work in progress), I often need to get (at point) both the verse number and the book number, so that it can be canonically cited in many references I include in the prologue and footnotes. For example: Od. 2.125 (book + verse). So I wrote this little code: First, you get the verse number at point: #+begin_src emacs-lisp (defun verse-num-at-point () "Return the verse number at point inside a `verse' block" (save-excursion (end-of-line) (save-restriction (org-narrow-to-block) (narrow-to-region (point-min) (point)) (goto-char (point-min)) (end-of-line) (let ((versenum 0)) (save-excursion (while (re-search-forward "^." nil t) (setf versenum (+ versenum 1))) (setq verse-at-point versenum))))) verse-at-point) #+end_src And, with this function, you get the canonical citation (taking into account that book number is a property named `:book:'): #+begin_src emacs-lisp (defun locate-odyssey () (interactive) (let ((book (org-entry-get nil "book")) (verse (verse-num-at-point))) (message "Od. %s.%s" book verse) (kill-new (format "Od. %s.%s" book verse)))) #+end_src Bonus track: I also wrote this little package to display verse numbers at margin: https://gitlab.com/maciaschain/org-verse-num Best regards, Juan Manuel