From cce6a0563002faa9b27911f0ca31dc7da94b90e6 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Sun, 13 Mar 2022 09:04:55 -0700 Subject: [PATCH] (fix)buffer: update defcustom for org-roam-mode-section-functions (#2124) --- CHANGELOG.md | 2 ++ doc/org-roam.org | 8 ++++---- doc/org-roam.texi | 8 ++++---- org-roam-compat.el | 4 ++++ org-roam-mode.el | 38 ++++++++++++++++++++++++++------------ 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be45ab..9938cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - [#2050](https://github.com/org-roam/org-roam/pull/2050) core: add `FILTER-FN` to `org-roam-node-random` - [#2065](https://github.com/org-roam/org-roam/pull/2065) dailies: add `keys` argument to the remaining dailies functions `org-roam-dailies-goto-yesterday`/`-today`/`-tomorrow`/`-date` and `org-roam-dailies-capture-yesterday`/`-tomorrow`/`-date` to give the abilty to get into a capture buffer bypassing the selection screen in all dailies commands. Extension of #2055 - [#2079](https://github.com/org-roam/org-roam/pull/2079) capture: ensure that `:ref` info captured in all cases. +- [#2121](https://github.com/org-roam/org-roam/pull/2121) buffer: add unique option to `org-roam-backlinks-section` ### Removed ### Fixed @@ -30,6 +31,7 @@ - [#2040](https://github.com/org-roam/org-roam/pull/2040) completions: fix completions display-width for Helm users - [#2025](https://github.com/org-roam/org-roam/pull/2025) chore: removed the dependencies on f.el and s.el - [#2109](https://github.com/org-roam/org-roam/pull/2109) capture: `org-roam-node-insert` places cursor after inserted link where appropriate +- [#2123](https://github.com/org-roam/org-roam/pull/2123), [#2124](https://github.com/org-roam/org-roam/pull/2124) buffer: `org-roam-mode-section-functions` renamed to `org-roam-mode-sections`, supports passing args into the section-rendering function ## 2.2.0 ### Added diff --git a/doc/org-roam.org b/doc/org-roam.org index 260e384..56afb9d 100644 --- a/doc/org-roam.org +++ b/doc/org-roam.org @@ -636,10 +636,10 @@ There are currently 3 provided widget types: - Unlinked references :: View nodes that contain text that match the nodes title/alias but are not linked -To configure what sections are displayed in the buffer, set ~org-roam-mode-section-functions~. +To configure what sections are displayed in the buffer, set ~org-roam-mode-sections. #+begin_src emacs-lisp - (setq org-roam-mode-section-functions + (setq org-roam-mode-sections (list #'org-roam-backlinks-section #'org-roam-reflinks-section ;; #'org-roam-unlinked-references-section @@ -650,10 +650,10 @@ Note that computing unlinked references may be slow, and has not been added in b For each section function, you can pass args along to modify its behaviour. For example, if you want to render unique sources for backlinks (and also keep -rendering reference links), set ~org-roam-mode-section-functions~ as follows: +rendering reference links), set ~org-roam-mode-sections~ as follows: #+begin_src emacs-lisp - (setq org-roam-mode-section-functions + (setq org-roam-mode-sections '((org-roam-backlinks-section :unique t) org-roam-reflinks-section)) #+end_src diff --git a/doc/org-roam.texi b/doc/org-roam.texi index 38d0ed4..3e3494e 100644 --- a/doc/org-roam.texi +++ b/doc/org-roam.texi @@ -976,10 +976,10 @@ There are currently 3 provided widget types: title/alias but are not linked @end itemize -To configure what sections are displayed in the buffer, set @code{org-roam-mode-section-functions}. +To configure what sections are displayed in the buffer, set ~org-roam-mode-sections. @lisp -(setq org-roam-mode-section-functions +(setq org-roam-mode-sections (list #'org-roam-backlinks-section #'org-roam-reflinks-section ;; #'org-roam-unlinked-references-section @@ -990,10 +990,10 @@ Note that computing unlinked references may be slow, and has not been added in b For each section function, you can pass args along to modify its behaviour. For example, if you want to render unique sources for backlinks (and also keep -rendering reference links), set @code{org-roam-mode-section-functions} as follows: +rendering reference links), set @code{org-roam-mode-sections} as follows: @lisp -(setq org-roam-mode-section-functions +(setq org-roam-mode-sections '((org-roam-backlinks-section :unique t) org-roam-reflinks-section)) @end lisp diff --git a/org-roam-compat.el b/org-roam-compat.el index 3c2ef53..6331ec8 100644 --- a/org-roam-compat.el +++ b/org-roam-compat.el @@ -229,6 +229,10 @@ nodes." org-id-locations-file) 'org-roam-remove-property 'org-roam-property-remove "org-roam 2.1") +(define-obsolete-variable-alias + 'org-roam-mode-section-functions + 'org-roam-mode-sections "org-roam 2.2.0") + ;;; Obsolete functions (make-obsolete 'org-roam-get-keyword 'org-collect-keywords "org-roam 2.0") diff --git a/org-roam-mode.el b/org-roam-mode.el index b12b5b4..227b49e 100644 --- a/org-roam-mode.el +++ b/org-roam-mode.el @@ -39,14 +39,28 @@ (defvar org-ref-buffer-hacked) ;;; Options -(defcustom org-roam-mode-section-functions (list #'org-roam-backlinks-section - #'org-roam-reflinks-section) - "Functions that insert sections in the `org-roam-mode' based buffers. -Each function is called with one argument, which is an -`org-roam-node' for which the buffer will be constructed for. -Normally this node is `org-roam-buffer-current-node'." +(defcustom org-roam-mode-sections (list #'org-roam-backlinks-section + #'org-roam-reflinks-section) + "A list of sections for the `org-roam-mode' based buffers. +Each section is a function that is passed the an `org-roam-node' +for which the section will be constructed for as the first +argument. Normally this node is `org-roam-buffer-current-node'. +The function may also accept other optional arguments. Each item +in the list is either: + +1. A function, which is called only with the `org-roam-node' as the argument +2. A list, containing the function and the optional arguments. + +For example, one can add + + (org-roam-backlinks-section :unique t) + +to the list to pass :unique t to the section-rendering function." :group 'org-roam - :type 'hook) + :type `(repeat (choice (symbol :tag "Function") + (list :tag "Function with arguments" + (symbol :tag "Function") + (repeat :tag "Arguments" :inline t (sexp :tag "Arg")))))) (defcustom org-roam-buffer-postrender-functions (list) "Functions to run after the Org-roam buffer is rendered. @@ -168,7 +182,7 @@ This mode is used by special Org-roam buffers, such as persistent `org-roam-buffer' and dedicated Org-roam buffers \(`org-roam-buffer-display-dedicated'), which render the information in a section-like manner (see -`org-roam-mode-section-functions'), with which the user can +`org-roam-mode-sections'), with which the user can interact with." :group 'org-roam (face-remap-add-relative 'header-line 'org-roam-header-line)) @@ -228,14 +242,14 @@ buffer." (org-roam-node-title org-roam-buffer-current-node)) (magit-insert-section (org-roam) (magit-insert-heading) - (dolist (section-fn org-roam-mode-section-functions) - (pcase section-fn + (dolist (section org-roam-mode-sections) + (pcase section ((pred functionp) - (funcall section-fn org-roam-buffer-current-node)) + (funcall section org-roam-buffer-current-node)) (`(,fn . ,args) (apply fn (cons org-roam-buffer-current-node args))) (_ - (user-error "Invalid `org-roam-mode-section-functions specification.'"))))) + (user-error "Invalid `org-roam-mode-sections' specification"))))) (run-hooks 'org-roam-buffer-postrender-functions) (goto-char 0)))