[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tip] get the verse number at point inside a verse block

From: Juan Manuel Macías
Subject: [tip] get the verse number at point inside a verse block
Date: Fri, 13 Aug 2021 13:45:03 +0000


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"
      (narrow-to-region (point-min) (point))
      (goto-char (point-min))
          ((versenum 0))
              (re-search-forward "^." nil t)
            (setf versenum (+ versenum 1)))
          (setq verse-at-point versenum)))))

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 ()
  (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))))

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]