1

I'm using org-mode to control some charges, using c++ code to balance. But I have to assign the values by hand. And I would like to assign the values via org properties or some other form of assignment by reference. But I don't know how to make the org data interact with my c++ code. Or do it in a more elegant way. any idea? my code

*  mayo 2022 
** Acario 
   :PROPERTIES:
   :fecha: <2022-05-01 Dom> 
   :empleador: acario
   :horas_all: 9
   :dinero: 80
   :cobrado: no
   :END:

** Acario  
   :PROPERTIES:
   :fecha: <2022-05-07 Sat>
   :empleador: acario
   :horas_all: 8
   :dinero: 60
   :cobrado: no
   :END:
   
** Chiete
   :PROPERTIES: 
   :fecha: <2022-05-08 Sun>
   :empleador: Chiete
   :horas_all: 6.5
   :dinero: 65
   :cobrado: no
   :extra_cobrado: 50
   :END:


#+begin_src C++ :includes <iostream>
  int Pendiente=80+60+65; 
  int Dinero_total=80+60+65+50;
  std::cout<<"Dinero_total Pendiente\n";
  std::cout<<Dinero_total<<"\t";
  std::cout<<Pendiente;
#+end_src  

#+RESULTS:
| Dinero_total | Pendiente |
|          255 |       205 |
0

3 Answers 3

1

You may try something like that:

*  mayo 2022
** Acario
   :PROPERTIES:
   :header-args: :var empleador="acario" dinero=80
   :END:

#+begin_src C++ :includes <iostream>
  std::cout<<empleador<<"\n";
  std::cout<<dinero<<"\n";
#+end_src

#+RESULTS:
| acario |
|     80 |
2

Better to use a named Org table than properties in outline nodes. You then add :var myVarName=myOrgTableName to your source block header. I'm not sure how the table data is passed to a C++ block, probably nested arrays. In Elisp it's nested lists.

3
  • where can i find documentation and examples?
    – Levo
    Commented May 9, 2022 at 17:39
  • Start with the Org manual: (info "(org) Working with Source Code") Commented May 9, 2022 at 18:39
  • 1
    193 / 5.000 Resultados de traducción Finally I decided to use org mode spreadsheets since it is a simple solution and it gives the necessary power, if I had needed more data work, org sql would have been interesting. Formula i found #+TBLFM: $falta_cobrar='(apply #'+ (cl-mapcar (lambda (num sw) (if (eq sw 'no) num 0)) '(@I$5..@II$5) '(@I$6..@II$6)));L :: $ya_cobrado='(apply #'+ (cl-mapcar (lambda (num sw) (if (eq sw 'si) num 0)) '(@I$5..@II$5) '(@I$6..@II$6)));L :: $total_horas=vsum(@I$4..@II$4) :: $total_mes=vsum(@I$5..@II$5)
    – Levo
    Commented May 16, 2022 at 9:07
1

By using pre-processor, I can include anything in anything, independently of the mode.

RCD Template Interpolation System for Emacs:
https://hyperscope.link/3/7/1/3/3/RCD-Template-Interpolation-System-for-Emacs.html

Example file:

* Some details
  :PROPERTIES:
  :AMOUNT:   100.21
  :END:

#+BEGIN_SRC shell
echo ⟦ (string-to-number (car (org-property-values "AMOUNT"))) ⟧
#+END_SRC

#+RESULTS:

example pre-processed result:

* Some details
  :PROPERTIES:
  :AMOUNT:   100.21
  :END:

#+BEGIN_SRC shell
echo 100.21
#+END_SRC

#+RESULTS:
: 100.21

Using the pre-processor would require 2 steps preview, first to preview the buffer, by using M-x rcd-template-buffer-preview and second to run the functions or export Org. It could be integrated into one action automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.