mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat) add org-roam-refile
This commit is contained in:
@ -168,10 +168,11 @@ is the `org-roam-node'."
|
||||
:tags (gethash id tags-table))))
|
||||
(cons (propertize alias 'node node) node)))))
|
||||
|
||||
(defun org-roam-node-read (&optional initial-input filter-fn)
|
||||
(defun org-roam-node-read (&optional initial-input filter-fn require-match)
|
||||
"Read and return an `org-roam-node'.
|
||||
INITIAL-INPUT is the initial prompt value.
|
||||
FILTER-FN is a function applied to the completion list."
|
||||
FILTER-FN is a function applied to the completion list.
|
||||
If REQUIRE-MATCH, require returning a match."
|
||||
(let* ((nodes (org-roam-node--completions))
|
||||
(nodes (funcall (or filter-fn #'identity) nodes))
|
||||
(node (completing-read "Node: "
|
||||
@ -181,7 +182,7 @@ FILTER-FN is a function applied to the completion list."
|
||||
(annotation-function . org-roam-node--annotation)
|
||||
(category . org-roam-node))
|
||||
(complete-with-action action nodes string pred)))
|
||||
nil nil initial-input)))
|
||||
nil require-match initial-input)))
|
||||
(or (cdr (assoc node nodes))
|
||||
(org-roam-node-create :title node))))
|
||||
|
||||
|
72
org-roam-refile.el
Normal file
72
org-roam-refile.el
Normal file
@ -0,0 +1,72 @@
|
||||
;;; org-roam-refile.el --- Refile Org-roam Notes -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||
|
||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||
;; URL: https://github.com/org-roam/org-roam
|
||||
;; Keywords: org-mode, roam, convenience
|
||||
;; Version: 2.0.0
|
||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||
|
||||
;; This file is NOT part of GNU Emacs.
|
||||
|
||||
;; 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, 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 GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; Org-roam refile allows you to refile notes to your nodes.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(defun org-roam-refile ()
|
||||
"Refile to node."
|
||||
(interactive)
|
||||
(let* ((regionp (org-region-active-p))
|
||||
(region-start (and regionp (region-beginning)))
|
||||
(region-end (and regionp (region-end)))
|
||||
(node (org-roam-node-read nil nil 'require-match))
|
||||
(file (org-roam-node-file node))
|
||||
(nbuf (or (find-buffer-visiting file)
|
||||
(find-file-noselect file)))
|
||||
level reversed)
|
||||
(if regionp
|
||||
(progn
|
||||
(org-kill-new (buffer-substring region-start region-end))
|
||||
(org-save-markers-in-region region-start region-end))
|
||||
(org-copy-subtree 1 nil t))
|
||||
(with-current-buffer nbuf
|
||||
(org-with-wide-buffer
|
||||
(goto-char (org-roam-node-point node))
|
||||
(setq level (org-get-valid-level (funcall outline-level) 1)
|
||||
reversed (org-notes-order-reversed-p))
|
||||
(goto-char
|
||||
(if reversed
|
||||
(or (outline-next-heading) (point-max))
|
||||
(or (save-excursion (org-get-next-sibling))
|
||||
(org-end-of-subtree t t)
|
||||
(point-max))))
|
||||
(unless (bolp) (newline))
|
||||
(org-paste-subtree level nil nil t)
|
||||
(and org-auto-align-tags
|
||||
(let ((org-loop-over-headlines-in-active-region nil))
|
||||
(org-align-tags)))
|
||||
(when (fboundp 'deactivate-mark) (deactivate-mark))))
|
||||
(if regionp
|
||||
(delete-region (point) (+ (point) (- region-end region-start)))
|
||||
(org-preserve-local-variables
|
||||
(delete-region
|
||||
(and (org-back-to-heading t) (point))
|
||||
(min (1+ (buffer-size)) (org-end-of-subtree t t) (point)))))))
|
Reference in New Issue
Block a user