emacs-orgmode
[Top][All Lists]
Advanced

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

Search in descriptive plain lists


From: Juan Manuel Macías
Subject: Search in descriptive plain lists
Date: Thu, 19 Aug 2021 11:04:01 +0000

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 via email to

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