Closed Fuco1 closed 6 years ago
Modified get value to discard the description ::
(maybe make it optional)
(defun org-radio-list-get-value (list-name)
"Return the value of the checked item in a radio list."
(save-excursion
(loop for el in (org-element-property
:structure
(org-get-plain-list list-name))
if (string= (nth 4 el) "[X]")
return (progn
(let ((item (buffer-substring (car el) (car (last el)))))
(string-match "\\[X\\]\\(.* ::\\)?\\(.*\\)$" item)
(match-string 2 item))))))
depends on
(defun get-radio-list-value (list-name)
"Return the value of the checked item in a radio list."
(save-excursion
(loop for el in (org-element-property
:structure
(org-get-plain-list list-name))
if (string= (nth 4 el) "[X]")
return (progn
(let ((item (buffer-substring (car el) (car (last el)))))
(string-match "\\[X\\]\\(.* ::\\)?\\(.*\\)$" item)
(match-string 2 item))))))
Can be probably impemented better using org primitives.
Practical use case
#+attr_org: :radio
#+name: mongo_port
- [ ] localhost :: 27018
- [X] staging b2c :: 27004
- [ ] staging mm :: 27044
#+NAME: query
#+BEGIN_SRC mongo :db db :host 127.0.0.1 :port (org-radio-list-get-value "mongo_port") :exports code
db.getCollection('request-logs').find({
name: 'GetMp',
}).sort({_id: -1}).limit(1)
#+END_SRC
References
implementation
Also add the reference methods to get the picked value, will probably need a bit of work.
Usage