From b7b85eaf9a40e95dad1f1a7b580b1133721ebfda Mon Sep 17 00:00:00 2001 From: J S Date: Mon, 13 Nov 2023 12:43:22 -0500 Subject: [PATCH] feat[archive]: Removed archive functionality I removed the advanced subtree archives as it was disrupting my workflow. I would like to rework it at some point. I also stripped out the display-in-eww functionality. --- config.el | 160 +++++----------------------------------------------- config.org | 161 ++++------------------------------------------------- 2 files changed, 27 insertions(+), 294 deletions(-) diff --git a/config.el b/config.el index 1e25fd5..0660d9d 100644 --- a/config.el +++ b/config.el @@ -264,160 +264,30 @@ If nil it defaults to `split-string-default-separators', normally (org-edna-mode) (use-package org-habit - :custom - (org-habit-graph-column 1) - (org-habit-preceding-days 10) - (org-habit-following-days 1) - (org-habit-show-habits-only-for-today nil)) +:custom +(org-habit-graph-column 1) +(org-habit-preceding-days 10) +(org-habit-following-days 1) +(org-habit-show-habits-only-for-today nil)) (use-package! org-heatmap - :after (org) - :config - (org-heatmap-mode)) +:after (org) +:config +(org-heatmap-mode)) (map! :leader - :desc "Export to html and diplay with eww" - :n "m A" #'org-archive-subtree-default) - -(require 'org-archive) - -; Set the function to use for org-archive-default (C-c C-x C-a) -; (setq org-archive-location (concat org-directory "/archive/%s_archive::")) -; (setq org-archive-location "archive/archived_%s::") - -(setq org-archive-location "~/org/archive.org") -(setq org-archive-location (concat org-directory "/archive.org::")) -; unmap org-archive-subtree - -; select command to execute via org-archive-subtree-default (C-c C-x C-a) -(setq org-archive-default-command 'org-archive-subtree-hierarchical) - -(defun line-content-as-string () - "Returns the content of the current line as a string" - (save-excursion - (beginning-of-line) - (buffer-substring-no-properties - (line-beginning-position) (line-end-position)))) - -(defun org-child-list (&optional top-level) - "This function returns all children of a heading as a list. " - (interactive) - (save-excursion - ;; this only works with org-version > 8.0, since in previous - ;; org-mode versions the function (org-outline-level) returns - ;; gargabe when the point is not on a heading. - (unless top-level - (if (= (org-outline-level) 0) - (outline-next-visible-heading 1) - (org-goto-first-child))) - (let ((child-list (list (line-content-as-string)))) - (while (org-goto-sibling) - (setq child-list (cons (line-content-as-string) child-list))) - child-list))) - -(defun fa/org-struct-subtree () - "This function returns the tree structure in which a subtree belongs as a list." - (interactive) - (let ((archive-tree nil)) - (save-excursion - (while (org-up-heading-safe) - (let ((heading - (buffer-substring-no-properties - (line-beginning-position) (line-end-position)))) - (if (eq archive-tree nil) - (setq archive-tree (list heading)) - (setq archive-tree (cons heading archive-tree)))))) - archive-tree)) - -(defun org-archive-subtree-hierarchical () - "This function archives a subtree hierarchical" - (interactive) - (let ((org-tree (fa/org-struct-subtree)) - (source-buffer (current-buffer)) - (file (abbreviate-file-name - (or (buffer-file-name (buffer-base-buffer)) - (error "No file associated to buffer"))))) - (save-excursion - (setq location (org-archive--compute-location - (or (org-entry-get nil "ARCHIVE" 'inherit) - org-archive-location)) - afile (car location) - heading (cdr location) - infile-p (equal file (abbreviate-file-name (or afile "")))) - (unless afile - (error "Invalid `org-archive-location'")) - (if (not (equal heading "")) - (progn - (setq org-tree (cons heading - (mapcar (lambda (s) (concat "*" s)) org-tree))) - (org-demote-subtree))) - (if (> (length afile) 0) - (progn - (setq newfile-p (not (file-exists-p afile)) - visiting (find-buffer-visiting afile) - target-buffer (or visiting (find-file-noselect afile)))) - (progn - (setq target-buffer (current-buffer)))) - (unless target-buffer - (error "Cannot access file \"%s\"" afile)) - (org-cut-subtree) - (set-buffer target-buffer) - (setq ind-target-buffer (clone-indirect-buffer nil nil)) - (set-buffer ind-target-buffer) - (org-mode) - (goto-char (point-min)) - - ; simplified version of org-complex-heading-regexp-format - (setq my-org-complex-heading-regexp-format - (concat "^" - "\\(%s\\)" - "\\(?: *\\[[0-9%%/]+\\]\\)*" - "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?" - "[ \t]*$")) - (setq top-level-p t) - (while (not (equal org-tree nil)) - (let ((child-list (org-child-list top-level-p)) - (re (format my-org-complex-heading-regexp-format (regexp-quote (car org-tree)))) - ) - (if (member "______FOUND_MATCH" (mapcar (lambda (s) (replace-regexp-in-string re "______FOUND_MATCH" s)) child-list)) - (progn - (re-search-forward re nil t) - (setq org-tree (cdr org-tree))) - (progn - (if (not top-level-p) (newline)) - (org-insert-struct org-tree) - (setq org-tree nil)))) - (setq top-level-p nil)) - (end-of-buffer) - (newline) - (org-yank) - ;; Kill the indirect buffer, returning the current buffer to the direct target buffer - (kill-buffer ind-target-buffer) - ;; Save and kill the target buffer, if it is not the source buffer. - (when (not (eq source-buffer target-buffer)) - (save-buffer target-buffer) - (kill-buffer target-buffer)) - ;; ensure font-lock and indentation are normal - (set-buffer source-buffer) - (org-restart-font-lock) - (org-indent-mode t) - (message "Subtree archived %s" - (concat "in file: " (abbreviate-file-name afile)))))) - -(defun org-insert-struct (struct) - "TODO" - (interactive) - (when struct - (insert (car struct)) - (if (not (equal (length struct) 1)) - (newline)) - (org-insert-struct (cdr struct)))) +:desc "Archive subtree" +:n "m A" #'org-archive-subtree-default) (setq templates/post-capture-props "#+date: [%<%Y-%m-%d %a>]\n#+lastmod:\n#+categories[]:\n#+tags[]:\n#+images[]: ") (setq templates/post-capture-title "#+TITLE: ${title}\n") (setq templates/post-capture-template (concat templates/post-capture-title templates/post-capture-props)) -(setq org-preview-latex-image-directory (concat org-directory (file-name-as-directory "images/latexsnip"))) +(add-to-list 'org-roam-capture-templates + '("m" "Markdown" plain "" :target + (file+head "training-resources/content/${title}.md" +"---\ntitle: ${title}\nid: %<%Y-%m-%dT%H%M%S>\ncategory: \n---\n") + :unnarrowed t)) (setq org-hugo-base-dir (concat org-directory (file-name-as-directory "website"))) (setq org-hugo-default-section-directory "posts") diff --git a/config.org b/config.org index c8a998a..6cff3f6 100644 --- a/config.org +++ b/config.org @@ -426,162 +426,25 @@ Edna allows better dependency handling for todos and the like. ** Org-habit #+BEGIN_SRC emacs-lisp - (use-package org-habit - :custom - (org-habit-graph-column 1) - (org-habit-preceding-days 10) - (org-habit-following-days 1) - (org-habit-show-habits-only-for-today nil)) +(use-package org-habit +:custom +(org-habit-graph-column 1) +(org-habit-preceding-days 10) +(org-habit-following-days 1) +(org-habit-show-habits-only-for-today nil)) - (use-package! org-heatmap - :after (org) - :config - (org-heatmap-mode)) +(use-package! org-heatmap +:after (org) +:config +(org-heatmap-mode)) #+END_SRC ** Org-archive with structure Many thanks to Mark Edigmar's [[https://gist.github.com/edgimar/072d99d8650abe81a9fe7c8687c0c993][Gist]] *** Keymaps #+BEGIN_SRC emacs-lisp (map! :leader - :desc "Export to html and diplay with eww" - :n "m A" #'org-archive-subtree-default) -#+END_SRC - -*** Source -#+BEGIN_SRC emacs-lisp -(require 'org-archive) - -; Set the function to use for org-archive-default (C-c C-x C-a) -; (setq org-archive-location (concat org-directory "/archive/%s_archive::")) -; (setq org-archive-location "archive/archived_%s::") - -(setq org-archive-location "~/org/archive.org") -(setq org-archive-location (concat org-directory "/archive.org::")) -; unmap org-archive-subtree - -; select command to execute via org-archive-subtree-default (C-c C-x C-a) -(setq org-archive-default-command 'org-archive-subtree-hierarchical) - -(defun line-content-as-string () - "Returns the content of the current line as a string" - (save-excursion - (beginning-of-line) - (buffer-substring-no-properties - (line-beginning-position) (line-end-position)))) - -(defun org-child-list (&optional top-level) - "This function returns all children of a heading as a list. " - (interactive) - (save-excursion - ;; this only works with org-version > 8.0, since in previous - ;; org-mode versions the function (org-outline-level) returns - ;; gargabe when the point is not on a heading. - (unless top-level - (if (= (org-outline-level) 0) - (outline-next-visible-heading 1) - (org-goto-first-child))) - (let ((child-list (list (line-content-as-string)))) - (while (org-goto-sibling) - (setq child-list (cons (line-content-as-string) child-list))) - child-list))) - -(defun fa/org-struct-subtree () - "This function returns the tree structure in which a subtree belongs as a list." - (interactive) - (let ((archive-tree nil)) - (save-excursion - (while (org-up-heading-safe) - (let ((heading - (buffer-substring-no-properties - (line-beginning-position) (line-end-position)))) - (if (eq archive-tree nil) - (setq archive-tree (list heading)) - (setq archive-tree (cons heading archive-tree)))))) - archive-tree)) - -(defun org-archive-subtree-hierarchical () - "This function archives a subtree hierarchical" - (interactive) - (let ((org-tree (fa/org-struct-subtree)) - (source-buffer (current-buffer)) - (file (abbreviate-file-name - (or (buffer-file-name (buffer-base-buffer)) - (error "No file associated to buffer"))))) - (save-excursion - (setq location (org-archive--compute-location - (or (org-entry-get nil "ARCHIVE" 'inherit) - org-archive-location)) - afile (car location) - heading (cdr location) - infile-p (equal file (abbreviate-file-name (or afile "")))) - (unless afile - (error "Invalid `org-archive-location'")) - (if (not (equal heading "")) - (progn - (setq org-tree (cons heading - (mapcar (lambda (s) (concat "*" s)) org-tree))) - (org-demote-subtree))) - (if (> (length afile) 0) - (progn - (setq newfile-p (not (file-exists-p afile)) - visiting (find-buffer-visiting afile) - target-buffer (or visiting (find-file-noselect afile)))) - (progn - (setq target-buffer (current-buffer)))) - (unless target-buffer - (error "Cannot access file \"%s\"" afile)) - (org-cut-subtree) - (set-buffer target-buffer) - (setq ind-target-buffer (clone-indirect-buffer nil nil)) - (set-buffer ind-target-buffer) - (org-mode) - (goto-char (point-min)) - - ; simplified version of org-complex-heading-regexp-format - (setq my-org-complex-heading-regexp-format - (concat "^" - "\\(%s\\)" - "\\(?: *\\[[0-9%%/]+\\]\\)*" - "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?" - "[ \t]*$")) - (setq top-level-p t) - (while (not (equal org-tree nil)) - (let ((child-list (org-child-list top-level-p)) - (re (format my-org-complex-heading-regexp-format (regexp-quote (car org-tree)))) - ) - (if (member "______FOUND_MATCH" (mapcar (lambda (s) (replace-regexp-in-string re "______FOUND_MATCH" s)) child-list)) - (progn - (re-search-forward re nil t) - (setq org-tree (cdr org-tree))) - (progn - (if (not top-level-p) (newline)) - (org-insert-struct org-tree) - (setq org-tree nil)))) - (setq top-level-p nil)) - (end-of-buffer) - (newline) - (org-yank) - ;; Kill the indirect buffer, returning the current buffer to the direct target buffer - (kill-buffer ind-target-buffer) - ;; Save and kill the target buffer, if it is not the source buffer. - (when (not (eq source-buffer target-buffer)) - (save-buffer target-buffer) - (kill-buffer target-buffer)) - ;; ensure font-lock and indentation are normal - (set-buffer source-buffer) - (org-restart-font-lock) - (org-indent-mode t) - (message "Subtree archived %s" - (concat "in file: " (abbreviate-file-name afile)))))) - -(defun org-insert-struct (struct) - "TODO" - (interactive) - (when struct - (insert (car struct)) - (if (not (equal (length struct) 1)) - (newline)) - (org-insert-struct (cdr struct)))) +:desc "Archive subtree" +:n "m A" #'org-archive-subtree-default) #+END_SRC * Website