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

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

[elpa] externals/denote 9dbfd371ff 02/14: Refactor of denote--inferred-k


From: ELPA Syncer
Subject: [elpa] externals/denote 9dbfd371ff 02/14: Refactor of denote--inferred-keywords
Date: Sat, 9 Jul 2022 02:57:35 -0400 (EDT)

branch: externals/denote
commit 9dbfd371ff155e7c9c899ebeba56d231fa187cd1
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>

    Refactor of denote--inferred-keywords
    
    denote--inferred-keywords now delete duplicates.
    Removal of denote--keywords-in-files.
    Refactor denote--extract into denote--extract-keywords-from-path.
---
 denote.el | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/denote.el b/denote.el
index eb5aec037a..f971fb4e6a 100644
--- a/denote.el
+++ b/denote.el
@@ -239,6 +239,9 @@ are described in the doc string of `format-time-string'."
 (defconst denote--id-regexp "\\([0-9]\\{8\\}\\)\\(T[0-9]\\{6\\}\\)"
   "Regular expression to match `denote--id-format'.")
 
+(defconst denote--keywords-regexp "__\\([0-9A-Za-z_-]*\\)"
+  "Regular expression to match keywords.")
+
 (defconst denote--file-title-regexp
   (concat denote--id-regexp "\\(--\\)\\(.*\\)\\(__\\)")
   "Regular expression to match file names from `denote'.")
@@ -279,16 +282,6 @@ We consider those characters illigal for our purposes.")
       (make-directory path t))
     (file-name-as-directory path)))
 
-(defun denote--extract (regexp str &optional group)
-  "Extract REGEXP from STR, with optional regexp GROUP."
-  (when group
-    (unless (and (integerp group) (> group 0))
-      (error "`%s' is not a positive integer" group)))
-  (with-temp-buffer
-    (insert str)
-    (when (re-search-forward regexp nil t -1)
-      (match-string (or group 1)))))
-
 (defun denote--slug-no-punct (str)
   "Convert STR to a file name slug."
   (replace-regexp-in-string denote--punctuation-regexp "" str))
@@ -395,24 +388,25 @@ part of the list."
         f))
     (denote--directory-files))))
 
-(defun denote--keywords-in-files ()
-  "Produce list of keywords in `denote--directory-files'."
-  (delq nil (mapcar
-             (lambda (x)
-               (denote--extract denote--file-regexp x 6))
-             ;; REVIEW 2022-07-03: I tested this with ~3000 files.  It
-             ;; has about 2 seconds of delay on my end.  After I placed
-             ;; the list of those files in a variable instead of calling
-             ;; `denote--directory-files', there was no noticeable
-             ;; performance penalty.
-             (denote--directory-files))))
+(defun denote--extract-keywords-from-path (path)
+  "Extract keywords from PATH."
+  (let* ((file-name (file-name-nondirectory path))
+         (kws (when (string-match denote--keywords-regexp file-name)
+                (match-string-no-properties 1 file-name))))
+    (when kws
+      (split-string kws "_"))))
 
 (defun denote--inferred-keywords ()
   "Extract keywords from `denote--directory-files'."
-  (let ((sequence (denote--keywords-in-files)))
-    (mapcan (lambda (s)
-              (split-string s "_" t))
-            sequence)))
+  (delete-dups
+   (mapcan (lambda (p)
+             (denote--extract-keywords-from-path p))
+           ;; REVIEW 2022-07-03: I tested this with ~3000 files.  It
+           ;; has about 2 seconds of delay on my end.  After I placed
+           ;; the list of those files in a variable instead of calling
+           ;; `denote--directory-files', there was no noticeable
+           ;; performance penalty.
+           (denote--directory-files))))
 
 (defun denote-keywords ()
   "Return appropriate list of keyword candidates.



reply via email to

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