emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 49a2932d42 189/355: Implement denote-link-add-li


From: ELPA Syncer
Subject: [elpa] externals/denote 49a2932d42 189/355: Implement denote-link-add-links
Date: Sun, 26 Jun 2022 23:58:22 -0400 (EDT)

branch: externals/denote
commit 49a2932d42a53812b6a5a69dd0daa87753a44dd2
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Implement denote-link-add-links
---
 README.org     | 38 ++++++++++++++++++++++++++++++++++++++
 denote-link.el | 29 +++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/README.org b/README.org
index cf879c0e3a..054f5fb3aa 100644
--- a/README.org
+++ b/README.org
@@ -597,6 +597,44 @@ By default, the backlinks' buffer is displayed below the 
current window.
 The doc string of our user option includes a configuration that places
 the buffer in a left side window instead.
 
+#+findex: denote-link-add-links
+The command ~denote-link-add-links~ adds links matching a regular
+expression or plain string.  The links are added at point as a
+typographic list, such as:
+
+#+begin_example
+- link1
+- link2
+#+end_example
+
+The current note is excluded from the matching entries (adding a link to
+itself is pointless).
+
+Same examples of a regular expression that can be used with this
+command:
+
+- =journal= match all files which include =journal= anywhere in their
+  name.
+
+- =_journal= match all files which include =journal= as a keyword.
+
+- =^2022.*_journal= match all file names starting with =2022= and
+  including the keyword =journal=.
+
+If files are created with ~denote-sort-keywords~ as non-nil (the
+default), then it is easy to write a regexp that includes multiple
+keywords in alphabetic order:
+
+- =_denote.*_package= match all files that include both the =denote= and
+  =package= keywords, in this order.
+
+- =\(.*denote.*package.*\)\|\(.*package.*denote.*\)= is the same as
+  above, but out-of-order.
+
+Remember that in Emacs regexp input only needs to be quoted once when
+done interactively but twice when called from Lisp.  What we show above
+is for interactive usage.
+
 ** TODO Finalise first version of denote-link.el [2/4]
 *** DONE Add generic linking mechanism
 *** DONE Flesh out the ~denote-link-backlinks~ prototype
diff --git a/denote-link.el b/denote-link.el
index 1c8e998b3d..c23c6c1fbc 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -256,5 +256,34 @@ default, it will show up below the current window."
         (denote-link--prepare-backlinks id files title)
       (user-error "No links to the current note"))))
 
+(defvar denote-link--links-to-files nil
+  "String of `denote-link-add-links-matching-keyword'.")
+
+(defun denote-link--prepare-links (files ext)
+  "Prepare links to FILES using format of EXT."
+  (setq denote-link--links-to-files
+        (with-temp-buffer
+          (mapc (lambda (f)
+                  (insert (concat "- " (denote-link--format-link f ext)))
+                  (newline))
+                files)
+          (let ((min (point-min))
+                (max (point-max)))
+            (buffer-substring-no-properties min max)))))
+
+;;;###autoload
+(defun denote-link-add-links (regexp)
+  "Insert links to all notes matching REGEXP.
+Use this command to reference multiple files at once.
+Particularly useful for the creation of metanotes (read the
+manual for more on the matter)."
+  (interactive
+   (list (read-regexp "Insert links matching REGEX: ")))
+  (let* ((default-directory (denote-directory))
+         (ext (denote-link--file-type-format (buffer-file-name))))
+    (if-let ((files (denote--directory-files-matching-regexp regexp)))
+        (insert (denote-link--prepare-links files ext))
+      (user-error "No links matching `%s'" regexp))))
+
 (provide 'denote-link)
 ;;; denote-link.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]