emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: Search in descriptive plain lists
Date: Thu, 19 Aug 2021 11:04:01 +0000	[thread overview]
Message-ID: <87bl5tzof2.fsf@posteo.net> (raw)

Hi all,

For my translation (work in progress) of Homer's Odyssey I am writing a long descriptive
plain list which is a glossary of Homeric formulas (in Homer a 'formula' is a passage that
is repeated exactly the same, or with slight variations, throughout the work: a very
typical resource of traditional poems). This glossary helps me remember how I have
translated a certain formula before. But it was a bit awkward for me having to query the
list every time so I wrote a function which returns as a message the item searched after
writing or marking a few words. I have redone a bit the code to give it a more general
use, and I share it here, in case someone found useful or perhaps would like to improve
it. The idea is to search in descriptive lists within sections containing the tag :makealist:
(one list per section). And has more sense when the descriptive lists work as a kind of
glossary.

#+begin_src emacs-lisp
  (setq my-org/desc-plainlist-alist nil)
  
  (defun my-org/search-desc-plainlist ()
    (interactive)
    (org-map-entries
     (lambda ()
       (save-restriction
	 (org-narrow-to-subtree)
	 (when
	     (re-search-forward "^- " nil t)
	   (beginning-of-line)
	   (mapc (lambda (el)
		   (add-to-list 'my-org/desc-plainlist-alist el))
		 (cdr (org-list-to-lisp))))))
     "makealist")
    (let ((element-re (if (region-active-p)
			  (buffer-substring-no-properties (region-beginning) (region-end))
			(read-from-minibuffer "Search in descriptive lists: "))))
      (setq my-org/desc-plainlist-candidate
	    (assoc-if
	     (lambda (x)
	       (string-match-p element-re x))
	     my-org/desc-plainlist-alist))
      (message
       (mapconcat 'identity
		  my-org/desc-plainlist-candidate ""))))
#+end_src

Best regards,

Juan Manuel 


                 reply	other threads:[~2021-08-19 11:05 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=87bl5tzof2.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: Search in descriptive plain lists' \
    /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

Code repositories for project(s) associated with this 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 NNTP newsgroup(s).