branch: externals/denote
commit ee22a7f380a5e7c2763fb5db8e6f576015e8071c
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Add helper function for line predicates
---
denote.el | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/denote.el b/denote.el
index 71ddc9486d..99059e7626 100644
--- a/denote.el
+++ b/denote.el
@@ -143,6 +143,29 @@ trailing hyphen."
"Return non-nil if FILE is empty."
(zerop (or (file-attribute-size (file-attributes file)) 0)))
+(defvar denote--line-regexp-alist
+ '((empty . "[\s\t]*$")
+ (indent . "^[\s\t]+")
+ (non-empty . "^.+$")
+ (list . "^\\([\s\t#*+]+\\|[0-9]+[^\s]?[).]+\\)")
+ (heading . "^\\*+ +")) ; assumes Org markup
+ "Alist of regexp types used by `denote-line-regexp-p'.")
+
+(defun denote--line-regexp-p (type &optional n)
+ "Test for TYPE on line.
+TYPE is the car of a cons cell in
+`denote--line-regexp-alist'. It matches a regular
+expression.
+
+With optional N, search in the Nth line from point."
+ (save-excursion
+ (goto-char (point-at-bol))
+ (and (not (bobp))
+ (or (beginning-of-line n) t)
+ (save-match-data
+ (looking-at
+ (alist-get type denote--line-regexp-alist))))))
+
;;;; Keywords
(defun denote--directory-files ()