mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
c23bca69f8 | |||
f206b5bbf9 | |||
30fab7bcc4 | |||
76d2e3f6b4 | |||
8881c9732b | |||
0aa0a7c05a | |||
ea4bfbb55d | |||
0443351800 | |||
6345d0c22e | |||
f2c1500beb |
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,5 +1,16 @@
|
||||
# Changelog
|
||||
|
||||
## 1.2.2 (TBD)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
### Features
|
||||
|
||||
- [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
|
||||
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
|
||||
|
||||
### Bugfixes
|
||||
|
||||
## 1.2.1 (27-07-2020)
|
||||
|
||||
This release consisted of a big deal of refactoring and bug fixes. Notably, we fixed several catastrophic failures on db builds with bad setups (#854), and modularized tag and title extractions.
|
||||
|
@ -4,6 +4,11 @@
|
||||
|
||||
## Synopsis
|
||||
|
||||
> **NOTE:** Org-roam builds upon Emacs and Org-mode, both of which are intricate
|
||||
> tools that require time investment for mastery. This makes Org-roam less
|
||||
> friendly for beginners, but extremely powerful for those familiar with the
|
||||
> ecosystem, or willing to invest effort in it.
|
||||
|
||||
Org-roam is a [Roam][roamresearch] replica built on top of the
|
||||
all-powerful [Org-mode][org].
|
||||
|
||||
|
@ -56,6 +56,38 @@ Org-roam provides several benefits over other tooling:
|
||||
- Leverages the Org-mode ecosystem :: Over the years, Emacs and Org-mode has developed into a mature system for plain-text organization. Building upon Org-mode already puts Org-roam light-years ahead of many other solutions.
|
||||
- Built on Emacs :: Emacs is also a fantastic interface for editing text, and we can inherit many of the powerful text-navigation and editing packages available to Emacs.
|
||||
|
||||
* Target Audience
|
||||
|
||||
Org-roam is a tool that will appear unfriendly to anyone unfamiliar with Emacs
|
||||
and Org-mode, but is also extremely powerful to those willing to put effort in
|
||||
mastering the intricacies of the tools. Org-roam stands on the shoulders on
|
||||
giants. Emacs was first created in 1976, and remains a top tier tool for editing
|
||||
text and designing textual interfaces. The malleability of Emacs allowed the
|
||||
creation of Org-mode, an all-purpose plain-text system for maintaining TODO
|
||||
lists, planning projects, and authoring documents. Both of these tools are
|
||||
incredibly vast and require significant time investment to master.
|
||||
|
||||
Org-roam assumes basic familiarity with these tools. It is not difficult to get
|
||||
up and running with basic text-editing functionality, but one will only fully
|
||||
appreciate the power of building Roam functionality into Emacs and Org-mode when
|
||||
the usage of these tools become more advanced.
|
||||
|
||||
One key advantage to Org-roam is that building on top of Emacs gives it
|
||||
malleability. This is especially important for note-taking workflows. It is our
|
||||
belief that note-taking workflows are extremely personal, and there is no one
|
||||
tool that's perfect for you. Org-mode and Org-roam allows you to discover what
|
||||
works for you, and build that perfect tool for yourself.
|
||||
|
||||
If you are new to the software, and choose to take this leap of faith, I hope
|
||||
you find yourself equally entranced as Neal Stephenson was.
|
||||
|
||||
#+BEGIN_QUOTE
|
||||
Emacs outshines all other editing software in approximately the same way that
|
||||
the noonday sun does the stars. It is not just bigger and brighter; it simply
|
||||
makes everything else vanish. – Neal Stephenson, In the Beginning was the
|
||||
Command Line (1998)
|
||||
#+END_QUOTE
|
||||
|
||||
* A Brief Introduction to the Zettelkasten Method
|
||||
|
||||
Org-roam provides utilities for maintaining a digital slip-box. This section
|
||||
|
@ -65,6 +65,7 @@ General Public License for more details.
|
||||
|
||||
@menu
|
||||
* Introduction::
|
||||
* Target Audience::
|
||||
* A Brief Introduction to the Zettelkasten Method::
|
||||
* Installation::
|
||||
* Getting Started::
|
||||
@ -186,6 +187,40 @@ Over the years, Emacs and Org-mode has developed into a mature system for plain-
|
||||
Emacs is also a fantastic interface for editing text, and we can inherit many of the powerful text-navigation and editing packages available to Emacs.
|
||||
@end table
|
||||
|
||||
@node Target Audience
|
||||
@chapter Target Audience
|
||||
|
||||
Org-roam is a tool that will appear unfriendly to anyone unfamiliar with Emacs
|
||||
and Org-mode, but is also extremely powerful to those willing to put effort in
|
||||
mastering the intricacies of the tools. Org-roam stands on the shoulders on
|
||||
giants. Emacs was first created in 1976, and remains a top tier tool for editing
|
||||
text and designing textual interfaces. The malleability of Emacs allowed the
|
||||
creation of Org-mode, an all-purpose plain-text system for maintaining TODO
|
||||
lists, planning projects, and authoring documents. Both of these tools are
|
||||
incredibly vast and require significant time investment to master.
|
||||
|
||||
Org-roam assumes basic familiarity with these tools. It is not difficult to get
|
||||
up and running with basic text-editing functionality, but one will only fully
|
||||
appreciate the power of building Roam functionality into Emacs and Org-mode when
|
||||
the usage of these tools become more advanced.
|
||||
|
||||
One key advantage to Org-roam is that building on top of Emacs gives it
|
||||
malleability. This is especially important for note-taking workflows. It is our
|
||||
belief that note-taking workflows are extremely personal, and there is no one
|
||||
tool that's perfect for you. Org-mode and Org-roam allows you to discover what
|
||||
works for you, and build that perfect tool for yourself.
|
||||
|
||||
If you are new to the software, and choose to take this leap of faith, I hope
|
||||
you find yourself equally entranced as Neal Stephenson was.
|
||||
|
||||
@quotation
|
||||
Emacs outshines all other editing software in approximately the same way that
|
||||
the noonday sun does the stars. It is not just bigger and brighter; it simply
|
||||
makes everything else vanish. – Neal Stephenson, In the Beginning was the
|
||||
Command Line (1998)
|
||||
|
||||
@end quotation
|
||||
|
||||
@node A Brief Introduction to the Zettelkasten Method
|
||||
@chapter A Brief Introduction to the Zettelkasten Method
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
;;; Code:
|
||||
;;;; Library Requires
|
||||
(require 'org-capture)
|
||||
(require 'org-roam-macs)
|
||||
(require 'dash)
|
||||
(require 's)
|
||||
(require 'cl-lib)
|
||||
@ -102,7 +103,7 @@ The Org-roam capture-templates builds on the default behaviours of
|
||||
|
||||
3. The `:head' key is added, which contains the template that is
|
||||
inserted upon the creation of a new file. This is where you
|
||||
should add your note metadata should go.
|
||||
your note metadata should go.
|
||||
|
||||
Each template should have the following structure:
|
||||
|
||||
@ -320,8 +321,14 @@ the capture)."
|
||||
|
||||
(defun org-roam-capture--finalize ()
|
||||
"Finalize the `org-roam-capture' process."
|
||||
(let* ((finalize (org-roam-capture--get :finalize))
|
||||
;; In case any regions were shielded before, unshield them
|
||||
(region (when-let ((region (org-roam-capture--get :region)))
|
||||
(org-roam-unshield-region (car region) (cdr region))))
|
||||
(beg (car region))
|
||||
(end (cdr region)))
|
||||
(unless org-note-abort
|
||||
(pcase (org-roam-capture--get :finalize)
|
||||
(pcase finalize
|
||||
('find-file
|
||||
(when-let ((file-path (org-roam-capture--get :file-path)))
|
||||
(org-roam--find-file file-path)
|
||||
@ -330,7 +337,7 @@ the capture)."
|
||||
(when-let* ((mkr (org-roam-capture--get :insert-at))
|
||||
(buf (marker-buffer mkr)))
|
||||
(with-current-buffer buf
|
||||
(when-let ((region (org-roam-capture--get :region))) ;; Remove previously selected text.
|
||||
(when region
|
||||
(delete-region (car region) (cdr region)))
|
||||
(let ((path (org-roam-capture--get :file-path))
|
||||
(desc (org-roam-capture--get :link-description)))
|
||||
@ -338,8 +345,11 @@ the capture)."
|
||||
(insert (org-roam--format-link path desc))
|
||||
(org-with-point-at mkr
|
||||
(insert (org-roam--format-link path desc))))))))))
|
||||
(when region
|
||||
(set-marker beg nil)
|
||||
(set-marker end nil))
|
||||
(org-roam-capture--save-file-maybe)
|
||||
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize))
|
||||
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize)))
|
||||
|
||||
(defun org-roam-capture--install-finalize ()
|
||||
"Install `org-roam-capture--finalize' if the capture is an Org-roam capture."
|
||||
|
@ -492,6 +492,7 @@ If FORCE, force a rebuild of the cache from scratch."
|
||||
(let ((contents-hash (org-roam-db--file-hash file)))
|
||||
(unless (string= (gethash file current-files)
|
||||
contents-hash)
|
||||
(condition-case nil
|
||||
(org-roam--with-temp-buffer file
|
||||
(org-roam-db--clear-file file)
|
||||
(org-roam-db-query
|
||||
@ -501,7 +502,12 @@ If FORCE, force a rebuild of the cache from scratch."
|
||||
(setq file-count (1+ file-count))
|
||||
(when-let ((headlines (org-roam--extract-headlines file)))
|
||||
(when (org-roam-db--insert-headlines headlines)
|
||||
(setq headline-count (1+ headline-count)))))))))
|
||||
(setq headline-count (1+ headline-count)))))
|
||||
(file-error
|
||||
(setq org-roam-files (remove file org-roam-files))
|
||||
(org-roam-db--clear-file file)
|
||||
(lwarn '(org-roam) :warning
|
||||
"Skipping unreadable file while building cache: %s" file)))))))
|
||||
;; Second step: Rebuild the rest
|
||||
(dolist (file org-roam-files)
|
||||
(let ((contents-hash (org-roam-db--file-hash file)))
|
||||
|
67
org-roam-faces.el
Normal file
67
org-roam-faces.el
Normal file
@ -0,0 +1,67 @@
|
||||
;;; org-roam-faces.el --- Face definitions -*- coding: utf-8; 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: 1.2.1
|
||||
;; Package-Requires: ((emacs "26.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:
|
||||
|
||||
;; This file contains the face definitions for Org-roam.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defgroup org-roam-faces nil
|
||||
"Faces used by Org-roam."
|
||||
:group 'org-roam
|
||||
:group 'faces)
|
||||
|
||||
;;; Definitions
|
||||
(defface org-roam-link
|
||||
'((t :inherit org-link))
|
||||
"Face for Org-roam links."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
(defface org-roam-link-current
|
||||
'((t :inherit org-link))
|
||||
"Face for Org-roam links pointing to the current buffer."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
(defface org-roam-link-invalid
|
||||
'((t :inherit (error org-link)))
|
||||
"Face for Org-roam links that are not valid.
|
||||
This face is used for links without a destination."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
(defface org-roam-link-shielded
|
||||
'((t :inherit (warning org-link)))
|
||||
"Face for Org-roam links that are shielded.
|
||||
This face is used on the region target by `org-roam-insertion'
|
||||
during an `org-roam-capture'."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
;;; _
|
||||
|
||||
(provide 'org-roam-faces)
|
||||
|
||||
;;; org-roam-faces.el ends here
|
0
org-roam-flow.el
Normal file
0
org-roam-flow.el
Normal file
@ -77,6 +77,28 @@ to look.
|
||||
(s-replace "\\" "\\\\")
|
||||
(s-replace "\"" "\\\"")))
|
||||
|
||||
;;; Shielding regions
|
||||
(defun org-roam-shield-region (beg end)
|
||||
"Shield REGION against modifications.
|
||||
REGION must be a cons-cell containing the marker to the region
|
||||
beginning and maximum values."
|
||||
(when (and beg end)
|
||||
(add-text-properties beg end
|
||||
'(font-lock-face org-roam-link-shielded
|
||||
read-only t)
|
||||
(marker-buffer beg))
|
||||
(cons beg end)))
|
||||
|
||||
(defun org-roam-unshield-region (beg end)
|
||||
"Unshield the shielded REGION."
|
||||
(when (and beg end)
|
||||
(let ((inhibit-read-only t))
|
||||
(remove-text-properties beg end
|
||||
'(font-lock-face org-roam-link-shielded
|
||||
read-only t)
|
||||
(marker-buffer beg)))
|
||||
(cons beg end)))
|
||||
|
||||
(provide 'org-roam-macs)
|
||||
|
||||
;;; org-roam-macs.el ends here
|
||||
|
195
org-roam.el
195
org-roam.el
@ -54,6 +54,8 @@
|
||||
;; @TODO: implement something akin to `org-modules' that allows
|
||||
;; selectively loading different sets of features.
|
||||
;; ~NV [2020-05-22 Fri]
|
||||
|
||||
(require 'org-roam-faces)
|
||||
(require 'org-roam-buffer)
|
||||
(require 'org-roam-completion)
|
||||
(require 'org-roam-capture)
|
||||
@ -78,11 +80,6 @@
|
||||
:link '(url-link :tag "Github" "https://github.com/org-roam/org-roam")
|
||||
:link '(url-link :tag "Online Manual" "https://www.orgroam.com/manual/"))
|
||||
|
||||
(defgroup org-roam-faces nil
|
||||
"Faces used by Org-roam."
|
||||
:group 'org-roam
|
||||
:group 'faces)
|
||||
|
||||
(defcustom org-roam-directory (expand-file-name "~/org-roam/")
|
||||
"Default path to Org-roam files.
|
||||
All Org files, at any level of nesting, are considered part of the Org-roam."
|
||||
@ -942,25 +939,7 @@ Return nil if the file does not exist."
|
||||
file)
|
||||
org-roam-directory))))
|
||||
|
||||
;;; The org-roam buffer
|
||||
;;;; org-roam-link-face
|
||||
(defface org-roam-link
|
||||
'((t :inherit org-link))
|
||||
"Face for Org-roam links."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
(defface org-roam-link-current
|
||||
'((t :inherit org-link))
|
||||
"Face for Org-roam links pointing to the current buffer."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
(defface org-roam-link-invalid
|
||||
'((t :inherit (error org-link)))
|
||||
"Face for Org-roam links that are not valid.
|
||||
This face is used for links without a destination."
|
||||
:group 'org-roam-faces)
|
||||
|
||||
;;;; org-roam-backlinks-mode
|
||||
;;; org-roam-backlinks-mode
|
||||
(define-minor-mode org-roam-backlinks-mode
|
||||
"Minor mode for the `org-roam-buffer'.
|
||||
\\{org-roam-backlinks-mode-map}"
|
||||
@ -999,39 +978,6 @@ buffer or a marker."
|
||||
(backlink-dest (org-roam--retrieve-link-destination)))
|
||||
(string= current backlink-dest)))
|
||||
|
||||
(defun org-roam--roam-file-link-face (path)
|
||||
"Conditional face for org file links.
|
||||
Applies `org-roam-link-current' if PATH corresponds to the
|
||||
currently opened Org-roam file in the backlink buffer, or
|
||||
`org-roam-link-face' if PATH corresponds to any other Org-roam
|
||||
file."
|
||||
(cond ((and (not (file-remote-p path)) ;; Prevent lockups opening Tramp links
|
||||
(not (file-exists-p path)))
|
||||
'org-roam-link-invalid)
|
||||
((and (org-roam--in-buffer-p)
|
||||
(org-roam--backlink-to-current-p))
|
||||
'org-roam-link-current)
|
||||
((org-roam--org-roam-file-p path)
|
||||
'org-roam-link)
|
||||
(t
|
||||
'org-link)))
|
||||
|
||||
(defun org-roam--roam-id-link-face (id)
|
||||
"Conditional face for org ID links.
|
||||
Applies `org-roam-link-current' if ID corresponds to the
|
||||
currently opened Org-roam file in the backlink buffer, or
|
||||
`org-roam-link-face' if ID corresponds to any other Org-roam
|
||||
file."
|
||||
(cond ((not (org-roam-id-find id))
|
||||
'org-roam-link-invalid)
|
||||
((and (org-roam--in-buffer-p)
|
||||
(org-roam--backlink-to-current-p))
|
||||
'org-roam-link-current)
|
||||
((org-roam-id-find id t)
|
||||
'org-roam-link)
|
||||
(t
|
||||
'org-link)))
|
||||
|
||||
(defun org-roam-open-at-point ()
|
||||
"Open an Org-roam link or visit the text previewed at point.
|
||||
When point is on an Org-roam link, open the link in the Org-roam window.
|
||||
@ -1068,34 +1014,21 @@ for Org-ref cite links."
|
||||
:order-by (asc from)]
|
||||
target))
|
||||
|
||||
(defun org-roam-store-link-file ()
|
||||
"Store a link to an `org-roam' file."
|
||||
(when (org-before-first-heading-p)
|
||||
(when-let ((title (cdr (assoc "TITLE" (org-roam--extract-global-props '("TITLE"))))))
|
||||
(defun org-roam-store-link ()
|
||||
"Store a link to an Org-roam file or heading."
|
||||
(when (and (bound-and-true-p org-roam-mode)
|
||||
(org-roam--org-roam-file-p))
|
||||
(if (org-before-first-heading-p)
|
||||
(when-let ((titles (org-roam--extract-titles)))
|
||||
(org-link-store-props
|
||||
:type "file"
|
||||
:link (format "file:%s" (abbreviate-file-name buffer-file-name))
|
||||
:description title))))
|
||||
|
||||
(defun org-roam--store-link (arg &optional interactive?)
|
||||
"Store a link to the current location within Org-roam.
|
||||
See `org-roam-store-link' for details on ARG and INTERACTIVE?."
|
||||
(let ((org-id-link-to-org-use-id t)
|
||||
(id (org-id-get)))
|
||||
(org-store-link arg interactive?)
|
||||
:description (car titles)))
|
||||
(let ((id (org-id-get)))
|
||||
(org-id-store-link)
|
||||
;; If :ID: was created, update the cache
|
||||
(unless id
|
||||
(org-roam-db--update-headlines))))
|
||||
|
||||
(defun org-roam-store-link (arg &optional interactive?)
|
||||
"Store a link to the current location.
|
||||
This commands is a wrapper for `org-store-link' which forces the
|
||||
automatic creation of :ID: properties.
|
||||
See `org-roam-store-link' for details on ARG and INTERACTIVE?."
|
||||
(interactive "P\np")
|
||||
(if (org-roam--org-roam-file-p)
|
||||
(org-roam--store-link arg interactive?)
|
||||
(org-store-link arg interactive?)))
|
||||
(org-roam-db--update-headlines))))))
|
||||
|
||||
(defun org-roam-id-find (id &optional markerp strict)
|
||||
"Return the location of the entry with the id ID.
|
||||
@ -1149,15 +1082,73 @@ This function hooks into `org-open-at-point' via
|
||||
(t
|
||||
nil)))))
|
||||
|
||||
;;; The global minor org-roam-mode
|
||||
;;; Org-roam-mode
|
||||
;;;; Function Faces
|
||||
;; These faces are used by `org-link-set-parameters', which take one argument,
|
||||
;; which is the path.
|
||||
(defcustom org-roam-link-use-custom-faces 'everywhere
|
||||
"Define where to apply custom faces to Org-roam links.
|
||||
|
||||
Valide values are:
|
||||
|
||||
t Use custom faces inside Org-roam notes (i.e. files in
|
||||
`org-roam-directory'.)
|
||||
|
||||
everywhere Apply custom faces everywhere.
|
||||
|
||||
Otherwise, do not apply custom faces to Org-roam links."
|
||||
:type '(choice
|
||||
(const :tag "Use custom faces inside Org-roam notes" t)
|
||||
(const :tag "Apply custom faces everywhere" everywhere)
|
||||
(const :tag "Do not apply custom faces" nil))
|
||||
:group 'org-roam)
|
||||
|
||||
(defun org-roam--file-link-face (path)
|
||||
"Conditional face for file: links.
|
||||
Applies `org-roam-link-current' if PATH corresponds to the
|
||||
currently opened Org-roam file in the backlink buffer, or
|
||||
`org-roam-link-face' if PATH corresponds to any other Org-roam
|
||||
file."
|
||||
(let* ((in-note (-> (buffer-file-name (buffer-base-buffer))
|
||||
(org-roam--org-roam-file-p)))
|
||||
(custom (or (and in-note org-roam-link-use-custom-faces)
|
||||
(eq org-roam-link-use-custom-faces 'everywhere))))
|
||||
(cond ((and custom
|
||||
(not (file-remote-p path)) ;; Prevent lockups opening Tramp links
|
||||
(not (file-exists-p path)))
|
||||
'org-roam-link-invalid)
|
||||
((and (org-roam--in-buffer-p)
|
||||
(org-roam--backlink-to-current-p))
|
||||
'org-roam-link-current)
|
||||
((and custom
|
||||
(org-roam--org-roam-file-p path))
|
||||
'org-roam-link)
|
||||
(t
|
||||
'org-link))))
|
||||
|
||||
(defun org-roam--id-link-face (id)
|
||||
"Conditional face for id links.
|
||||
Applies `org-roam-link-current' if ID corresponds to the
|
||||
currently opened Org-roam file in the backlink buffer, or
|
||||
`org-roam-link-face' if ID corresponds to any other Org-roam
|
||||
file."
|
||||
(cond ((not (org-roam-id-find id))
|
||||
'org-roam-link-invalid)
|
||||
((and (org-roam--in-buffer-p)
|
||||
(org-roam--backlink-to-current-p))
|
||||
'org-roam-link-current)
|
||||
((org-roam-id-find id t)
|
||||
'org-roam-link)
|
||||
(t
|
||||
'org-link)))
|
||||
|
||||
;;;; Hooks and Advices
|
||||
(defun org-roam--find-file-hook-function ()
|
||||
"Called by `find-file-hook' when mode symbol `org-roam-mode' is on."
|
||||
(when (org-roam--org-roam-file-p)
|
||||
(setq org-roam-last-window (get-buffer-window))
|
||||
(add-hook 'post-command-hook #'org-roam-buffer--update-maybe nil t)
|
||||
(add-hook 'after-save-hook #'org-roam-db--update-file nil t)
|
||||
(org-link-set-parameters "file" :face 'org-roam--roam-file-link-face :store #'org-roam-store-link-file)
|
||||
(org-link-set-parameters "id" :face 'org-roam--roam-id-link-face)
|
||||
(org-roam-buffer--update-maybe :redisplay t)))
|
||||
|
||||
(defun org-roam--delete-file-advice (file &optional _trash)
|
||||
@ -1292,7 +1283,6 @@ nil, or positive. If ARG is `toggle', toggle `org-roam-mode'.
|
||||
Otherwise, behave as if called interactively."
|
||||
:lighter " Org-roam"
|
||||
:keymap (let ((map (make-sparse-keymap)))
|
||||
(define-key map [remap org-store-link] 'org-roam-store-link)
|
||||
map)
|
||||
:group 'org-roam
|
||||
:require 'org-roam
|
||||
@ -1311,6 +1301,9 @@ M-x info for more information at Org-roam > Installation > Post-Installation Tas
|
||||
(add-hook 'org-open-at-point-functions #'org-roam-open-id-at-point)
|
||||
(advice-add 'rename-file :after #'org-roam--rename-file-advice)
|
||||
(advice-add 'delete-file :before #'org-roam--delete-file-advice)
|
||||
(when (fboundp 'org-link-set-parameters)
|
||||
(org-link-set-parameters "file" :face 'org-roam--file-link-face :store #'org-roam-store-link)
|
||||
(org-link-set-parameters "id" :face 'org-roam---id-link-face))
|
||||
(org-roam-db-build-cache))
|
||||
(t
|
||||
(setq org-execute-file-search-functions (delete 'org-roam--execute-file-row-col org-execute-file-search-functions))
|
||||
@ -1319,11 +1312,13 @@ M-x info for more information at Org-roam > Installation > Post-Installation Tas
|
||||
(remove-hook 'org-open-at-point-functions #'org-roam-open-id-at-point)
|
||||
(advice-remove 'rename-file #'org-roam--rename-file-advice)
|
||||
(advice-remove 'delete-file #'org-roam--delete-file-advice)
|
||||
(when (fboundp 'org-link-set-parameters)
|
||||
(dolist (face '("file" "id"))
|
||||
(org-link-set-parameters face :face 'org-link)))
|
||||
(org-roam-db--close-all)
|
||||
;; Disable local hooks for all org-roam buffers
|
||||
(dolist (buf (org-roam--get-roam-buffers))
|
||||
(with-current-buffer buf
|
||||
(org-link-set-parameters "file" :face 'org-link)
|
||||
(remove-hook 'post-command-hook #'org-roam-buffer--update-maybe t)
|
||||
(remove-hook 'after-save-hook #'org-roam-db--update-file t))))))
|
||||
|
||||
@ -1420,11 +1415,16 @@ If DESCRIPTION is provided, use this as the link label. See
|
||||
`org-roam--get-title-path-completions' for details."
|
||||
(interactive "P")
|
||||
(unless org-roam-mode (org-roam-mode))
|
||||
(let* ((region (and (region-active-p)
|
||||
;; following may lose active region, so save it
|
||||
(cons (region-beginning) (region-end))))
|
||||
(region-text (when region
|
||||
(buffer-substring-no-properties (car region) (cdr region))))
|
||||
;; Deactivate the mark on quit since `atomic-change-group' prevents it
|
||||
(unwind-protect
|
||||
;; Group functions together to avoid inconsistent state on quit
|
||||
(atomic-change-group
|
||||
(let* (region-text
|
||||
beg end
|
||||
(_ (when (region-active-p)
|
||||
(setq beg (set-marker (make-marker) (region-beginning)))
|
||||
(setq end (set-marker (make-marker) (region-end)))
|
||||
(setq region-text (buffer-substring-no-properties beg end))))
|
||||
(completions (--> (or completions
|
||||
(org-roam--get-title-path-completions))
|
||||
(if filter-fn
|
||||
@ -1440,22 +1440,25 @@ If DESCRIPTION is provided, use this as the link label. See
|
||||
(link-description (org-roam--format-link-title (if lowercase
|
||||
(downcase description)
|
||||
description))))
|
||||
(if (and target-file-path
|
||||
(cond ((and target-file-path
|
||||
(file-exists-p target-file-path))
|
||||
(progn
|
||||
(when region ;; Remove previously selected text.
|
||||
(delete-region (car region) (cdr region)))
|
||||
(when region-text
|
||||
(delete-region beg end)
|
||||
(set-marker beg nil)
|
||||
(set-marker end nil))
|
||||
(insert (org-roam--format-link target-file-path link-description)))
|
||||
(t
|
||||
(let ((org-roam-capture--info `((title . ,title-with-tags)
|
||||
(slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
|
||||
(org-roam-capture--context 'title))
|
||||
(setq org-roam-capture-additional-template-props (list :region region
|
||||
(setq org-roam-capture-additional-template-props (list :region (org-roam-shield-region beg end)
|
||||
:insert-at (point-marker)
|
||||
:link-description link-description
|
||||
:finalize 'insert-link))
|
||||
(org-roam--with-template-error 'org-roam-capture-templates
|
||||
(org-roam-capture--capture))))
|
||||
(org-roam-capture--capture)))))
|
||||
res))
|
||||
(deactivate-mark)))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-roam-insert-immediate (arg &rest args)
|
||||
|
Reference in New Issue
Block a user