<commit_before>;;; lang/org/config.el -*- lexical-binding: t; -*-

;; FIXME deprecated
(define-obsolete-variable-alias '+org-dir 'org-directory "2.1.0")

;; Changed org defaults (should be set before org loads)
(defvar org-directory "~/org/")
(defvar org-modules
  '(org-w3m
    ;; org-bbdb
    org-bibtex
    org-docview
    ;; org-gnus
    org-info
    ;; org-irc
    ;; org-mhe
    ;; org-rmail
    ))

;; Sub-modules
(if (featurep! +attach)  (load! "+attach"))
(if (featurep! +babel)   (load! "+babel"))
(if (featurep! +capture) (load! "+capture"))
(if (featurep! +export)  (load! "+export"))
(if (featurep! +present) (load! "+present"))
;; TODO (if (featurep! +publish) (load! "+publish"))

(doom-load-packages-incrementally
 '(calendar find-func format-spec org-macs org-compat
   org-faces org-entities org-list org-pcomplete org-src
   org-footnote org-macro ob org org-agenda org-capture))


;;
;; Packages

;; `toc-org'
(setq toc-org-hrefify-default "org")

(def-package! evil-org
  :when (featurep! :feature evil +everywhere)
  :hook (org-mode . evil-org-mode)
  :init
  (defvar evil-org-key-theme '(navigation insert textobjects))
  (defvar evil-org-special-o/O '(table-row))
  (add-hook 'org-load-hook #'+org|setup-evil)
  (add-hook 'evil-org-mode-hook #'evil-normalize-keymaps)
  :config
  ;; change `evil-org-key-theme' instead
  (advice-add #'evil-org-set-key-theme :override #'ignore)
  (def-package! evil-org-agenda
    :after org-agenda
    :config (evil-org-agenda-set-keys)))

(def-package! org-pdfview
  :when (featurep! :tools pdf)
  :commands (org-pdfview-open)
  :init
  (after! org
    (delete '("\\.pdf\\'" . default) org-file-apps)
    ;; org links to pdf files are opened in pdf-view-mode
    (add-to-list 'org-file-apps '("\\.pdf\\'" . (lambda (_file link) (org-pdfview-open link)))) 
    ;; support for links to specific pages
    (add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . (lambda (_file link) (org-pdfview-open link))))))

