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

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

[elpa] externals/denote f193199c88 228/355: Insert generic format links


From: ELPA Syncer
Subject: [elpa] externals/denote f193199c88 228/355: Insert generic format links with prefix argument
Date: Sun, 26 Jun 2022 23:58:27 -0400 (EDT)

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

    Insert generic format links with prefix argument
---
 README.org     | 21 ++++++++++++++++++---
 denote-link.el | 39 ++++++++++++++++++++++++++++++---------
 2 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/README.org b/README.org
index 9282f532e4..a9bb47cfb5 100644
--- a/README.org
+++ b/README.org
@@ -581,12 +581,17 @@ participate in the development of Denote.
 *The linking facility is the only major area that needs to be reviewed
 before releasing the first stable version of Denote.*
 
+#+findex: denote-link
 The ~denote-link~ command inserts a link at point to an entry specified
 at the minibuffer prompt.  Links are formatted depending on the file
 type of current note.  In Org and plain text buffers, links are
 formatted thus: =[[denote:IDENTIFIER][TITLE]]=.  While in Markdown they
 are expressed as =[TITLE](denote:IDENTIFIER)=.
 
+When ~denote-link~ is called with a prefix argument (=C-u= by default)
+it formats links like =[[denote:IDENTIFIER]]=.  The user might prefer
+its simplicity.
+
 How those links behave will depend on the user's preference.  Denote
 provides a simple-minded implementation for such link, which either
 works competently with point-and-click kind of interaction or, at the
@@ -689,9 +694,19 @@ typographic list, such as:
 - link3
 #+end_example
 
-Each link is formatted according to the file type of the current note.
-The current note is excluded from the matching entries (adding a link to
-itself is pointless).
+Each link is formatted according to the file type of the current note,
+as explained further above about the ~denote-link~ command.  The current
+note is excluded from the matching entries (adding a link to itself is
+pointless).
+
+When called with a prefix argument (=C-u=) ~denote-link-add-links~ will
+format all links as =[[denote:IDENTIFIER]]=, hence a typographic list:
+
+#+begin_example
+- [[denote:IDENTIFIER-1]]
+- [[denote:IDENTIFIER-2]]
+- [[denote:IDENTIFIER-3]]
+#+end_example
 
 Same examples of a regular expression that can be used with this
 command:
diff --git a/denote-link.el b/denote-link.el
index ada84d252c..3bbf807136 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -97,6 +97,9 @@ and/or the documentation string of `display-buffer'."
 (defconst denote-link--format-markdown "[%2$s](denote:%1$s)"
   "Format of Markdown link to note.")
 
+(defconst denote-link--format-id-only "[[denote:%s]]"
+  "Format of identifier-only link to note.")
+
 (defconst denote-link--regexp-org
   (concat "\\[\\[" "denote:"  "\\(?1:" denote--id-regexp "\\)" "]" "\\[.*?]]"))
 
@@ -118,17 +121,30 @@ and/or the documentation string of `display-buffer'."
 (defun denote-link--format-link (file pattern)
   "Prepare link to FILE using PATTERN."
   (let* ((file-id (denote-retrieve--filename-identifier file))
-         (file-title (denote-retrieve--value-title file)))
+         (file-title (unless (string= pattern denote-link--format-id-only)
+                       (denote-retrieve--value-title file))))
     (format pattern file-id file-title)))
 
+(defun denote-link--extension-format-or-id (id-only)
+  "Determine format for link.
+If ID-ONLY is non-nil, use `denote-link--format-id-only', else
+delegate to `denote-link--file-type-format'."
+  (if id-only
+      denote-link--format-id-only
+    (denote-link--file-type-format (buffer-file-name))))
+
 ;;;###autoload
-(defun denote-link (target)
-  "Create link to TARGET note in variable `denote-directory'."
-  (interactive (list (denote-retrieve--read-file-prompt)))
+(defun denote-link (target &optional id-only)
+  "Create link to TARGET note in variable `denote-directory'.
+With optional ID-ONLY, such as a universal prefix
+argument (\\[universal-argument]), insert links with just the
+identifier and no further description.  In this case, the link
+format is always [[denote:IDENTIFIER]]."
+  (interactive (list (denote-retrieve--read-file-prompt) current-prefix-arg))
   (insert
    (denote-link--format-link
     target
-    (denote-link--file-type-format (buffer-file-name)))))
+   (denote-link--extension-format-or-id id-only))))
 
 (defalias 'denote-link-insert-link (symbol-function 'denote-link))
 
@@ -269,15 +285,20 @@ default, it will show up below the current window."
   "Minibuffer history for `denote-link-add-links'.")
 
 ;;;###autoload
-(defun denote-link-add-links (regexp)
+(defun denote-link-add-links (regexp &optional id-only)
   "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)."
+manual for more on the matter).
+
+Optional ID-ONLY has the same meaning as in `denote-link': it
+inserts links with just the identifier."
   (interactive
-   (list (read-regexp "Insert links matching REGEX: " nil 
'denote-link--add-links-history)))
+   (list
+    (read-regexp "Insert links matching REGEX: " nil 
'denote-link--add-links-history)
+    current-prefix-arg))
   (let* ((default-directory (denote-directory))
-         (ext (denote-link--file-type-format (buffer-file-name))))
+         (ext (denote-link--extension-format-or-id id-only)))
     (if-let ((files (denote--directory-files-matching-regexp regexp)))
         (insert (denote-link--prepare-links files ext))
       (user-error "No links matching `%s'" regexp))))



reply via email to

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