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

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

[elpa] externals/denote 36440d7b7d: Refine front matter rewrite


From: ELPA Syncer
Subject: [elpa] externals/denote 36440d7b7d: Refine front matter rewrite
Date: Sun, 24 Jul 2022 20:57:31 -0400 (EDT)

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

    Refine front matter rewrite
    
    This should avoid false positives by anchoring the search at the
    relevant front matter key.
    
    The code is broken into smaller parts for easier hacking.
    
    This change should address the bug with false positives reported by
    hpgisler in issue 63 on the GitHub mirror:
    <https://github.com/protesilaos/denote/issues/63>.
---
 denote-dired.el    | 28 +++++++++++++++++++++-------
 denote-retrieve.el |  3 +++
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/denote-dired.el b/denote-dired.el
index d990169ee4..8ece6de42b 100644
--- a/denote-dired.el
+++ b/denote-dired.el
@@ -282,6 +282,25 @@ replace what isn't there."
          ;; Heuristic to check if this is one of our notes
          (string= (expand-file-name default-directory) (denote-directory)))))
 
+;; FIXME 2022-07-25: We should make the underlying regular expressions
+;; that `denote-retrieve--value-title' targets more refined, so that we
+;; capture eveyrhing at once.
+(defun denote-dired--rewrite-title (file old new)
+  "Rewrite OLD front matter of title to NEW value in FILE."
+  (save-excursion
+    (goto-char (point-min))
+    (re-search-forward denote-retrieve--title-front-matter-key-regexp nil t 1)
+    (search-forward old nil t 1)
+    (replace-match (concat "\\1" new) t)))
+
+(defun denote-dired--rewrite-keywords (file old new)
+  "Rewrite OLD front matter of keywords to NEW value in FILE."
+  (save-excursion
+    (goto-char (point-min))
+    (re-search-forward denote-retrieve--keywords-front-matter-key-regexp nil t 
1)
+    (search-forward old nil t 1)
+    (replace-match (concat "\\1" new) t)))
+
 (defun denote-dired--rewrite-front-matter (file title keywords)
   "Rewrite front matter of note after `denote-dired-rename-file'.
 The FILE, TITLE, and KEYWORDS are passed from the renaming
@@ -302,13 +321,8 @@ appropriate."
                          (propertize new-title 'face 'success)
                          (propertize old-keywords 'face 'error)
                          (propertize new-keywords 'face 'success)))
-          (save-excursion
-            (goto-char (point-min))
-            (search-forward old-title nil t 1)
-            (replace-match (concat "\\1" new-title) t)
-            (goto-char (point-min))
-            (search-forward old-keywords nil t 1)
-            (replace-match (concat "\\1" new-keywords) t)))))))
+          (denote-dired--rewrite-title file old-title new-title)
+          (denote-dired--rewrite-keywords file old-keywords new-keywords))))))
 
 (defun denote-dired--add-front-matter (file title keywords id)
   "Add front matter to the beginning of FILE.
diff --git a/denote-retrieve.el b/denote-retrieve.el
index fd21df0453..0e6ef21f86 100644
--- a/denote-retrieve.el
+++ b/denote-retrieve.el
@@ -33,6 +33,9 @@
 (require 'denote)
 (require 'xref)
 
+;; FIXME 2022-07-25: We must review these.  When we need to move in the
+;; buffer, we should capture both the key and its value at once.  Check
+;; `denote-dired--rewrite-front-matter'.
 (defconst denote-retrieve--title-front-matter-key-regexp
   "^\\(?:#\\+\\)?\\(?:title\\)\\s-*[:=]"
   "Regular expression for title key.")



reply via email to

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