zkry / yaml-pro

Edit YAML in Emacs like a pro
GNU General Public License v3.0
137 stars 9 forks source link

[feature request] Jump to an existing field given its outline path #29

Open rodrigomorales1 opened 11 months ago

rodrigomorales1 commented 11 months ago

In Org Mode, it is possible to jump to a given headline by speciying its outline. See minimal working example below.

(with-temp-buffer
  (org-mode)
  (insert
   (concat
    "* 1\n"
    "* 2\n"
    "** 2.1\n"
    "*** 2.1.1\n"
    "*** 2.1.2\n"
    "* 3\n"))
  (goto-char (point-min))
  (goto-char (org-find-olp '("2" "2.1" "2.1.1") t))
  (thing-at-point 'line t))
*** 2.1.1

Given the similarity between YAML and Org Mode documents, I believe that such function would come in handy when editing YAML files.

The function could be called yaml-find-olp and it would work the same way as org-find-olp. Consider the YAML document shown below, after executing (yaml-find-olp '("2" "2.1" "2.1.1") t), the point would be at <point>.

1:
2:
  2.1:
    2.1.1:
    2.1.2: <point>

The function would also complain when there are two fields with the same outline path just as org-find-olp does (see minimal working example below).

(with-temp-buffer
  (org-mode)
  (insert
   (concat
    "* 1\n"
    "* 2\n"
    "** 2.1\n"
    "*** 2.1.1\n"
    "*** 2.1.1\n"
    "* 3\n"))
  (goto-char (point-min))
  (condition-case err
      (org-find-olp '("2" "2.1" "2.1.1") t)
    ('error (error-message-string err))))
Heading not unique on level 3: 2.1.1
zkry commented 7 months ago

Looks like this could be worked on in tandem with #30.

So imenu is set up to work properly so it can kind of give you a similar experience if your workflow is interactive. With something like the "orderless" package it works really nice. Though this isn't really useful for elisp programs which is what I'm guessing your use-case is.