From c51e54957deae21d2517313a3b7321c03525c24f Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Sun, 28 Feb 2021 22:03:53 +0100 Subject: Split nroam.el * nroam-backlinks.el: * nroam-utils.el: New files. --- nroam-utils.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 nroam-utils.el (limited to 'nroam-utils.el') diff --git a/nroam-utils.el b/nroam-utils.el new file mode 100644 index 0000000..b53eeac --- /dev/null +++ b/nroam-utils.el @@ -0,0 +1,58 @@ +;;; nroam-utils.el --- Util functions for nroam -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 Nicolas Petton + +;; Author: Nicolas Petton +;; URL: https://github.com/NicolasPetton/nroam +;; Keywords: convenience +;; Version: 0.0.1 +;; Package-Requires: ((emacs "26.1") (org-roam "1.2.3")) + + +;; 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 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; 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 contain one before point." + (let ((inhibit-read-only t)) + (unless (eq ?\n (char-before (1- (point)))) (insert "\n")))) + +(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) + (delete-blank-lines) + (nroam--ensure-empty-line)) + (funcall function item)) + sequence)) + +(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 -- cgit v1.2.3-54-g00ecf