How can I match the values for the keys (org mode attributes) #+label
OR #+name
?
Example: Using get-labels ()
I got fig:foo
. Nice.
How can I get fig:bar
as well?
#+label: fig:foo
#+name: fig:bar
While this one works for #+label
:
(re-search-forward "#\\+label: \\([a-zA-z0-9:-]*\\)" (point-max) t)
This one fails i.e. matches only #+name
:
(re-search-forward "#\\+label:\\|#\\+name: \\([a-zA-z0-9:-]*\\)" (point-max) t)
Used here
(defun get-labels ()
(interactive)
(save-excursion
(goto-char (point-min))
(let ((matches '()))
(while (re-search-forward "#\\+label: \\([a-zA-z0-9:-]*\\)" (point-max) t)
(add-to-list 'matches (match-string-no-properties 1) t))
matches)))
.
# -*- mode: snippet -*-
# --
cref:${1:$$(yas-choose-value (get-labels))} $0
"#\\+label:\\|#\\+name: \\([a-zA-z0-9:-]*\\)"
is either"#\\+label:"
or"#\\+name: \\([a-zA-z0-9:-]*\\)"
. Is that what you meant to match?get-labels()
should returnfig:bar
as well. Currently it only returnsfig:foo
M-x re-builder
and experiment with the various kinds of regexp syntax to get your head around them. Read the regexp sub-sections under(emacs)Search
and test the various things to see how they work. Spending a bit of time doing this should clarify things for you enormously. Also take note of emacs.stackexchange.com/q/5568/454.