From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [tip] get the verse number at point inside a verse block
Date: Fri, 13 Aug 2021 13:45:03 +0000 [thread overview]
Message-ID: <87h7ftihls.fsf@posteo.net> (raw)
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
reply other threads:[~2021-08-13 13:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h7ftihls.fsf@posteo.net \
--to=maciaschain@posteo.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).