denote lazy loading
This commit is contained in:
parent
3c81cb004a
commit
4ca76053d2
|
|
@ -9,21 +9,23 @@
|
||||||
|
|
||||||
(require 'module-denote)
|
(require 'module-denote)
|
||||||
|
|
||||||
(defvar my/denote-metadata-index-file (concat denote-directory "../denote-metadata.org")
|
(with-eval-after-load 'denote
|
||||||
|
|
||||||
|
(defvar my/denote-metadata-index-file (concat denote-directory "../denote-metadata.org")
|
||||||
"Path to the metadata index file.")
|
"Path to the metadata index file.")
|
||||||
|
|
||||||
(defun my/extract-date-from-filename (file)
|
(defun my/extract-date-from-filename (file)
|
||||||
"Extract date from FILE name. Assumes first 8 characters are YYYYMMDD."
|
"Extract date from FILE name. Assumes first 8 characters are YYYYMMDD."
|
||||||
(substring (file-name-nondirectory file) 0 8))
|
(substring (file-name-nondirectory file) 0 8))
|
||||||
|
|
||||||
(defun my/format-date (date-string)
|
(defun my/format-date (date-string)
|
||||||
"Format DATE-STRING (YYYYMMDD) as YYYY-MM-DD."
|
"Format DATE-STRING (YYYYMMDD) as YYYY-MM-DD."
|
||||||
(format "%s-%s-%s"
|
(format "%s-%s-%s"
|
||||||
(substring date-string 0 4)
|
(substring date-string 0 4)
|
||||||
(substring date-string 4 6)
|
(substring date-string 4 6)
|
||||||
(substring date-string 6 8)))
|
(substring date-string 6 8)))
|
||||||
|
|
||||||
(defun my/extract-summary (file)
|
(defun my/extract-summary (file)
|
||||||
"Extract summary from FILE."
|
"Extract summary from FILE."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents file)
|
(insert-file-contents file)
|
||||||
|
|
@ -35,7 +37,7 @@
|
||||||
(string-trim (buffer-substring-no-properties start (line-beginning-position)))
|
(string-trim (buffer-substring-no-properties start (line-beginning-position)))
|
||||||
(string-trim (buffer-substring-no-properties start (point-max))))))))
|
(string-trim (buffer-substring-no-properties start (point-max))))))))
|
||||||
|
|
||||||
(defun my/update-denote-metadata-index ()
|
(defun my/update-denote-metadata-index ()
|
||||||
"Update the metadata index for Denote notes in Org format."
|
"Update the metadata index for Denote notes in Org format."
|
||||||
(interactive)
|
(interactive)
|
||||||
(with-temp-file my/denote-metadata-index-file
|
(with-temp-file my/denote-metadata-index-file
|
||||||
|
|
@ -72,7 +74,7 @@
|
||||||
(insert "\n\n"))))))))))
|
(insert "\n\n"))))))))))
|
||||||
|
|
||||||
|
|
||||||
(defun my/search-denote-notes ()
|
(defun my/search-denote-notes ()
|
||||||
"Use consult-ripgrep to search only the Denote metadata index file."
|
"Use consult-ripgrep to search only the Denote metadata index file."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((index-file my/denote-metadata-index-file)
|
(let* ((index-file my/denote-metadata-index-file)
|
||||||
|
|
@ -87,7 +89,7 @@
|
||||||
(consult-ripgrep default-directory)
|
(consult-ripgrep default-directory)
|
||||||
(message "Metadata index file not found: %s" index-file))))
|
(message "Metadata index file not found: %s" index-file))))
|
||||||
|
|
||||||
(global-set-key (kbd "C-x n /") #'my/search-denote-notes)
|
(global-set-key (kbd "C-x n /") #'my/search-denote-notes))
|
||||||
|
|
||||||
(provide 'module-denote-index)
|
(provide 'module-denote-index)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,16 @@
|
||||||
(require 'module-denote-index)
|
(require 'module-denote-index)
|
||||||
(require 'module-alioth) ;; depends on alioth for some functions
|
(require 'module-alioth) ;; depends on alioth for some functions
|
||||||
|
|
||||||
(defvar my/denote-local-notes-directory "~/notes/")
|
(autoload 'my/denote-create-note "denote" nil t)
|
||||||
(defvar my/denote-remote-notes-directory "~/alioth/notes/")
|
|
||||||
|
|
||||||
(setq denote-directory my/denote-local-notes-directory)
|
(with-eval-after-load 'denote
|
||||||
|
|
||||||
(defun my/denote-open-or-create ()
|
(defvar my/denote-local-notes-directory "~/notes/")
|
||||||
|
(defvar my/denote-remote-notes-directory "~/alioth/notes/")
|
||||||
|
|
||||||
|
(setq denote-directory my/denote-local-notes-directory)
|
||||||
|
|
||||||
|
(defun my/denote-open-or-create ()
|
||||||
"Ensure alioth is mounted before creating or opening a note."
|
"Ensure alioth is mounted before creating or opening a note."
|
||||||
(interactive)
|
(interactive)
|
||||||
(ensure-alioth-mounted)
|
(ensure-alioth-mounted)
|
||||||
|
|
@ -24,18 +28,18 @@
|
||||||
(find-file target)
|
(find-file target)
|
||||||
(denote--command-with-features (denote-command-prompt) :use-file-prompt-as-def-title nil nil nil))))
|
(denote--command-with-features (denote-command-prompt) :use-file-prompt-as-def-title nil nil nil))))
|
||||||
|
|
||||||
(defun my/denote-echo-current-directory ()
|
(defun my/denote-echo-current-directory ()
|
||||||
"Echo the current value of denote-directory."
|
"Echo the current value of denote-directory."
|
||||||
(declare (interactive-only t))
|
(declare (interactive-only t))
|
||||||
(interactive)
|
(interactive)
|
||||||
(message "Current Denote directory: %s" denote-directory))
|
(message "Current Denote directory: %s" denote-directory))
|
||||||
|
|
||||||
(defun my/denote-directory-segment ()
|
(defun my/denote-directory-segment ()
|
||||||
"Return the current Denote directory for the mode line."
|
"Return the current Denote directory for the mode line."
|
||||||
(when (bound-and-true-p denote-directory)
|
(when (bound-and-true-p denote-directory)
|
||||||
(format " Denote:%s " (file-name-nondirectory (directory-file-name denote-directory)))))
|
(format " Denote:%s " (file-name-nondirectory (directory-file-name denote-directory)))))
|
||||||
|
|
||||||
(defun my/denote-switch-directory ()
|
(defun my/denote-switch-directory ()
|
||||||
"Switch current denote working directory."
|
"Switch current denote working directory."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((new-dir (if (string= denote-directory my/denote-local-notes-directory)
|
(let ((new-dir (if (string= denote-directory my/denote-local-notes-directory)
|
||||||
|
|
@ -45,7 +49,7 @@
|
||||||
(setq my/denote-metadata-index-file (concat denote-directory "../denote-metadata.org"))
|
(setq my/denote-metadata-index-file (concat denote-directory "../denote-metadata.org"))
|
||||||
(message "Denote directory switched to %s" new-dir)))
|
(message "Denote directory switched to %s" new-dir)))
|
||||||
|
|
||||||
(defun my/denote-use-both-directories (orig-fun &rest args)
|
(defun my/denote-use-both-directories (orig-fun &rest args)
|
||||||
"Temporarily use both directories for a given ORIG-FUN and ARGS."
|
"Temporarily use both directories for a given ORIG-FUN and ARGS."
|
||||||
(let ((original-dir denote-directory)
|
(let ((original-dir denote-directory)
|
||||||
(result nil))
|
(result nil))
|
||||||
|
|
@ -56,7 +60,7 @@
|
||||||
(setq denote-directory original-dir)
|
(setq denote-directory original-dir)
|
||||||
result))
|
result))
|
||||||
|
|
||||||
(defun my/denote-create-note ()
|
(defun my/denote-create-note ()
|
||||||
"Create a note in directory of choice."
|
"Create a note in directory of choice."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((dirs (list my/denote-local-notes-directory my/denote-remote-notes-directory))
|
(let* ((dirs (list my/denote-local-notes-directory my/denote-remote-notes-directory))
|
||||||
|
|
@ -64,15 +68,15 @@
|
||||||
(let ((denote-directory chosen-dir))
|
(let ((denote-directory chosen-dir))
|
||||||
(call-interactively #'denote))))
|
(call-interactively #'denote))))
|
||||||
|
|
||||||
(advice-add 'denote-directory-files
|
(advice-add 'denote-directory-files
|
||||||
:around #'my/denote-use-both-directories)
|
:around #'my/denote-use-both-directories)
|
||||||
(advice-add 'denote-directory-subdirectories
|
(advice-add 'denote-directory-subdirectories
|
||||||
:around #'my/denote-use-both-directories)
|
:around #'my/denote-use-both-directories)
|
||||||
|
|
||||||
(global-set-key (kbd "C-x n f") #'my/denote-open-or-create)
|
(global-set-key (kbd "C-x n f") #'my/denote-open-or-create)
|
||||||
(global-set-key (kbd "C-x n n") #'my/denote-create-note)
|
(global-set-key (kbd "C-x n n") #'my/denote-create-note)
|
||||||
(global-set-key (kbd "C-x n d s") #'my/denote-switch-directory)
|
(global-set-key (kbd "C-x n d s") #'my/denote-switch-directory)
|
||||||
(global-set-key (kbd "C-x n d d") #'my/denote-echo-current-directory)
|
(global-set-key (kbd "C-x n d d") #'my/denote-echo-current-directory))
|
||||||
|
|
||||||
(provide 'module-denote-multidir)
|
(provide 'module-denote-multidir)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,11 @@
|
||||||
|
|
||||||
(pkg/require 'denote)
|
(pkg/require 'denote)
|
||||||
|
|
||||||
(denote-rename-buffer-mode 1)
|
(with-eval-after-load 'denote
|
||||||
|
|
||||||
(setq denote-save-buffers nil
|
(denote-rename-buffer-mode 1)
|
||||||
|
|
||||||
|
(setq denote-save-buffers nil
|
||||||
denote-known-keywords '("emacs" "golang" "dev")
|
denote-known-keywords '("emacs" "golang" "dev")
|
||||||
denote-infer-keywords t
|
denote-infer-keywords t
|
||||||
denote-sort-keywords t
|
denote-sort-keywords t
|
||||||
|
|
@ -27,26 +29,27 @@
|
||||||
denote-date-format nil
|
denote-date-format nil
|
||||||
denote-backlinks-show-context t)
|
denote-backlinks-show-context t)
|
||||||
|
|
||||||
(global-unset-key (kbd "C-x n"))
|
(global-unset-key (kbd "C-x n"))
|
||||||
(global-set-key (kbd "C-x n c") #'denote-region)
|
(global-set-key (kbd "C-x n n") #'denote)
|
||||||
(global-set-key (kbd "C-x n !") #'denote-date)
|
(global-set-key (kbd "C-x n c") #'denote-region)
|
||||||
(global-set-key (kbd "C-x n z") #'denote-signature)
|
(global-set-key (kbd "C-x n !") #'denote-date)
|
||||||
(global-set-key (kbd "C-x n s") #'denote-subdirectory)
|
(global-set-key (kbd "C-x n z") #'denote-signature)
|
||||||
(global-set-key (kbd "C-x n S-n") #'denote-type)
|
(global-set-key (kbd "C-x n s") #'denote-subdirectory)
|
||||||
(global-set-key (kbd "C-x n t") #'denote-template)
|
(global-set-key (kbd "C-x n S-n") #'denote-type)
|
||||||
(global-set-key (kbd "C-x n l l") #'denote-link)
|
(global-set-key (kbd "C-x n t") #'denote-template)
|
||||||
(global-set-key (kbd "C-x n l a") #'denote-add-links)
|
(global-set-key (kbd "C-x n l l") #'denote-link)
|
||||||
(global-set-key (kbd "C-x n l f") #'denote-find-link)
|
(global-set-key (kbd "C-x n l a") #'denote-add-links)
|
||||||
(global-set-key (kbd "C-x n b l") #'denote-backlinks)
|
(global-set-key (kbd "C-x n l f") #'denote-find-link)
|
||||||
(global-set-key (kbd "C-x n b f") #'denote-find-backlink)
|
(global-set-key (kbd "C-x n b l") #'denote-backlinks)
|
||||||
(global-set-key (kbd "C-x n r r") #'denote-rename-file)
|
(global-set-key (kbd "C-x n b f") #'denote-find-backlink)
|
||||||
(global-set-key (kbd "C-x n r f") #'denote-rename-file-using-front-matter)
|
(global-set-key (kbd "C-x n r r") #'denote-rename-file)
|
||||||
(let ((map dired-mode-map))
|
(global-set-key (kbd "C-x n r f") #'denote-rename-file-using-front-matter)
|
||||||
|
(let ((map dired-mode-map))
|
||||||
(define-key map (kbd "C-x n d") #'denote-dired-mode)
|
(define-key map (kbd "C-x n d") #'denote-dired-mode)
|
||||||
(define-key map (kbd "C-x n i") #'denote-link-dired-marked-notes)
|
(define-key map (kbd "C-x n i") #'denote-link-dired-marked-notes)
|
||||||
(define-key map (kbd "C-x n k") #'denote-dired-rename-marked-files-with-keywords)
|
(define-key map (kbd "C-x n k") #'denote-dired-rename-marked-files-with-keywords)
|
||||||
(define-key map (kbd "C-x n r r") #'denote-dired-rename-files)
|
(define-key map (kbd "C-x n r r") #'denote-dired-rename-files)
|
||||||
(define-key map (kbd "C-x n r f") #'denote-dired-rename-marked-files-using-front-matter))
|
(define-key map (kbd "C-x n r f") #'denote-dired-rename-marked-files-using-front-matter)))
|
||||||
|
|
||||||
|
|
||||||
(provide 'module-denote)
|
(provide 'module-denote)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue