nroam is a supplementary package for org-roam that replaces the backlink side buffer of Org-roam. Instead, it displays org-roam backlinks at the end of org-roam buffers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.2 KiB

;;; nroam-utils.el --- Util functions for nroam -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Nicolas Petton
;; Author: Nicolas Petton <>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Commentary:
;; This library provides utility functions used by other files in nroam.
;;; Code:
(require 'seq)
(require 'org-roam)
(defun nroam--pluralize (n thing)
"Pluralize the string THING if N>1."
(format "%s%s" thing (if (> n 1) "s" "")))
(defun nroam--ensure-empty-line ()
"Insert a newline character if the buffer does not contain one before point."
(let ((inhibit-read-only t))
(unless (eq ?\n (char-before (1- (point)))) (insert "\n"))))
(defun nroam--insert-heading (level title &optional tags)
"Insert TITLE as a section heading with LEVEL stars.
When non-nil, add the string or list of strings as TAGS to the heading."
(let ((pos (point))
(stars (make-string level ?*)))
(insert stars " " title "\n")
(when tags
(goto-char pos)
(org-set-tags tags)))))
(defun nroam--do-separated-by-newlines (function sequence)
"Apply FUNCTION to each element of SEQUENCE.
Insert a single newline between each call to FUNCTION."
(seq-do-indexed (lambda (item index)
(unless (= index 0)
(funcall function item))
(defun nroam--fix-links (content origin)
"Correct all relative links in CONTENT from ORIGIN.
Temporary fix until `org-roam' v2 is out."
(org-roam-buffer-expand-links content origin))
(provide 'nroam-utils)
;;; nroam-utils.el ends here