[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote edbc0e4322 1/2: Absorb denote-org-dblock.el into
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote edbc0e4322 1/2: Absorb denote-org-dblock.el into denote-org-extras.el |
Date: |
Tue, 23 Jan 2024 00:57:41 -0500 (EST) |
branch: externals/denote
commit edbc0e43225f94a605feaf4743b034ce6d2fd9ce
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Absorb denote-org-dblock.el into denote-org-extras.el
---
README.org | 56 +++++++++----
denote-org-dblock.el | 223 ++++++---------------------------------------------
denote-org-extras.el | 216 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 282 insertions(+), 213 deletions(-)
diff --git a/README.org b/README.org
index 63ac74d983..1117d7603a 100644
--- a/README.org
+++ b/README.org
@@ -2498,6 +2498,16 @@ own function and assigning it to the
~denote-rename-buffer-function~.
:CUSTOM_ID: h:8b542c50-dcc9-4bca-8037-a36599b22779
:END:
+[ As part of version 3.0.0 (currently {{{development-version}}}), all
+ dynamic blocks are defined in the file =denote-org-extras.el=. The
+ file which was once called =denote-org-dblock.el= contains aliases
+ for the new function names and dipslays a warning about its
+ deprecation. There is no need to ~require~ the ~denote-org-extras~
+ feature because all of Denote's Org dynamic blocks are autoloaded
+ (meaning that they work as soon as they are used). For backward
+ compatibility, all dynamic blocks retain their original names as an
+ alias for the newer one. ]
+
Denote can optionally integrate with Org mode's "dynamic blocks"
facility. This means that it can use special blocks that are evaluated
with =C-c C-x C-u= (~org-dblock-update~) to generate their contents.
@@ -2507,12 +2517,6 @@ provided by Denote.
- [[#h:50160fae-6515-4d7d-9737-995ad925e64b][Org dynamic blocks to insert
links or backlinks]]
- [[#h:f15fa143-5036-416f-9bff-1bcabbb03456][Org dynamic block to insert file
contents]]
-Start by loading the relevant extension:
-
-#+begin_src emacs-lisp
-(require 'denote-org-dblock)
-#+end_src
-
A dynamic block gets its contents by evaluating a function that
corresponds to the type of block. The block type and its parameters
are stated in the opening =#+BEGIN= line. Typing =C-c C-x C-u=
@@ -2535,9 +2539,19 @@ Evaluate:
:CUSTOM_ID: h:50160fae-6515-4d7d-9737-995ad925e64b
:END:
-#+findex: denote-org-dblock-insert-links
+[ As part of version 3.0.0 (currently {{{development-version}}}), all
+ dynamic blocks are defined in the file =denote-org-extras.el=. The
+ file which was once called =denote-org-dblock.el= contains aliases
+ for the new function names and dipslays a warning about its
+ deprecation. There is no need to ~require~ the ~denote-org-extras~
+ feature because all of Denote's Org dynamic blocks are autoloaded
+ (meaning that they work as soon as they are used). For backward
+ compatibility, all dynamic blocks retain their original names as an
+ alias for the newer one. ]
+
+#+findex: denote-org-extras-dblock-insert-links
The =denote-links= block can be inserted at point with the command
-~denote-org-dblock-insert-links~ or by manually including the
+~denote-org-extras-dblock-insert-links~ or by manually including the
following in an Org file:
: #+BEGIN: denote-links :regexp "YOUR REGEXP HERE" :sort-by-component nil
:reverse-sort nil :id-only nil
@@ -2565,7 +2579,7 @@ line to update the block.
- The =:sort-by-component= parameter is optional. It sorts the files
by the given Denote file name component. The value it accepts is an
unquoted symbol among =title=, =keywords=, =signature=, =identifier=.
- When using the command ~denote-org-dblock-insert-files~, this
+ When using the command ~denote-org-extras-dblock-insert-files~, this
parameter is automatically inserted together with the (=:regexp=
parameter) and the user is prompted for a file name component.
@@ -2584,10 +2598,10 @@ line to update the block.
processing using Org facilities (a feature that is outside Denote's
purview).
-#+findex: denote-org-dblock-insert-backlinks
+#+findex: denote-org-extras-dblock-insert-backlinks
The same as above except for the =:regexp= parameter are true for the
=denote-backlinks= block. The block can be inserted at point with the
-command ~denote-org-dblock-insert-backlinks~ or by manually writing
+command ~denote-org-extras-dblock-insert-backlinks~ or by manually writing
this in an Org file:
: #+BEGIN: denote-backlinks :sort-by-component nil :reverse-sort nil :id-only
nil
@@ -2602,6 +2616,16 @@ Remember to type =C-c C-x C-u= (~org-dblock-update~)
with point on the
:CUSTOM_ID: h:f15fa143-5036-416f-9bff-1bcabbb03456
:END:
+[ As part of version 3.0.0 (currently {{{development-version}}}), all
+ dynamic blocks are defined in the file =denote-org-extras.el=. The
+ file which was once called =denote-org-dblock.el= contains aliases
+ for the new function names and dipslays a warning about its
+ deprecation. There is no need to ~require~ the ~denote-org-extras~
+ feature because all of Denote's Org dynamic blocks are autoloaded
+ (meaning that they work as soon as they are used). For backward
+ compatibility, all dynamic blocks retain their original names as an
+ alias for the newer one. ]
+
Denote can optionally use Org's dynamic blocks facility to produce a
section that lists entire file contents
([[#h:8b542c50-dcc9-4bca-8037-a36599b22779][Use Org dynamic blocks]]).
This works by instructing Org to match a regular expression of Denote
@@ -2612,8 +2636,8 @@ list of scattered thoughts on a given topic, like
=^2023.*_emacs= for
a long entry that incorporates all the notes written in 2023 with the
keyword =emacs=.
-#+findex: denote-org-dblock-insert-files
-To produce such a block, call the command ~denote-org-dblock-insert-files~
+#+findex: denote-org-extras-dblock-insert-files
+To produce such a block, call the command
~denote-org-extras-dblock-insert-files~
or manually write the following block in an Org file and then type
=C-c C-x C-u= (~org-dblock-update~) on the =#+BEGIN= line to run it
(do it again to recalculate the block):
@@ -2640,7 +2664,7 @@ parameters, which are described further below:
- The =:sort-by-component= parameter is optional. It sorts the files
by the given Denote file name component. The value it accepts is an
unquoted symbol among =title=, =keywords=, =signature=, =identifier=.
- When using the command ~denote-org-dblock-insert-files~, this
+ When using the command ~denote-org-extras-dblock-insert-files~, this
parameter is automatically inserted together with the (=:regexp=
parameter) and the user is prompted for a file name component.
@@ -2649,10 +2673,10 @@ parameters, which are described further below:
of the parameter =:sort-by-component=, though it also combines with
it.
-#+vindex: denote-org-dblock-file-contents-separator
+#+vindex: denote-org-extras-dblock-file-contents-separator
- The =:file-separator= parameter is optional. If it is omitted, then
Denote will use no separator between the files it inserts. If the
- value is ~t~ the ~denote-org-dblock-file-contents-separator~ is
+ value is ~t~ the ~denote-org-extras-dblock-file-contents-separator~ is
applied at the end of each file: it introduces some empty lines and
a horizontal rule between them to visually distinguish individual
files. If the =:file-separator= value is a string, it is used as the
diff --git a/denote-org-dblock.el b/denote-org-dblock.el
index 158da6fd15..03a97dbce0 100644
--- a/denote-org-dblock.el
+++ b/denote-org-dblock.el
@@ -1,10 +1,11 @@
-;;; denote-org-dblock.el --- Denote Org Dynamic blocks -*- lexical-binding: t
-*-
+;;; denote-org-dblock.el --- Compatibility alieases for Denote Org Dynamic
blocks -*- lexical-binding: t -*-
;; Copyright (C) 2022-2024 Free Software Foundation, Inc.
;; Authors: Elias Storms <elias.storms@gmail.com>,
;; Protesilaos Stavrou <info@protesilaos.com>
;; Maintainer: Protesilaos Stavrou <info@protesilaos.com>
+;; Deprecated-since: 3.0.0
;; URL: https://github.com/protesilaos/denote
;; This file is NOT part of GNU Emacs.
@@ -24,6 +25,13 @@
;;; Commentary:
;;
+;; This file defines compatibility aliases for Org dynamic blocks set
+;; up by Denote. The new source of these is the denote-org-extras.el.
+;;
+;; Below is the old commentary.
+;;
+;; * * *
+;;
;; This file defines Org dynamic blocks using the facility described
;; in the Org manual. Evaluate this:
;;
@@ -36,206 +44,27 @@
;;; Code:
-(require 'denote)
-(require 'denote-sort)
-(require 'org)
-
-;;;; Common helper functions
-
-(defun denote-org-dblock--files (files-matching-regexp &optional
sort-by-component reverse)
- "Return list of FILES-MATCHING-REGEXP in variable `denote-directory'.
-SORT-BY-COMPONENT and REVERSE have the same meaning as
-`denote-sort-files'. If both are nil, do not try to perform any
-sorting."
- (cond
- ((and sort-by-component reverse)
- (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse :omit-current))
- (sort-by-component
- (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse :omit-current))
- (reverse
- (denote-sort-get-directory-files files-matching-regexp
:no-component-specified reverse :omit-current))
- (t
- (denote-directory-files files-matching-regexp :omit-current))))
-
-;;;; Dynamic block to insert links
-
-;;;###autoload
-(defun denote-org-dblock-insert-links (regexp)
- "Create Org dynamic block to insert Denote links matching REGEXP."
- (interactive
- (list
- (denote-files-matching-regexp-prompt))
- org-mode)
- (org-create-dblock (list :name "denote-links"
- :regexp regexp
- :sort-by-component nil
- :reverse-sort nil
- :id-only nil))
- (org-update-dblock))
-
-(org-dynamic-block-define "denote-links" 'denote-org-dblock-insert-links)
-
-(defun org-dblock-write:denote-links (params)
- "Function to update `denote-links' Org Dynamic blocks.
-Used by `org-dblock-update' with PARAMS provided by the dynamic block."
- (let* ((regexp (plist-get params :regexp))
- (rx (if (listp regexp) (macroexpand `(rx ,regexp)) regexp))
- (sort (plist-get params :sort-by-component))
- (reverse (plist-get params :reverse-sort))
- (block-name (plist-get params :block-name))
- (files (denote-org-dblock--files rx sort reverse)))
- (when block-name (insert "#+name: " block-name "\n"))
- (denote-link--insert-links files 'org (plist-get params :id-only)
:no-other-sorting)
- (join-line))) ; remove trailing empty line
-
-;;;; Dynamic block to insert backlinks
-
-(defun denote-org-dblock--maybe-sort-backlinks (files sort-by-component
reverse)
- "Sort backlink FILES if SORT-BY-COMPONENT and/or REVERSE is non-nil."
- (cond
- ((and sort-by-component reverse)
- (denote-sort-files files sort-by-component reverse))
- (sort-by-component
- (denote-sort-files files sort-by-component))
- (reverse
- (denote-sort-files files :no-component-specified reverse))
- (t
- files)))
-
-;;;###autoload
-(defun denote-org-dblock-insert-backlinks ()
- "Create Org dynamic block to insert Denote backlinks to current file."
- (interactive nil org-mode)
- (org-create-dblock (list :name "denote-backlinks"
- :sort-by-component nil
- :reverse-sort nil
- :id-only nil))
- (org-update-dblock))
-
-(org-dynamic-block-define "denote-backlinks"
'denote-org-dblock-insert-backlinks)
-
-(defun org-dblock-write:denote-backlinks (params)
- "Function to update `denote-backlinks' Org Dynamic blocks.
-Used by `org-dblock-update' with PARAMS provided by the dynamic block."
- (when-let ((files (denote-link-return-backlinks)))
- (let* ((sort (plist-get params :sort-by-component))
- (reverse (plist-get params :reverse-sort))
- (files (denote-org-dblock--maybe-sort-backlinks files sort
reverse)))
- (denote-link--insert-links files 'org (plist-get params :id-only)
:no-other-sorting)
- (join-line)))) ; remove trailing empty line
-
-;;;; Dynamic block to insert entire file contents
-
-(defun denote-org-dblock--get-file-contents (file &optional no-front-matter
add-links)
- "Insert the contents of FILE.
-With optional NO-FRONT-MATTER as non-nil, try to remove the front
-matter from the top of the file. If NO-FRONT-MATTER is a number,
-remove that many lines starting from the top. If it is any other
-non-nil value, delete from the top until the first blank line.
-
-With optional ADD-LINKS as non-nil, first insert a link to the
-file and then insert its contents. In this case, format the
-contents as a typographic list. If ADD-LINKS is `id-only', then
-insert links as `denote-link' does when supplied with an ID-ONLY
-argument."
- (when (denote-file-is-note-p file)
- (with-temp-buffer
- (when add-links
- (insert
- (format "- %s\n\n"
- (denote-format-link
- file
- (if (eq add-links 'id-only)
- denote-id-only-link-format
- denote-org-link-format)
- (let ((type (denote-filetype-heuristics file)))
- (if (denote-file-has-signature-p file)
- (denote--link-get-description-with-signature file type)
- (denote--link-get-description file type)))))))
- (let ((beginning-of-contents (point)))
- (insert-file-contents file)
- (when no-front-matter
- (delete-region
- (if (natnump no-front-matter)
- (progn (forward-line no-front-matter) (line-beginning-position))
- (1+ (re-search-forward "^$" nil :no-error 1)))
- beginning-of-contents))
- (when add-links
- (indent-region beginning-of-contents (point-max) 2)))
- (buffer-string))))
-
-(defvar denote-org-dblock-file-contents-separator
- (concat "\n\n" (make-string 50 ?-) "\n\n\n")
- "Fallback separator used by `denote-org-dblock-add-files'.")
-
-(defun denote-org-dblock--separator (separator)
- "Return appropriate value of SEPARATOR for `denote-org-dblock-add-files'."
- (cond
- ((null separator) "")
- ((stringp separator) separator)
- (t denote-org-dblock-file-contents-separator)))
-
-(defun denote-org-dblock-add-files (regexp &optional separator no-front-matter
add-links sort-by-component reverse)
- "Insert files matching REGEXP.
-
-Seaprate them with the optional SEPARATOR. If SEPARATOR is nil,
-use the `denote-org-dblock-file-contents-separator'.
-
-If optional NO-FRONT-MATTER is non-nil try to remove the front
-matter from the top of the file. Do it by finding the first
-blank line, starting from the top of the buffer.
-
-If optional ADD-LINKS is non-nil, first insert a link to the file
-and then insert its contents. In this case, format the contents
-as a typographic list.
-
-If optional SORT-BY-COMPONENT is a symbol among `denote-sort-components',
-sort files matching REGEXP by the corresponding Denote file name
-component. If the symbol is not among `denote-sort-components',
-fall back to the default identifier-based sorting.
+(require 'denote-org-extras)
-If optional REVERSE is non-nil reverse the sort order."
- (let* ((files (denote-org-dblock--files regexp sort-by-component reverse))
- (files-contents (mapcar
- (lambda (file) (denote-org-dblock--get-file-contents
file no-front-matter add-links))
- files)))
- (insert (string-join files-contents (denote-org-dblock--separator
separator)))))
+(define-obsolete-function-alias
+ 'denote-org-dblock-insert-links
+ 'denote-org-extras-dblock-insert-links
+ "3.0.0")
-;;;###autoload
-(defun denote-org-dblock-insert-files (regexp sort-by-component)
- "Create Org dynamic block to insert Denote files matching REGEXP.
-Sort the files according to SORT-BY-COMPONENT, which is a symbol
-among `denote-sort-components'."
- (interactive
- (list
- (denote-files-matching-regexp-prompt)
- (denote-sort-component-prompt))
- org-mode)
- (org-create-dblock (list :name "denote-files"
- :regexp regexp
- :sort-by-component sort-by-component
- :reverse-sort nil
- :no-front-matter nil
- :file-separator nil
- :add-links nil))
- (org-update-dblock))
+(define-obsolete-function-alias
+ 'denote-org-dblock-insert-backlinks
+ 'denote-org-extras-dblock-insert-backlinks
+ "3.0.0")
-(org-dynamic-block-define "denote-files" 'denote-org-dblock-insert-files)
+(define-obsolete-function-alias
+ 'denote-org-dblock-insert-files
+ 'denote-org-extras-dblock-insert-files
+ "3.0.0")
-(defun org-dblock-write:denote-files (params)
- "Function to update `denote-files' Org Dynamic blocks.
-Used by `org-dblock-update' with PARAMS provided by the dynamic block."
- (let* ((regexp (plist-get params :regexp))
- (rx (if (listp regexp) (macroexpand `(rx ,regexp)) regexp))
- (sort (plist-get params :sort-by-component))
- (reverse (plist-get params :reverse-sort))
- (block-name (plist-get params :block-name))
- (separator (plist-get params :file-separator))
- (no-f-m (plist-get params :no-front-matter))
- (add-links (plist-get params :add-links)))
- (when block-name (insert "#+name: " block-name "\n"))
- (when rx (denote-org-dblock-add-files rx separator no-f-m add-links sort
reverse)))
- (join-line)) ; remove trailing empty line
+(display-warning
+ 'denote
+ "`denote-org-dblock.el' is obsolete; use `denote-org-extras.el'"
+ :warning)
(provide 'denote-org-dblock)
;;; denote-org-dblock.el ends here
diff --git a/denote-org-extras.el b/denote-org-extras.el
index 93a8783bdd..b3b7147540 100644
--- a/denote-org-extras.el
+++ b/denote-org-extras.el
@@ -28,6 +28,7 @@
;;; Code:
(require 'denote)
+(require 'denote-sort)
(require 'org)
;;;; Link to file and heading
@@ -165,5 +166,220 @@ Make the new note an Org file regardless of the value of
(insert text))
(user-error "No subtree to extract; aborting")))
+;;;; Org dynamic blocks
+
+;; NOTE 2024-01-22 12:26:13 +0200: The following is copied from the
+;; now-deleted denote-org-dblock.el. Its original author was Elias
+;; Storms <elias.storms@gmail.com>, with substantial contributions and
+;; further developments by me (Protesilaos).
+
+;; This section defines Org dynamic blocks using the facility described
+;; in the Org manual. Evaluate this:
+;;
+;; (info "(org) Dynamic Blocks")
+;;
+;; The dynamic blocks defined herein are documented at length in the
+;; Denote manual. See the following node and its subsections:
+;;
+;; (info "(denote) Use Org dynamic blocks")
+
+;;;;; Common helper functions
+
+(defun denote-org-extras-dblock--files (files-matching-regexp &optional
sort-by-component reverse)
+ "Return list of FILES-MATCHING-REGEXP in variable `denote-directory'.
+SORT-BY-COMPONENT and REVERSE have the same meaning as
+`denote-sort-files'. If both are nil, do not try to perform any
+sorting."
+ (cond
+ ((and sort-by-component reverse)
+ (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse :omit-current))
+ (sort-by-component
+ (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse :omit-current))
+ (reverse
+ (denote-sort-get-directory-files files-matching-regexp
:no-component-specified reverse :omit-current))
+ (t
+ (denote-directory-files files-matching-regexp :omit-current))))
+
+;;;;; Dynamic block to insert links
+
+;;;###autoload
+(defun denote-org-extras-dblock-insert-links (regexp)
+ "Create Org dynamic block to insert Denote links matching REGEXP."
+ (interactive
+ (list
+ (denote-files-matching-regexp-prompt))
+ org-mode)
+ (org-create-dblock (list :name "denote-links"
+ :regexp regexp
+ :sort-by-component nil
+ :reverse-sort nil
+ :id-only nil))
+ (org-update-dblock))
+
+(org-dynamic-block-define "denote-links"
'denote-org-extras-dblock-insert-links)
+
+(defun org-dblock-write:denote-links (params)
+ "Function to update `denote-links' Org Dynamic blocks.
+Used by `org-dblock-update' with PARAMS provided by the dynamic block."
+ (let* ((regexp (plist-get params :regexp))
+ (rx (if (listp regexp) (macroexpand `(rx ,regexp)) regexp))
+ (sort (plist-get params :sort-by-component))
+ (reverse (plist-get params :reverse-sort))
+ (block-name (plist-get params :block-name))
+ (files (denote-org-extras-dblock--files rx sort reverse)))
+ (when block-name (insert "#+name: " block-name "\n"))
+ (denote-link--insert-links files 'org (plist-get params :id-only)
:no-other-sorting)
+ (join-line))) ; remove trailing empty line
+
+;;;;; Dynamic block to insert backlinks
+
+(defun denote-org-extras-dblock--maybe-sort-backlinks (files sort-by-component
reverse)
+ "Sort backlink FILES if SORT-BY-COMPONENT and/or REVERSE is non-nil."
+ (cond
+ ((and sort-by-component reverse)
+ (denote-sort-files files sort-by-component reverse))
+ (sort-by-component
+ (denote-sort-files files sort-by-component))
+ (reverse
+ (denote-sort-files files :no-component-specified reverse))
+ (t
+ files)))
+
+;;;###autoload
+(defun denote-org-extras-dblock-insert-backlinks ()
+ "Create Org dynamic block to insert Denote backlinks to current file."
+ (interactive nil org-mode)
+ (org-create-dblock (list :name "denote-backlinks"
+ :sort-by-component nil
+ :reverse-sort nil
+ :id-only nil))
+ (org-update-dblock))
+
+(org-dynamic-block-define "denote-backlinks"
'denote-org-extras-dblock-insert-backlinks)
+
+(defun org-dblock-write:denote-backlinks (params)
+ "Function to update `denote-backlinks' Org Dynamic blocks.
+Used by `org-dblock-update' with PARAMS provided by the dynamic block."
+ (when-let ((files (denote-link-return-backlinks)))
+ (let* ((sort (plist-get params :sort-by-component))
+ (reverse (plist-get params :reverse-sort))
+ (files (denote-org-extras-dblock--maybe-sort-backlinks files sort
reverse)))
+ (denote-link--insert-links files 'org (plist-get params :id-only)
:no-other-sorting)
+ (join-line)))) ; remove trailing empty line
+
+;;;;; Dynamic block to insert entire file contents
+
+(defun denote-org-extras-dblock--get-file-contents (file &optional
no-front-matter add-links)
+ "Insert the contents of FILE.
+With optional NO-FRONT-MATTER as non-nil, try to remove the front
+matter from the top of the file. If NO-FRONT-MATTER is a number,
+remove that many lines starting from the top. If it is any other
+non-nil value, delete from the top until the first blank line.
+
+With optional ADD-LINKS as non-nil, first insert a link to the
+file and then insert its contents. In this case, format the
+contents as a typographic list. If ADD-LINKS is `id-only', then
+insert links as `denote-link' does when supplied with an ID-ONLY
+argument."
+ (when (denote-file-is-note-p file)
+ (with-temp-buffer
+ (when add-links
+ (insert
+ (format "- %s\n\n"
+ (denote-format-link
+ file
+ (if (eq add-links 'id-only)
+ denote-id-only-link-format
+ denote-org-link-format)
+ (let ((type (denote-filetype-heuristics file)))
+ (if (denote-file-has-signature-p file)
+ (denote--link-get-description-with-signature file type)
+ (denote--link-get-description file type)))))))
+ (let ((beginning-of-contents (point)))
+ (insert-file-contents file)
+ (when no-front-matter
+ (delete-region
+ (if (natnump no-front-matter)
+ (progn (forward-line no-front-matter) (line-beginning-position))
+ (1+ (re-search-forward "^$" nil :no-error 1)))
+ beginning-of-contents))
+ (when add-links
+ (indent-region beginning-of-contents (point-max) 2)))
+ (buffer-string))))
+
+(defvar denote-org-extras-dblock-file-contents-separator
+ (concat "\n\n" (make-string 50 ?-) "\n\n\n")
+ "Fallback separator used by `denote-org-extras-dblock-add-files'.")
+
+(defun denote-org-extras-dblock--separator (separator)
+ "Return appropriate value of SEPARATOR for
`denote-org-extras-dblock-add-files'."
+ (cond
+ ((null separator) "")
+ ((stringp separator) separator)
+ (t denote-org-extras-dblock-file-contents-separator)))
+
+(defun denote-org-extras-dblock-add-files (regexp &optional separator
no-front-matter add-links sort-by-component reverse)
+ "Insert files matching REGEXP.
+
+Seaprate them with the optional SEPARATOR. If SEPARATOR is nil,
+use the `denote-org-extras-dblock-file-contents-separator'.
+
+If optional NO-FRONT-MATTER is non-nil try to remove the front
+matter from the top of the file. Do it by finding the first
+blank line, starting from the top of the buffer.
+
+If optional ADD-LINKS is non-nil, first insert a link to the file
+and then insert its contents. In this case, format the contents
+as a typographic list.
+
+If optional SORT-BY-COMPONENT is a symbol among `denote-sort-components',
+sort files matching REGEXP by the corresponding Denote file name
+component. If the symbol is not among `denote-sort-components',
+fall back to the default identifier-based sorting.
+
+If optional REVERSE is non-nil reverse the sort order."
+ (let* ((files (denote-org-extras-dblock--files regexp sort-by-component
reverse))
+ (files-contents (mapcar
+ (lambda (file)
(denote-org-extras-dblock--get-file-contents file no-front-matter add-links))
+ files)))
+ (insert (string-join files-contents (denote-org-extras-dblock--separator
separator)))))
+
+;;;###autoload
+(defun denote-org-extras-dblock-insert-files (regexp sort-by-component)
+ "Create Org dynamic block to insert Denote files matching REGEXP.
+Sort the files according to SORT-BY-COMPONENT, which is a symbol
+among `denote-sort-components'."
+ (interactive
+ (list
+ (denote-files-matching-regexp-prompt)
+ (denote-sort-component-prompt))
+ org-mode)
+ (org-create-dblock (list :name "denote-files"
+ :regexp regexp
+ :sort-by-component sort-by-component
+ :reverse-sort nil
+ :no-front-matter nil
+ :file-separator nil
+ :add-links nil))
+ (org-update-dblock))
+
+(org-dynamic-block-define "denote-files"
'denote-org-extras-dblock-insert-files)
+
+(defun org-dblock-write:denote-files (params)
+ "Function to update `denote-files' Org Dynamic blocks.
+Used by `org-dblock-update' with PARAMS provided by the dynamic block."
+ (let* ((regexp (plist-get params :regexp))
+ (rx (if (listp regexp) (macroexpand `(rx ,regexp)) regexp))
+ (sort (plist-get params :sort-by-component))
+ (reverse (plist-get params :reverse-sort))
+ (block-name (plist-get params :block-name))
+ (separator (plist-get params :file-separator))
+ (no-f-m (plist-get params :no-front-matter))
+ (add-links (plist-get params :add-links)))
+ (when block-name (insert "#+name: " block-name "\n"))
+ (when rx (denote-org-extras-dblock-add-files rx separator no-f-m add-links
sort reverse)))
+ (join-line)) ; remove trailing empty line
+
+
(provide 'denote-org-extras)
;;; denote-org-extras.el ends here