emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [tip] get the verse number at point inside a verse block
@ 2021-08-13 13:45 Juan Manuel Macías
  0 siblings, 0 replies; only message in thread
From: Juan Manuel Macías @ 2021-08-13 13:45 UTC (permalink / raw)
  To: orgmode

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-13 13:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 13:45 [tip] get the verse number at point inside a verse block Juan Manuel Macías

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).