An approach to parsing Org files: a state-machine inside of rg
?
#3013
-
Thanks for dropping by r/emacs recently. I wonder if I could indulge you with a day-dream about The basic
It's easy for
or similar. This of course would require some simple state machine living inside of the What's the craz-o-meter reading here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
For reference, my "state machine" is a list updated each time it lands upon a new heading. Just a data point showing it works to do things this way. ;; CRUMBS is a list that can look like
;; ((3 "Heading" "id1234" ("noexport" "work" "urgent"))
;; (2 "Another heading" "id6532" ("work"))
;; (... ... ... ...))
;; if the previous heading looked like
;; *** Heading :noexport:work:urgent:
;; :PROPERTIES:
;; :ID: id1234
;; :END:
;; It lets us track context so we know the outline path to the
;; current entry and what tags it should be able to inherit.
;; Update the list.
(cl-loop until (> LEVEL (or (caar CRUMBS) 0))
do (pop CRUMBS)
finally do
(push (list LEVEL TITLE ID HERITABLE-TAGS)
CRUMBS)) Another piece of state you might want is the top-level setting A thornier issue might be that it's not uncommon to want to your search to skip some areas, like between a @jdtsmith I wonder if you had in mind a more programmatic use, or if nested heading would also be useful for on-the-spot interactive search? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the question! I don't see any obvious way of doing what you want easily with ripgrep. The closest thing ripgrep has to something like this are the The only structure in files that ripgrep understands is lines. That is partially why it (and other tools, like GNU grep) can be as fast as they are. It is a feature that ripgrep doesn't try to understand anything more, because that winds up making the pre-processing step before searching very expensive. In contrasts, lines are a very lightweight structure that ripgrep can actually mostly "ignore" up-front, and then patch back together later. |
Beta Was this translation helpful? Give feedback.
Thanks for the question!
I don't see any obvious way of doing what you want easily with ripgrep. The closest thing ripgrep has to something like this are the
--before-context
and--after-context
flags, but they only accept fixed integer values.The only structure in files that ripgrep understands is lines. That is partially why it (and other tools, like GNU grep) can be as fast as they are. It is a feature that ripgrep doesn't try to understand anything more, because that winds up making the pre-processing step before searching very expensive. In contrasts, lines are a very lightweight structure that ripgrep can actually mostly "ignore" up-front, and then patch back together later.