(def-package! org-yt
  :after org
  :config
  (defun +org-inline-data-image (_protocol link _description)
    "Interpret LINK as base64-encoded image data."
    (base64-decode-string link))

  (defun +org-image-link (protocol link _description)
    "Interpret LINK as base64-encoded image data."
    (when (image-type-from-file-name link)
      (if-let* ((buf (url-retrieve-synchronously (concat protocol ":" link))))
          (with-current-buffer buf
            (goto-char (point-min))
            (re-search-forward "\r?\n\r?\n" nil t)
            (buffer-substring-no-properties (point) (point-max)))
        (message "Download of image \"%s\" failed" link)
        nil)))

  (org-link-set-parameters "http"  :image-data-fun #'+org-image-link)
  (org-link-set-parameters "https" :image-data-fun #'+org-image-link)
  (org-link-set-parameters "img"   :image-data-fun #'+org-inline-data-image))


;;
;; Bootstrap

(add-hook! 'org-load-hook
  #'(+org|setup-ui
     +org|setup-popup-rules
     +org|setup-agenda
     +org|setup-keybinds
     +org|setup-hacks
     +org|setup-pretty-code
     +org|setup-custom-links))

(add-hook! 'org-mode-hook
  #'(doom|disable-line-numbers  ; org doesn't really need em
     org-bullets-mode           ; "prettier" bullets
     org-indent-mode            ; margin-based indentation
     toc-org-enable             ; auto-table of contents
     auto-fill-mode             ; line wrapping
     ;; `show-paren-mode' causes flickering with indentation margins made by
     ;; `org-indent-mode', so we simply turn off show-paren-mode altogether."
     doom|disable-show-paren-mode

     +org|enable-auto-reformat-tables
     +org|enable-auto-update-cookies
     +org|smartparens-compatibility-config
     +org|unfold-to-2nd-level-or-point))


;;
;; `org-mode' hooks

(defun +org|unfold-to-2nd-level-or-point ()
  "My version of the 'overview' #+STARTUP option: expand first-level headings.
Expands the first level, but no further. If point was left somewhere deeper,
unfold to point on startup."
  (unless org-agenda-inhibit-startup
    (when (eq org-startup-folded t)
      (outline-hide-sublevels 2))
    (when (outline-invisible-p)<commit_msg>No longer disable line numbers in org-mode<commit_after>;;; lang/org/config.el -*- lexical-binding: t; -*-

;; FIXME deprecated
(define-obsolete-variable-alias '+org-dir 'org-directory "2.1.0")

;; Changed org defaults (should be set before org loads)
(defvar org-directory "~/org/")
(defvar org-modules
  '(org-w3m
    ;; org-bbdb
    org-bibtex
    org-docview
    ;; org-gnus
    org-info
    ;; org-irc
    ;; org-mhe
    ;; org-rmail
    ))

;; Sub-modules
(if (featurep! +attach)  (load! "+attach"))
(if (featurep! +babel)   (load! "+babel"))
(if (featurep! +capture) (load! "+capture"))
(if (featurep! +export)  (load! "+export"))
(if (featurep! +present) (load! "+present"))
;; TODO (if (featurep! +publish) (load! "+publish"))

(doom-load-packages-incrementally
 '(calendar find-func format-spec org-macs org-compat
   org-faces org-entities org-list org-pcomplete org-src
   org-footnote org-macro ob org org-agenda org-capture))


;;
;; Packages

;; `toc-org'
(setq toc-org-hrefify-default "org")

(def-package! evil-org
  :when (featurep! :feature evil +everywhere)
  :hook (org-mode . evil-org-mode)
  :init
  (defvar evil-org-key-theme '(navigation insert textobjects))
  (defvar evil-org-special-o/O '(table-row))
  (add-hook 'org-load-hook #'+org|setup-evil)
  (add-hook 'evil-org-mode-hook #'evil-normalize-keymaps)
  :config
  ;; change `evil-org-key-theme' instead
  (advice-add #'evil-org-set-key-theme :override #'ignore)
  (def-package! evil-org-agenda
    :after org-agenda
    :config (evil-org-agenda-set-keys)))

(def-package! org-pdfview
  :when (featurep! :tools pdf)
  :commands (org-pdfview-open)
  :init
  (after! org
    (delete '("\\.pdf\\'" . default) org-file-apps)
    ;; org links to pdf files are opened in pdf-view-mode
    (add-to-list 'org-file-apps '("\\.pdf\\'" . (lambda (_file link) (org-pdfview-open link)))) 
    ;; support for links to specific pages
    (add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . (lambda (_file link) (org-pdfview-open link))))))

(def-package! org-yt
  :after org
  :config
  (defun +org-inline-data-image (_protocol link _description)
    "Interpret LINK as base64-encoded image data."
    (base64-decode-string link))

  (defun +org-image-link (protocol link _description)
    "Interpret LINK as base64-encoded image data."
    (when (image-type-from-file-name link)
      (if-let* ((buf (url-retrieve-synchronously (concat protocol ":" link))))
          (with-current-buffer buf
            (goto-char (point-min))
            (re-search-forward "\r?\n\r?\n" nil t)
            (buffer-substring-no-properties (point) (point-max)))
        (message "Download of image \"%s\" failed" link)
        nil)))

  (org-link-set-parameters "http"  :image-data-fun #'+org-image-link)
  (org-link-set-parameters "https" :image-data-fun #'+org-image-link)
  (org-link-set-parameters "img"   :image-data-fun #'+org-inline-data-image))


;;
;; Bootstrap

(add-hook! 'org-load-hook
  #'(+org|setup-ui
     +org|setup-popup-rules
     +org|setup-agenda
     +org|setup-keybinds
     +org|setup-hacks
     +org|setup-pretty-code
     +org|setup-custom-links))

(add-hook! 'org-mode-hook
  #'(org-bullets-mode           ; "prettier" bullets
     org-indent-mode            ; margin-based indentation
     toc-org-enable             ; auto-table of contents
     auto-fill-mode             ; line wrapping
     ;; `show-paren-mode' causes flickering with indentation margins made by
     ;; `org-indent-mode', so we simply turn off show-paren-mode altogether."
     doom|disable-show-paren-mode

     +org|enable-auto-reformat-tables
     +org|enable-auto-update-cookies
     +org|smartparens-compatibility-config
     +org|unfold-to-2nd-level-or-point))


;;
;; `org-mode' hooks

(defun +org|unfold-to-2nd-level-or-point ()
  "My version of the 'overview' #+STARTUP option: expand first-level headings.
Expands the first level, but no further. If point was left somewhere deeper,
unfold to point on startup."
  (unless org-agenda-inhibit-startup
    (when (eq org-startup-folded t)
      (outline-hide-sublevels 2))
    (when (outline-invisible-p)
{'fraction_non_alphanumeric': 0.1679555340744321, 'fraction_numerical': 0.003141614306428226, 'mean_word_length': 3.1117734724292103, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6170396', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2925, 'n_words': 669}