<commit_before>(require 'org-element)
(require 'ar-ox-html)
(require 'f)
(require 's)

(defun ar/org-split-export-async ()
  (interactive)
  (async-shell-command (concat (expand-file-name invocation-name invocation-directory)
                               " --batch -Q"
                               " -l "(expand-file-name "~/.emacs.d/ar/ar-org-export-init.el")
                               " --execute '(ar/org-split-export)'")
                       "*org html export*"))

(defun ar/org-split-export ()
  (with-current-buffer (find-file-noselect (expand-file-name
                                            "~/stuff/active/blog/index.org"))
    (org-element-map (org-element-parse-buffer 'headline)
        'headline
      (lambda (headline)
        (when (org-element-property :CUSTOM_ID headline)
          (ar/org-split-export-headline (expand-file-name "~/stuff/active/blog/index.org")
                                        (ar/org-split-export--parse-headline-title
                                         (org-element-property :raw-value headline))
                                        (org-element-property :CUSTOM_ID headline)
                                        (org-element-property :begin headline))
          ;; Adding a sleep prevents error: "Creating pipe: Too many open files".
          (sleep-for 0.1))))))

(defun ar/org-split-export--parse-headline-title (headline)
  ;; For example:
  ;; [2019-03-30 Sat] Reading spreadsheets with python/pandas
  ;; => Reading spreadsheets with python/pandas
  (let ((match (s-match (rx "[" (= 4 num) "-"(= 2 num) "-" (= 2 num) (= 1 blank)
                            (or "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
                            "]"
                            (= 1 blank)
                            (group (one-or-more anything)))
                        headline)))
    (when (> (length match)
             1)
      (nth 1 match))))

(defun ar/org-html-link--postprocess (orig-fun &rest r)
  (let ((html-link (apply orig-fun r)))
    ;; Massage href from:
    ;; <a href=\"index.html#ID-trying-out-tesseract\"></a>
    ;; to:
    ;; <a href=\"../trying-out-tesseract\"></a>
    (setq html-link (s-replace-regexp "href=\\\"\\(.*#ID-\\)" "../"
                                      html-link nil nil 1))
    ;; Massage image from:
    ;; <img src=\"images/inserting-numbers-with-emacs-multiple-cursors/mc-number.gif\"></img>
    ;; to:
    ;; <img src=\"../images/inserting-numbers-with-emacs-multiple-cursors/mc-number.gif\"></img>
    (setq html-link (s-replace-regexp "src=\\\"\\(images\\)" "../images"
                                      html-link nil nil 1))
    html-link))

(defun ar/org-export--collect-tree-properties--postprocess (orig-fun &rest r)
  (save-excursion
    (save-restriction
      (widen)
      (org-combine-plists (apply orig-fun r)
                          `(:id-alist ,(org-element-map (org-element-parse-buffer 'headline)
                                           'headline
                                         (lambda (headline)
                                           (cons (org-element-property :CUSTOM_ID headline) "index.org"))))))))


(defun ar/org-export-current-headline-async ()
  (interactive)
  (let ((headline (ar/org-element-at-heading-1)))
    (assert (eq major-mode 'org-mode))
    (async-shell-command (concat (expand-file-name invocation-name invocation-directory)
                                 " --batch -Q"
                                 " -l "(expand-file-name "~/.emacs.d/ar/ar-org-export-init.el")
                                 (format " --execute '(ar/org-split-export-headline \"%s\" \"%s\" \"%s\" %d t)'"
                                         (expand-file-name "~/stuff/active/blog/index.org")
                                         (ar/org-split-export--parse-headline-title
                                          (org-element-property :raw-value headline))
                                         (org-element-property :CUSTOM_ID headline)
                                         (org-element-property :begin headline)))
                         "*org html export*")))
<commit_msg>Adding synchronous ar/org-export-current-headline<commit_after>(require 'org-element)
(require 'ar-ox-html)
(require 'f)
(require 's)

(defun ar/org-split-export-async ()
  (interactive)
  (async-shell-command (concat (expand-file-name invocation-name invocation-directory)
                               " --batch -Q"
                               " -l "(expand-file-name "~/.emacs.d/ar/ar-org-export-init.el")
                               " --execute '(ar/org-split-export)'")
                       "*org html export*"))

(defun ar/org-split-export ()
  (with-current-buffer (find-file-noselect (expand-file-name
                                            "~/stuff/active/blog/index.org"))
    (org-element-map (org-element-parse-buffer 'headline)
        'headline
      (lambda (headline)
        (when (org-element-property :CUSTOM_ID headline)
          (ar/org-split-export-headline (expand-file-name "~/stuff/active/blog/index.org")
                                        (ar/org-split-export--parse-headline-title
                                         (org-element-property :raw-value headline))
                                        (org-element-property :CUSTOM_ID headline)
                                        (org-element-property :begin headline))
          ;; Adding a sleep prevents error: "Creating pipe: Too many open files".
          (sleep-for 0.1))))))

(defun ar/org-split-export--parse-headline-title (headline)
  ;; For example:
  ;; [2019-03-30 Sat] Reading spreadsheets with python/pandas
  ;; => Reading spreadsheets with python/pandas
  (let ((match (s-match (rx "[" (= 4 num) "-"(= 2 num) "-" (= 2 num) (= 1 blank)
                            (or "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
                            "]"
                            (= 1 blank)
                            (group (one-or-more anything)))
                        headline)))
    (when (> (length match)
             1)
      (nth 1 match))))

(defun ar/org-html-link--postprocess (orig-fun &rest r)
  (let ((html-link (apply orig-fun r)))
    ;; Massage href from:
    ;; <a href=\"index.html#ID-trying-out-tesseract\"></a>
    ;; to:
    ;; <a href=\"../trying-out-tesseract\"></a>
    (setq html-link (s-replace-regexp "href=\\\"\\(.*#ID-\\)" "../"
                                      html-link nil nil 1))
    ;; Massage image from:
    ;; <img src=\"images/inserting-numbers-with-emacs-multiple-cursors/mc-number.gif\"></img>
    ;; to:
    ;; <img src=\"../images/inserting-numbers-with-emacs-multiple-cursors/mc-number.gif\"></img>
    (setq html-link (s-replace-regexp "src=\\\"\\(images\\)" "../images"
                                      html-link nil nil 1))
    html-link))

(defun ar/org-export--collect-tree-properties--postprocess (orig-fun &rest r)
  (save-excursion
    (save-restriction
      (widen)
      (org-combine-plists (apply orig-fun r)
                          `(:id-alist ,(org-element-map (org-element-parse-buffer 'headline)
                                           'headline
                                         (lambda (headline)
                                           (cons (org-element-property :CUSTOM_ID headline) "index.org"))))))))


(defun ar/org-export-current-headline-async ()
  (interactive)
  (let ((headline (ar/org-element-at-heading-1)))
    (assert (eq major-mode 'org-mode))
    (async-shell-command (concat (expand-file-name invocation-name invocation-directory)
                                 " --batch -Q"
                                 " -l "(expand-file-name "~/.emacs.d/ar/ar-org-export-init.el")
                                 (format " --execute '(ar/org-split-export-headline \"%s\" \"%s\" \"%s\" %d t)'"
                                         (expand-file-name "~/stuff/active/blog/index.org")
                                         (ar/org-split-export--parse-headline-title
                                          (org-element-property :raw-value headline))
                                         (org-element-property :CUSTOM_ID headline)
                                         (org-element-property :begin headline)))
                         "*org html export*")))

(defun ar/org-export-current-headline ()
  (interactive)
  (let ((headline (ar/org-element-at-heading-1)))
    (assert (eq major-mode 'org-mode))
    (ar/org-split-export-headline (expand-file-name "~/stuff/active/blog/index.org")
                                  (ar/org-split-export--parse-headline-title
                                   (org-element-property :raw-value headline))
                                  (org-element-property :CUSTOM_ID headline)
                                  (org-element-property :begin headline)) t)))

{'fraction_non_alphanumeric': 0.15375956776226926, 'fraction_numerical': 0.004615038271049077, 'mean_word_length': 1.4302516411378556, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1983764', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2491, 'n_words': 480}