[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 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [tip] get the verse number at point inside a verse block,
Juan Manuel Macías <=