branch: externals/org-mem
commit 82d613cabbe83e3f79e7825e51408a49840c1314
Author: Martin Edström <[email protected]>
Commit: Martin Edström <[email protected]>
Add command org-mem-list-example
Taken mostly verbatim from org-node-list-example
(which will now be an alias).
---
org-mem-list.el | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 138 insertions(+)
diff --git a/org-mem-list.el b/org-mem-list.el
index 0e251ceff4..0e7702f477 100644
--- a/org-mem-list.el
+++ b/org-mem-list.el
@@ -218,6 +218,144 @@ instead of default `org-mem-roamy--connection'."
(sqlite-mode-list-tables))
(message "No DB yet")))))
+
+(defvar org-mem--elisp-scratch :never-nil)
+(defun org-mem--prin1-to-fontified (value &optional is-raw-string)
+ (cl-assert (eq (current-buffer) org-mem--elisp-scratch))
+ (erase-buffer)
+ (if is-raw-string (insert value)
+ (prin1 value (current-buffer) '((length . 50) (level . 2))))
+ (font-lock-fontify-region (point-min) (point-max))
+ (buffer-string))
+
+;;;###autoload
+(defun org-mem-list-example (&optional entry)
+ "Display data from ENTRY, or a random member of `org-mem-all-entries'.
+See also command `org-mem-entry-at-point'."
+ (interactive)
+ (let ((entry (or entry (seq-random-elt (org-mem-all-entries))))
+ (entry-funs '(org-mem-entry-active-timestamps
+ org-mem-entry-active-timestamps-int
+ org-mem-entry-children
+ org-mem-entry-clocks
+ org-mem-entry-clocks-int
+ org-mem-entry-closed
+ org-mem-entry-closed-int
+ org-mem-entry-dangling-clocks
+ org-mem-entry-deadline
+ org-mem-entry-deadline-int
+ org-mem-entry-file
+ org-mem-entry-file-truename
+ org-mem-entry-id
+ org-mem-entry-keywords
+ org-mem-entry-level
+ org-mem-entry-lnum
+ org-mem-entry-olpath
+ org-mem-entry-olpath-with-file-title
+ org-mem-entry-olpath-with-file-title-or-basename
+ org-mem-entry-olpath-with-self
+ org-mem-entry-olpath-with-self-with-file-title
+
org-mem-entry-olpath-with-self-with-file-title-or-basename
+ org-mem-entry-pos
+ org-mem-entry-priority
+ org-mem-entry-properties-inherited
+ org-mem-entry-properties-local
+ org-mem-entry-pseudo-id
+ org-mem-entry-roam-aliases
+ org-mem-entry-roam-refs
+ org-mem-entry-scheduled
+ org-mem-entry-scheduled-int
+ org-mem-entry-stats-cookies
+ org-mem-entry-subtree-p
+ org-mem-entry-tags
+ org-mem-entry-tags-inherited
+ org-mem-entry-tags-local
+ org-mem-entry-text
+ org-mem-entry-title
+ org-mem-entry-title-maybe
+ org-mem-entry-todo-state
+ org-mem-id-links-to-entry
+ org-mem-links-in-entry
+ org-mem-next-entry
+ org-mem-previous-entry
+ org-mem-roam-reflinks-to-entry))
+ (file-funs '(org-mem-entries-in-file
+ org-mem-file-attributes
+ org-mem-file-char-count
+ org-mem-file-coding-system
+ org-mem-file-id-strict
+ org-mem-file-id-topmost
+ org-mem-file-keywords
+ org-mem-file-known-p
+ org-mem-file-line-count
+ org-mem-file-mtime
+ org-mem-file-mtime-floor
+ org-mem-file-ptmax
+ org-mem-file-size
+ org-mem-file-title-or-basename
+ org-mem-file-title-strict
+ org-mem-file-title-topmost)))
+
+ (pop-to-buffer (get-buffer-create "*org-mem example*" t))
+ ;; (window-tool-bar-mode)
+ ;; (keymap-set tool-bar-map )
+ (setq-local buffer-read-only t)
+ (setq-local revert-buffer-function (lambda (&rest _)
(org-mem-list-example)))
+ (keymap-local-set "g" #'revert-buffer-quick)
+ (keymap-local-set "q" #'quit-window)
+ (keymap-local-set "n" (lambda ()
+ (interactive)
+ (when (org-mem-next-entry entry)
+ (org-mem-list-example (org-mem-next-entry
entry)))))
+ (keymap-local-set "p" (lambda ()
+ (interactive)
+ (when (org-mem-previous-entry entry)
+ (org-mem-list-example (org-mem-previous-entry
entry)))))
+ (let ((buffer-read-only nil)
+ (win-start-line (line-number-at-pos (window-start)))
+ (win-line (line-number-at-pos)))
+ (erase-buffer)
+ (insert "Example data taken from entry titled \""
+ (org-mem-entry-title entry) "\"\n"
+ "Type g for a random entry.\n"
+ "Type n or p for next/previous entry in same file.\n\n")
+ ;; Use a persistent "temp buffer" so we can really spam this command.
+ (unless (buffer-live-p org-mem--elisp-scratch)
+ (setq org-mem--elisp-scratch (get-buffer-create "
*org-mem-elisp-scratch*" t))
+ (with-current-buffer org-mem--elisp-scratch
+ (emacs-lisp-mode))
+ (run-with-idle-timer 5 nil #'kill-buffer org-mem--elisp-scratch))
+ (mapc #'insert
+ (with-current-buffer org-mem--elisp-scratch
+ (cl-loop
+ for func in entry-funs
+ nconc (list (string-pad (concat "(" (propertize (symbol-name
func)
+ 'face
'font-lock-function-call-face)
+ " ENTRY)")
+ 67)
+ " => "
+ (org-mem--prin1-to-fontified (funcall func entry))
+ "\n"))))
+ (newline)
+ (mapc #'insert
+ (with-current-buffer org-mem--elisp-scratch
+ (cl-loop
+ with file = (org-mem-entry-file entry)
+ for func in file-funs
+ nconc (list (string-pad (concat
+ "(" (propertize (symbol-name func)
'face 'font-lock-function-call-face)
+ " (" (propertize "org-mem-entry-file"
'face 'font-lock-function-call-face)
+ " ENTRY))")
+ 60)
+ " => "
+ (org-mem--prin1-to-fontified (funcall func file))
+ "\n"))))
+ ;; Restore scroll position
+ (goto-char (point-min))
+ (forward-line (- win-start-line 1))
+ (set-window-start (selected-window) (point))
+ (forward-line (- win-line win-start-line)))))
+
(provide 'org-mem-list)
;;; org-mem-list.el ends here