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

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

[elpa] externals/denote d8ae24a80f 13/39: Merge branch 'main' into refac


From: ELPA Syncer
Subject: [elpa] externals/denote d8ae24a80f 13/39: Merge branch 'main' into refactor-denote-prompts
Date: Mon, 11 Jul 2022 00:57:44 -0400 (EDT)

branch: externals/denote
commit d8ae24a80f43783a24a6a4d93f67e4823e39743d
Merge: 95feac8448 6041e38ee5
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Merge branch 'main' into refactor-denote-prompts
---
 README.org      | 30 ++++++++++++++++++--
 denote-faces.el | 42 +++++++++++++++++++---------
 denote-link.el  |  2 +-
 denote.el       | 85 +++++++++++++++++++++++++++------------------------------
 4 files changed, 98 insertions(+), 61 deletions(-)

diff --git a/README.org b/README.org
index 4f7a6600ae..5b8f1dd5ec 100644
--- a/README.org
+++ b/README.org
@@ -612,6 +612,12 @@ Reproducing it here for the sake of convenience:
         (window-width . 0.3)))
 #+end_src
 
+Note that the backlinking facility uses Emacs' built-in Xref
+infrastructure.  On some operating systems, the user may need to add
+certain executables to the relevant environment variable.
+
+[[#h:42f6b07e-5956-469a-8294-17f9cf62eb2b][Why do I get "Search failed with 
status 1" when I search for backlinks?]]
+
 #+findex: denote-link-add-links
 The command ~denote-link-add-links~ adds links at point matching a
 regular expression or plain string.  The links are inserted as a
@@ -1630,6 +1636,25 @@ the file manager organise and provide access to files, 
search programs
 deal with searching and narrowing, and version control software handle
 the tracking of changes.
 
+** Why do I get "Search failed with status 1" when I search for backlinks?
+:PROPERTIES:
+:CUSTOM_ID: h:42f6b07e-5956-469a-8294-17f9cf62eb2b
+:END:
+
+Denote uses [[info:emacs#Xref][Emacs' Xref]] to find backlinks.  Xref requires 
~xargs~ and
+one of ~grep~ or ~ripgrep~, depending on your configuration.
+
+This is usually not an issue on *nix systems, but the necessary
+executables are not available on Windows Emacs distributions.  Please
+ensure that you have both ~xargs~ and either ~grep~ or ~ripgrep~
+available within your ~PATH~ environment variable.
+
+If you have ~git~ on Windows installed, then you may use the following
+code (adjust the git's installation path if necessary):
+#+begin_src emacs-lisp
+  (setenv "PATH" (concat (getenv "PATH") ";" "C:\\Program 
Files\\Git\\usr\\bin"))
+#+end_src
+
 * Acknowledgements
 :PROPERTIES:
 :CUSTOM_ID: h:f8126820-3b59-49fa-bcc2-73bd60132bb9
@@ -1640,8 +1665,9 @@ Denote is meant to be a collective effort.  Every bit of 
help matters.
 
 + Author/maintainer :: Protesilaos Stavrou.
 
-+ Contributions to code or the manual :: Damien Cassou, Jack Baty,
-  Jean-Philippe Gagné Guay, Kaushal Modi, Stefan Monnier.
++ Contributions to code or the manual :: Benjamin Kästner, Damien
+  Cassou, Jack Baty, Jean-Philippe Gagné Guay, Kaushal Modi, Stefan
+  Monnier.
 
 + Ideas and/or user feedback :: Benjamin Kästner, Colin McLear, Damien
   Cassou, Frank Ehmsen, Jack Baty, Kaushal Modi, M. Hadi Timachi, Peter
diff --git a/denote-faces.el b/denote-faces.el
index d19c913b1c..12e2220922 100644
--- a/denote-faces.el
+++ b/denote-faces.el
@@ -82,24 +82,40 @@ and seconds."
   "Face for file name delimiters in Dired buffers."
   :group 'denote-faces)
 
+(defvar denote-faces--file-name-regexp
+  (concat "\\(?1:[0-9]\\{8\\}\\)\\(?2:T[0-9]\\{6\\}\\)"
+          "\\(?:\\(?3:--\\)\\(?4:[0-9A-Za-z-]*\\)\\)?"
+          "\\(?:\\(?5:__\\)\\(?6:[0-9A-Za-z_-]*\\)\\)?"
+          "\\(?7:\\..*\\)?$")
+  "Regexp of file names for fontification.")
+
 (defconst denote-faces-file-name-keywords
-  `((,denote--file-regexp
+  `((,(concat " " denote-faces--file-name-regexp)
      (1 'denote-faces-date)
      (2 'denote-faces-time)
-     (3 'denote-faces-delimiter)
-     (4 'denote-faces-title)
-     (5 'denote-faces-delimiter)
-     (6 'denote-faces-keywords)
-     (7 'denote-faces-extension))
-    ("_"
-     (0 'denote-faces-delimiter t)))
+     (3 'denote-faces-delimiter nil t)
+     (4 'denote-faces-title nil t)
+     (5 'denote-faces-delimiter nil t)
+     (6 'denote-faces-keywords nil t)
+     (7 'denote-faces-extension nil t )))
   "Keywords for fontification of file names.")
 
-(defconst denote-faces-file-name-with-subdir-keywords
-  (append denote-faces-file-name-keywords
-          '(("\\(^.*/\\)?"
-             (0 'denote-faces-subdirectory))))
-  "Keywords for fontification of file names with a directory.")
+(define-obsolete-variable-alias
+  'denote-faces-file-name-with-subdir-keywords
+  'denote-faces-file-name-keywords-for-backlinks
+  "0.3.0")
+
+(defconst denote-faces-file-name-keywords-for-backlinks
+  `((,(concat "^\\(?8:.*/\\)?" denote-faces--file-name-regexp)
+     (8 'denote-faces-subdirectory nil t)
+     (1 'denote-faces-date)
+     (2 'denote-faces-time)
+     (3 'denote-faces-delimiter nil t)
+     (4 'denote-faces-title nil t)
+     (5 'denote-faces-delimiter nil t)
+     (6 'denote-faces-keywords nil t)
+     (7 'denote-faces-extension nil t )))
+  "Keywords for fontification of file names in the backlinks buffer.")
 
 (provide 'denote-faces)
 ;;; denote-faces.el ends here
diff --git a/denote-link.el b/denote-link.el
index 21f87f58de..2851d3cc7f 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -405,7 +405,7 @@ Use optional TITLE for a prettier heading."
             files)
       (goto-char (point-min))
       (when denote-link-fontify-backlinks
-        (font-lock-add-keywords nil 
denote-faces-file-name-with-subdir-keywords t)))
+        (font-lock-add-keywords nil 
denote-faces-file-name-keywords-for-backlinks t)))
     (denote-link--display-buffer buf)))
 
 ;;;###autoload
diff --git a/denote.el b/denote.el
index 6e353913be..19858a56e1 100644
--- a/denote.el
+++ b/denote.el
@@ -283,17 +283,14 @@ 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--file-title-regexp
-  (concat denote--id-regexp "\\(--\\)\\(.*\\)\\(__\\)")
-  "Regular expression to match file names from `denote'.")
+(defconst denote--title-regexp "--\\([0-9A-Za-z-]*\\)"
+  "Regular expression to match keywords.")
 
-(defconst denote--file-regexp
-  (concat denote--file-title-regexp "\\([0-9A-Za-z_-]*\\)\\(\\.?.*\\)")
-  "Regular expression to match the entire file name'.")
+(defconst denote--keywords-regexp "__\\([0-9A-Za-z_-]*\\)"
+  "Regular expression to match keywords.")
 
-(defconst denote--file-only-note-regexp
-  (concat denote--file-regexp "\\.\\(org\\|md\\|txt\\)")
-  "Regular expression to match the entire file name of a note file.")
+(defconst denote--extension-regexp "\\.\\(org\\|md\\|txt\\)"
+  "Regular expression to match supported Denote extensions.")
 
 (defconst denote--punctuation-regexp "[][{}!@#$%^&*()_=+'\"?,.\|;:~`‘’“”/]*"
   "Regular expression of punctionation that should be removed.
@@ -323,16 +320,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))
@@ -372,10 +359,13 @@ trailing hyphen."
 (defun denote--only-note-p (file)
   "Make sure FILE is an actual Denote note.
 FILE is relative to the variable `denote-directory'."
-  (and (not (file-directory-p file))
-       (file-regular-p file)
-       (string-match-p denote--file-only-note-regexp file)
-       (not (string-match-p "[#~]\\'" file))))
+  (let ((file-name (file-name-nondirectory file)))
+    (and (not (file-directory-p file))
+         (file-regular-p file)
+         (string-match-p (concat "\\`" denote--id-regexp
+                                 ".*" denote--extension-regexp "\\'")
+                         file-name)
+         (not (string-match-p "[#~]\\'" file)))))
 
 (defun denote--file-name-relative-to-denote-directory (file)
   "Return file name of FILE relative to the variable `denote-directory'.
@@ -439,24 +429,20 @@ 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))
+           (denote--directory-files))))
 
 (defun denote-keywords ()
   "Return appropriate list of keyword candidates.
@@ -510,16 +496,25 @@ output is sorted with `string-lessp'."
     ('text ".txt")
     (_ ".org")))
 
-(defun denote--format-file (path id keywords slug extension)
+(defun denote--format-file (path id keywords title-slug extension)
   "Format file name.
-PATH, ID, KEYWORDS, SLUG are expected to be supplied by `denote'
-or equivalent: they will all be converted into a single string.
-EXTENSION is the file type extension, either a string which
-include the starting dot or the return value of
+PATH, ID, KEYWORDS, TITLE-SLUG are expected to be supplied by
+`denote' or equivalent: they will all be converted into a single
+string.  EXTENSION is the file type extension, either a string
+which include the starting dot or the return value of
 `denote--file-extension'."
   (let ((kws (denote--keywords-combine keywords))
-        (ext (or extension (denote--file-extension))))
-    (format "%s%s--%s__%s%s" path id slug kws ext)))
+        (ext (or extension (denote--file-extension)))
+        (empty-title (string-empty-p title-slug)))
+    (cond
+     ((and keywords title-slug (not empty-title))
+      (format "%s%s--%s__%s%s" path id title-slug kws ext))
+     ((and keywords empty-title)
+      (format "%s%s__%s%s" path id kws ext))
+     ((and title-slug (not empty-title))
+      (format "%s%s--%s%s" path id title-slug ext))
+     (t
+      (format "%s%s%s" path id ext)))))
 
 (defun denote--map-quote-downcase (seq)
   "Quote and downcase elements in SEQ."



reply via email to

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