Skip to content

Instantly share code, notes, and snippets.

@chenyanming
Forked from alphapapa/fitness.org
Created October 4, 2020 04:45
Show Gist options
  • Select an option

  • Save chenyanming/e661865d22d50b172ba5e9e9d7060ed7 to your computer and use it in GitHub Desktop.

Select an option

Save chenyanming/e661865d22d50b172ba5e9e9d7060ed7 to your computer and use it in GitHub Desktop.

Revisions

  1. @alphapapa alphapapa revised this gist Dec 11, 2018. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions org-call-src-block.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    ;; The fitness.org file calls this function to eval the configuration source
    ;; block. This is the only function that needs to be defined outside of
    ;; fitness.org.

    (defun ap/org-call-src-block (name)
    ;; Based on <http://kitchingroup.cheme.cmu.edu/blog/2014/08/11/Using-org-mode-outside-of-Emacs-sort-of/>
    ;; This works better than the org-sbe (aka sbe) macro, because it
    ;; calls the block upon expansion, making it difficult to bind to
    ;; a command to run later
    ;; TODO: Use `org-babel-goto-named-src-block'! I guess it's new...or not, it's from 2010!
    (org-with-wide-buffer
    (-when-let (src (org-element-map (org-element-parse-buffer) 'src-block
    (lambda (element)
    (when (string= name (org-element-property :name element))
    element))
    nil ;info
    t ))
    (goto-char (org-element-property :begin src))
    (let ((org-confirm-babel-evaluate nil))
    (org-babel-execute-src-block)))))
  2. @alphapapa alphapapa revised this gist Dec 10, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fitness.org
    Original file line number Diff line number Diff line change
    @@ -2268,7 +2268,7 @@ I had the idea to check the file with git to see what changes had been made, so

    # ** Process data

    <<process-data>>
    <<process-data>>

    # ** Plot data

  3. @alphapapa alphapapa revised this gist Dec 10, 2018. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions fitness.org
    Original file line number Diff line number Diff line change
    @@ -1772,13 +1772,12 @@ I had the idea to check the file with git to see what changes had been made, so

    #+NAME: plot-data
    #+BEGIN_SRC python :noweb yes
    printerr("SETUP FIGURE") # REMOVE
    <<setup-figure>>

    # *** Plot workouts
    printerr("PLOTTING WORKOUTS") # REMOVE

    <<plot-workouts>>
    printerr("PLOTTED WORKOUTS") # REMOVE

    # *** Plot weight

    combined_frame.Weight.interpolate('time').plot(ax=weight_plot, color=ColorConverter().to_rgba(c.blue, ALPHA), label="_weight")
    @@ -2252,7 +2251,6 @@ I had the idea to check the file with git to see what changes had been made, so

    #+NAME: modular-plotting
    #+BEGIN_SRC python :noweb yes :var WORKOUT_LABELS_FACTOR=plot-num-workout-labels-factor :var WINDOW_WIDTH=(window-pixel-width) :var ALPHA=plot-alpha :var WINDOW=plot-window :var DAYS=plot-days :var workout_data=workout-log :var calorie_goal_data=calorie-goal-log :var calories_burned_data=calories-burned-log :var food_data=food-log :var weight_data=weight-log :var filename="~/org/double-plot.png" :results silent :exports code :tangle yes
    printerr ("DOES THIS EVEN") # REMOVE

    # * Imports

    @@ -2269,8 +2267,8 @@ I had the idea to check the file with git to see what changes had been made, so
    # * main

    # ** Process data
    printerr("PROCESSING DATA") # REMOVE
    <<process-data>>

    <<process-data>>

    # ** Plot data

  4. @alphapapa alphapapa revised this gist Dec 10, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions weight-capture-template.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ;; These go in `org-capture-templates' to capture weight entries.

    ("f" "Fitness")
    ("fw" "Weight" table-line
    (id "7c721aac-eafa-4a42-9354-fbc151402510")
    "| | %U | %^{Weight} | %^{Comment}" :immediate-finish t)
  5. @alphapapa alphapapa revised this gist Dec 10, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fitness.org
    Original file line number Diff line number Diff line change
    @@ -2606,7 +2606,7 @@ I think I can do this with this code that's used for =org-todo-yesterday=:
    : 1.55

    #+NAME: configure-fitness-buffer
    #+BEGIN_SRC emacs-lisp :results none :exports none
    #+BEGIN_SRC emacs-lisp :results none :exports code
    ;;; Requirements

    ;; Requires Org 9.0 now
  6. @alphapapa alphapapa revised this gist Dec 10, 2018. 1 changed file with 0 additions and 131 deletions.
    131 changes: 0 additions & 131 deletions fitness.org
    Original file line number Diff line number Diff line change
    @@ -3350,137 +3350,6 @@ I think I can do this with this code that's used for =org-todo-yesterday=:

    #+END_SRC

    #+BEGIN_SRC elisp
    ;; Experimental

    (defun org-fitness-optimal-day (stat)
    "Return data for optimal day, optimized for STAT."
    (cl-macrolet ((compare-fn (a b)
    `(-lambda ((_ date _ calories protein price _))))))
    (let* ((table-data (--remove (equal 'hline it) (org-with-wide-buffer
    (org-babel-goto-named-result table-name)
    (forward-line 2)
    (org-table-to-lisp))))
    (header (car table-data))
    (date-column-number (--find-index (string= "date" (downcase it)) header))
    (compare-fn (lambda (a b)
    )))))

    ;; I have ABSOLUTELY NO IDEA why this doesn't work. I get a "wrong argument type, sequencep binds" error, but binds is CLEARLY a list. It works fine when I actually insert the list, but when I use the variable, it fails.
    ;; (setq-local binds `(
    ;; ("C-l"
    ;; (helm-org-in-buffer-headings)
    ;; (recenter-top-bottom 1))
    ;; ("C-c C-f"
    ;; (ap/capture-food)
    ;; (org-fitness-call-src-blocks plot-all-in-one))
    ;; ("C-c C-p"
    ;; (org-fitness-call-src-blocks plot-workouts plot-all-in-one))
    ;; ("C-c C-w"
    ;; (ap/capture-workout-data)
    ;; (org-fitness-call-src-blocks plot-workouts))
    ;; ))

    ;; (cl-macrolet ((bind-kli (&rest forms)
    ;; ;; This works because somehow splicing into the
    ;; ;; explicit progn works, even though there's also
    ;; ;; an implicit progn around the explicit progn
    ;; (let ((res (-map
    ;; (-lambda ((key . rest))
    ;; `(local-set-key (kbd ,key)
    ;; (lambda ()
    ;; (interactive)
    ;; ,@rest)))
    ;; forms)))
    ;; `(progn ,@res))))
    ;; (bind-kli binds)
    ;; )

    ;; (cl-flet ((bind-kli (forms)
    ;; ;; This works because somehow splicing into the
    ;; ;; explicit progn works, even though there's also
    ;; ;; an implicit progn around the explicit progn
    ;; (-map
    ;; (-lambda ((key . body))
    ;; (local-set-key (kbd key)
    ;; (lambda ()
    ;; (interactive)
    ;; `,@body)))
    ;; forms)))
    ;; (bind-kli binds))

    ;; (cl-macrolet ((bind (&rest forms)
    ;; ;; This works because somehow splicing into the
    ;; ;; explicit progn works, even though there's also
    ;; ;; an implicit progn around the explicit progn
    ;; (let ((res (-map
    ;; (-lambda ((key plots &key fn)) ; &optional doesn't work, have to use &key
    ;; `(local-set-key (kbd ,key)
    ;; (lambda ()
    ;; (interactive)
    ;; ,(when fn `(call-interactively ',fn))
    ;; (dolist (plot ',plots)
    ;; (ap/org-call-src-block (symbol-name plot)))
    ;; (org-redisplay-inline-images))))
    ;; forms)))
    ;; `(progn ,@res))))
    ;; `(bind ,capture-binds))

    (cl-macrolet ((bind (&rest forms)
    ;; This works because somehow splicing into the
    ;; explicit progn works, even though there's also
    ;; an implicit progn around the explicit progn
    (let ((res (-map
    (-lambda ((key plots &key fn)) ; &optional doesn't work, have to use &key
    `(local-set-key (kbd ,key)
    (lambda ()
    (interactive)
    ,(when fn `(call-interactively ',fn))
    (dolist (plot ',plots)
    (ap/org-call-src-block (symbol-name plot)))
    (org-redisplay-inline-images))))
    forms)))
    `(progn ,@res))))
    (bind
    ("C-c C-f" (plot-all-in-one) :fn ap/capture-food)
    ("C-c C-p" (plot-workouts plot-all-in-one))
    ("C-c C-w" (plot-workouts) :fn ap/capture-workout)
    ))


    (cl-macrolet ((bind (&rest forms)
    ;; Doesn't work, can't figure out how to splice the result of -map into the implicit progn
    (-map (-lambda ((key plots &key fn))
    `(local-set-key (kbd ,key)
    (lambda ()
    (interactive)
    ,(when fn `(call-interactively ',fn))
    (dolist (plot ',plots)
    (ap/org-call-src-block (symbol-name plot)))
    (org-redisplay-inline-images))))
    forms)))
    (bind
    ("C-c C-f" (plot-all-in-one) :fn ap/capture-food)
    ("C-c C-p" (plot-workouts plot-all-in-one))
    ))

    (cl-flet ((bind (&rest forms)
    ;; This works! But I have to quote each list...
    (-map (-lambda ((key plots &key fn))
    (lexical-let ((key key) (plots plots) (fn fn))
    (local-set-key (kbd key) (lambda ()
    (interactive)
    (when fn (call-interactively fn))
    (dolist (plot plots)
    (ap/org-call-src-block plot))
    (org-redisplay-inline-images)))))
    forms)))
    (bind
    '("C-c C-f" (plot-all-in-one) :fn ap/capture-food)
    ))

    #+END_SRC

    # Local Variables:
    # eval: (setq-local org-confirm-babel-evaluate (lambda (lang body) (not (or (string= lang "python") (string= lang "emacs-lisp")))))
    # eval: (ap/org-call-src-block "configure-fitness-buffer")
  7. @alphapapa alphapapa created this gist Dec 10, 2018.
    3,487 changes: 3,487 additions & 0 deletions fitness.org
    3,487 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.