From ddaf855b5d625c8c9a740c486aeaaaf093fb8acc Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Thu, 20 Feb 2020 13:38:31 +0800 Subject: [PATCH] (chore): some cleanups (#139) * move org-roam-switch-to-buffer * add org-roam-switch-to-buffer to docs * Update changelog --- CHANGELOG.md | 17 ++++++++++++++--- README.md | 1 + doc/installation.md | 2 ++ org-roam.el | 41 ++++++++++++++++++++--------------------- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3038d98..8b16148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,22 +10,28 @@ * [#103][gh-103] Change `org-roam-file-format` to a function: `org-roam-file-name-function` to allow more flexible file name customizaton. Also changes `org-roam-use-timestamp-as-filename` to `org-roam-filename-noconfirm` to better describe what it does. ### New Features -* [#124](https://github.com/jethrokuan/org-roam/pull/124) Maintain cache consistency on file rename +* [#138][gh-138] add `org-roam-switch-to-buffer` +* [#124][gh-124] Maintain cache consistency on file rename * [#87][gh-87], [#90][gh-90] Support encrypted Org files * [#110][gh-110] Add prefix to `org-roam-insert`, for inserting titles down-cased -* [#99](https://github.com/jethrokuan/org-roam/pull/99) Add keybinding so that `` or `mouse-1` in the backlinks buffer visits the source file of the backlink at point +* [#99][gh-99] Add keybinding so that `` or `mouse-1` in the backlinks buffer visits the source file of the backlink at point ### Bugfixes * [#86][gh-86] Fix `org-roam--parse-content` incorrect `:to` computation for nested files * [#98][gh-98] Fix `org-roam--find-file` picking up temporary files +* [#136][gh-136] Misc bugfixes ### Internal -* [#92][gh-92], [#105][gh-105]: Add tests for core functionality +* [#122][gh-122], [#128][gh-128] Improve performance of post-command-hook +* [#92][gh-92], [#105][gh-105] Add tests for core functionality ### Contributors * [@chip2n](https://github.com/chip2n/) * [@l3kn](https://github.com/l3kn/) * [@jdormit](https://github.com/jdormit) +* [@herbertjones](https://github.com/herbertjones) +* [@CeleritasCelery](https://github.com/CeleritasCelery) +* [@daniel-koudouna](https://github.com/daniel-koudouna) ## 0.1.1 (2020-02-15) @@ -63,10 +69,15 @@ Mostly a documentation/cleanup release. [gh-90]: https://github.com/jethrokuan/org-roam/pull/90 [gh-92]: https://github.com/jethrokuan/org-roam/pull/92 [gh-98]: https://github.com/jethrokuan/org-roam/pull/98 +[gh-99]: https://github.com/jethrokuan/org-roam/pull/99 [gh-103]: https://github.com/jethrokuan/org-roam/pull/103 [gh-105]: https://github.com/jethrokuan/org-roam/pull/105 [gh-108]: https://github.com/jethrokuan/org-roam/pull/108 [gh-110]: https://github.com/jethrokuan/org-roam/pull/110 +[gh-122]: https://github.com/jethrokuan/org-roam/pull/122 +[gh-128]: https://github.com/jethrokuan/org-roam/pull/128 +[gh-136]: https://github.com/jethrokuan/org-roam/pull/136 +[gh-138]: https://github.com/jethrokuan/org-roam/pull/138 # Local Variables: # eval: (auto-fill-mode -1) diff --git a/README.md b/README.md index b99a8c3..b8286ba 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ The recommended method is using use-package and straight, or a similar package m ("C-c n l" . org-roam) ("C-c n t" . org-roam-today) ("C-c n f" . org-roam-find-file) + ("C-c n b" . org-roam-switch-to-buffer) ("C-c n i" . org-roam-insert) ("C-c n g" . org-roam-show-graph)) ``` diff --git a/doc/installation.md b/doc/installation.md index 9a7879d..f5a7896 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -17,6 +17,7 @@ The recommended method is using [use-package][use-package] and ("C-c n l" . org-roam) ("C-c n t" . org-roam-today) ("C-c n f" . org-roam-find-file) + ("C-c n b" . org-roam-switch-to-buffer) ("C-c n i" . org-roam-insert) ("C-c n g" . org-roam-show-graph)) ``` @@ -42,6 +43,7 @@ git clone https://github.com/jethrokuan/org-roam/ ~/.emacs.d/elisp/org-roam ("C-c n l" . org-roam) ("C-c n t" . org-roam-today) ("C-c n f" . org-roam-find-file) + ("C-c n b" . org-roam-switch-to-buffer) ("C-c n i" . org-roam-insert) ("C-c n g" . org-roam-show-graph)) ``` diff --git a/org-roam.el b/org-roam.el index 62c1685..868aeb5 100644 --- a/org-roam.el +++ b/org-roam.el @@ -317,6 +317,26 @@ If PREFIX, downcase the title before insertion." (org-roam--make-file absolute-file-path title-or-slug)) (find-file absolute-file-path))) +(defun org-roam-switch-to-buffer () + "Switch to an existing org-roam buffer using completing-read." + (interactive) + (let* ((all-buffers (buffer-list)) + (roam-buffers + (--filter (and (with-current-buffer it (derived-mode-p 'org-mode)) + (buffer-file-name it) + (org-roam--org-roam-file-p (buffer-file-name it))) + all-buffers)) + (names-and-buffers (mapcar (lambda (buffer) + (cons (or (org-roam--get-title-from-cache + (buffer-file-name buffer)) + (buffer-name buffer)) + buffer)) + roam-buffers))) + (unless roam-buffers + (error "No roam buffers.")) + (when-let ((name (completing-read "Choose a buffer: " names-and-buffers))) + (switch-to-buffer (cdr (assoc name names-and-buffers)))))) + ;;; Building the org-roam cache (defun org-roam--build-cache-async () "Builds the caches asychronously." @@ -637,27 +657,6 @@ This needs to be quick/infrequent, because this is run at (advice-add 'rename-file :after 'org-roam--rename-file-links) -(defun org-roam-switch-to-buffer () - "Switch to an existing org-roam buffer using completing-read." - (interactive) - (let* ((all-buffers (buffer-list)) - (roam-buffers - (--filter (and (with-current-buffer it (derived-mode-p 'org-mode)) - (buffer-file-name it) - (org-roam--org-roam-file-p (buffer-file-name it))) - all-buffers)) - (names-and-buffers (mapcar (lambda (buffer) - (cons (or (org-roam--get-title-from-cache - (buffer-file-name buffer)) - (buffer-name buffer)) - buffer)) - roam-buffers))) - (unless roam-buffers - (error "No roam buffers.")) - (when-let ((name (completing-read "Choose a buffer: " names-and-buffers))) - (switch-to-buffer (cdr (assoc name names-and-buffers)))))) - - (provide 'org-roam) ;;; org-roam.el ends here