Compare commits

...

10 Commits
v1.2.1 ... flow

Author SHA1 Message Date
c23bca69f8 (feat): Implement org-roam-flow 2020-08-04 15:23:00 +02:00
f206b5bbf9 (fix): skip unreadable files while building the cache (#995)
When using gpg encrypted files it might happen (intended) that on a
certain machine there is no key to decrypt that file.  Currently an
error of type 'file-error' will be raised and the cache building
process will be aborted.  So in a certain sense org-roam will not
be functional in that case.  Furthermore, when the the cache building
process is run from the emacs initialisation it will come to a halt as
well and the user will be left with a halfworking emacs instance.

This patch changes the behaviour to just skipping over offending files
while removing them from the db at the same time.  Here an offending
file is any file that cannot be read for indexing.  As it stands this
case only works reliably for the case of missing gpg keys.

An error buffer will still show up and be prominently displayed,
besides a log to the message buffer.

Implementation note: This io error will only be caught during the
first part of the cache rebuilding ("files and headlines").  If such
an error would occur during the second part ("rebuild the rest")
another (more severe) cause might be the problem and the user better
be informed the hard way (i.e. the same behaviour as before).
2020-08-03 16:58:22 +08:00
30fab7bcc4 (feat): Add toggle for custom-faces for Org-roam links (#997)
* org-roam.el (org-roam-link-use-custom-faces): New toggle
(org-roam--file-link-face): Refactor for new toggle
2020-08-02 18:27:38 +02:00
76d2e3f6b4 (feat): Simplify org-roam-store-link (#994)
* (feat): Simplify org-roam-store-link

Drop the wrapper, and refactor as an org-store-link function.
2020-08-01 08:02:57 +02:00
8881c9732b (fix) Change Emacs date to 1976 (#993)
cf. https://en.wikipedia.org/wiki/Emacs
2020-07-31 15:29:59 +02:00
0aa0a7c05a (doc): Add target audience section (#990) 2020-07-31 02:15:42 +08:00
ea4bfbb55d (fix): fix face-related functionality (#988)
- Ensure `org-roam-store-link-file` has no effect if org-roam-mode is
disabled
- Remove custom styling for ID links when org-roam-mode is disabled
2020-07-30 09:56:13 +08:00
0443351800 (internal): move faces into own file (#987) 2020-07-30 09:12:56 +08:00
6345d0c22e (feat): Protect region targeted by org-roam-insert (#974)
Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
2020-07-27 20:16:39 +02:00
f2c1500beb (doc): Fix docstring (#979) 2020-07-27 11:43:23 +02:00
10 changed files with 348 additions and 157 deletions

View File

@ -1,5 +1,16 @@
# Changelog # 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) ## 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. 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.

View File

@ -4,6 +4,11 @@
## Synopsis ## 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 Org-roam is a [Roam][roamresearch] replica built on top of the
all-powerful [Org-mode][org]. all-powerful [Org-mode][org].

View File

@ -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. - 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. - 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 * A Brief Introduction to the Zettelkasten Method
Org-roam provides utilities for maintaining a digital slip-box. This section Org-roam provides utilities for maintaining a digital slip-box. This section

View File

@ -65,6 +65,7 @@ General Public License for more details.
@menu @menu
* Introduction:: * Introduction::
* Target Audience::
* A Brief Introduction to the Zettelkasten Method:: * A Brief Introduction to the Zettelkasten Method::
* Installation:: * Installation::
* Getting Started:: * 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. 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 @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 @node A Brief Introduction to the Zettelkasten Method
@chapter A Brief Introduction to the Zettelkasten Method @chapter A Brief Introduction to the Zettelkasten Method

View File

@ -31,6 +31,7 @@
;;; Code: ;;; Code:
;;;; Library Requires ;;;; Library Requires
(require 'org-capture) (require 'org-capture)
(require 'org-roam-macs)
(require 'dash) (require 'dash)
(require 's) (require 's)
(require 'cl-lib) (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 3. The `:head' key is added, which contains the template that is
inserted upon the creation of a new file. This is where you 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: Each template should have the following structure:
@ -320,26 +321,35 @@ the capture)."
(defun org-roam-capture--finalize () (defun org-roam-capture--finalize ()
"Finalize the `org-roam-capture' process." "Finalize the `org-roam-capture' process."
(unless org-note-abort (let* ((finalize (org-roam-capture--get :finalize))
(pcase (org-roam-capture--get :finalize) ;; In case any regions were shielded before, unshield them
('find-file (region (when-let ((region (org-roam-capture--get :region)))
(when-let ((file-path (org-roam-capture--get :file-path))) (org-roam-unshield-region (car region) (cdr region))))
(org-roam--find-file file-path) (beg (car region))
(run-hooks 'org-roam-capture-after-find-file-hook))) (end (cdr region)))
('insert-link (unless org-note-abort
(when-let* ((mkr (org-roam-capture--get :insert-at)) (pcase finalize
(buf (marker-buffer mkr))) ('find-file
(with-current-buffer buf (when-let ((file-path (org-roam-capture--get :file-path)))
(when-let ((region (org-roam-capture--get :region))) ;; Remove previously selected text. (org-roam--find-file file-path)
(delete-region (car region) (cdr region))) (run-hooks 'org-roam-capture-after-find-file-hook)))
(let ((path (org-roam-capture--get :file-path)) ('insert-link
(desc (org-roam-capture--get :link-description))) (when-let* ((mkr (org-roam-capture--get :insert-at))
(if (eq (point) (marker-position mkr)) (buf (marker-buffer mkr)))
(insert (org-roam--format-link path desc)) (with-current-buffer buf
(org-with-point-at mkr (when region
(insert (org-roam--format-link path desc)))))))))) (delete-region (car region) (cdr region)))
(org-roam-capture--save-file-maybe) (let ((path (org-roam-capture--get :file-path))
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize)) (desc (org-roam-capture--get :link-description)))
(if (eq (point) (marker-position mkr))
(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)))
(defun org-roam-capture--install-finalize () (defun org-roam-capture--install-finalize ()
"Install `org-roam-capture--finalize' if the capture is an Org-roam capture." "Install `org-roam-capture--finalize' if the capture is an Org-roam capture."

View File

@ -492,16 +492,22 @@ If FORCE, force a rebuild of the cache from scratch."
(let ((contents-hash (org-roam-db--file-hash file))) (let ((contents-hash (org-roam-db--file-hash file)))
(unless (string= (gethash file current-files) (unless (string= (gethash file current-files)
contents-hash) contents-hash)
(org-roam--with-temp-buffer file (condition-case nil
(org-roam-db--clear-file file) (org-roam--with-temp-buffer file
(org-roam-db-query (org-roam-db--clear-file file)
[:insert :into files (org-roam-db-query
:values $v1] [:insert :into files
(vector file contents-hash (list :atime atime :mtime mtime))) :values $v1]
(setq file-count (1+ file-count)) (vector file contents-hash (list :atime atime :mtime mtime)))
(when-let ((headlines (org-roam--extract-headlines file))) (setq file-count (1+ file-count))
(when (org-roam-db--insert-headlines headlines) (when-let ((headlines (org-roam--extract-headlines file)))
(setq headline-count (1+ headline-count))))))))) (when (org-roam-db--insert-headlines headlines)
(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 ;; Second step: Rebuild the rest
(dolist (file org-roam-files) (dolist (file org-roam-files)
(let ((contents-hash (org-roam-db--file-hash file))) (let ((contents-hash (org-roam-db--file-hash file)))

67
org-roam-faces.el Normal file
View 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
View File

View File

@ -77,6 +77,28 @@ to look.
(s-replace "\\" "\\\\") (s-replace "\\" "\\\\")
(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) (provide 'org-roam-macs)
;;; org-roam-macs.el ends here ;;; org-roam-macs.el ends here

View File

@ -54,6 +54,8 @@
;; @TODO: implement something akin to `org-modules' that allows ;; @TODO: implement something akin to `org-modules' that allows
;; selectively loading different sets of features. ;; selectively loading different sets of features.
;; ~NV [2020-05-22 Fri] ;; ~NV [2020-05-22 Fri]
(require 'org-roam-faces)
(require 'org-roam-buffer) (require 'org-roam-buffer)
(require 'org-roam-completion) (require 'org-roam-completion)
(require 'org-roam-capture) (require 'org-roam-capture)
@ -78,11 +80,6 @@
:link '(url-link :tag "Github" "https://github.com/org-roam/org-roam") :link '(url-link :tag "Github" "https://github.com/org-roam/org-roam")
:link '(url-link :tag "Online Manual" "https://www.orgroam.com/manual/")) :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/") (defcustom org-roam-directory (expand-file-name "~/org-roam/")
"Default path to Org-roam files. "Default path to Org-roam files.
All Org files, at any level of nesting, are considered part of the Org-roam." 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) file)
org-roam-directory)))) org-roam-directory))))
;;; The org-roam buffer ;;; org-roam-backlinks-mode
;;;; 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
(define-minor-mode org-roam-backlinks-mode (define-minor-mode org-roam-backlinks-mode
"Minor mode for the `org-roam-buffer'. "Minor mode for the `org-roam-buffer'.
\\{org-roam-backlinks-mode-map}" \\{org-roam-backlinks-mode-map}"
@ -999,39 +978,6 @@ buffer or a marker."
(backlink-dest (org-roam--retrieve-link-destination))) (backlink-dest (org-roam--retrieve-link-destination)))
(string= current backlink-dest))) (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 () (defun org-roam-open-at-point ()
"Open an Org-roam link or visit the text previewed 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. 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)] :order-by (asc from)]
target)) target))
(defun org-roam-store-link-file () (defun org-roam-store-link ()
"Store a link to an `org-roam' file." "Store a link to an Org-roam file or heading."
(when (org-before-first-heading-p) (when (and (bound-and-true-p org-roam-mode)
(when-let ((title (cdr (assoc "TITLE" (org-roam--extract-global-props '("TITLE")))))) (org-roam--org-roam-file-p))
(org-link-store-props (if (org-before-first-heading-p)
:type "file" (when-let ((titles (org-roam--extract-titles)))
:link (format "file:%s" (abbreviate-file-name buffer-file-name)) (org-link-store-props
:description title)))) :type "file"
:link (format "file:%s" (abbreviate-file-name buffer-file-name))
(defun org-roam--store-link (arg &optional interactive?) :description (car titles)))
"Store a link to the current location within Org-roam. (let ((id (org-id-get)))
See `org-roam-store-link' for details on ARG and INTERACTIVE?." (org-id-store-link)
(let ((org-id-link-to-org-use-id t) ;; If :ID: was created, update the cache
(id (org-id-get))) (unless id
(org-store-link arg interactive?) (org-roam-db--update-headlines))))))
;; 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?)))
(defun org-roam-id-find (id &optional markerp strict) (defun org-roam-id-find (id &optional markerp strict)
"Return the location of the entry with the id ID. "Return the location of the entry with the id ID.
@ -1149,15 +1082,73 @@ This function hooks into `org-open-at-point' via
(t (t
nil))))) 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 () (defun org-roam--find-file-hook-function ()
"Called by `find-file-hook' when mode symbol `org-roam-mode' is on." "Called by `find-file-hook' when mode symbol `org-roam-mode' is on."
(when (org-roam--org-roam-file-p) (when (org-roam--org-roam-file-p)
(setq org-roam-last-window (get-buffer-window)) (setq org-roam-last-window (get-buffer-window))
(add-hook 'post-command-hook #'org-roam-buffer--update-maybe nil t) (add-hook 'post-command-hook #'org-roam-buffer--update-maybe nil t)
(add-hook 'after-save-hook #'org-roam-db--update-file 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))) (org-roam-buffer--update-maybe :redisplay t)))
(defun org-roam--delete-file-advice (file &optional _trash) (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." Otherwise, behave as if called interactively."
:lighter " Org-roam" :lighter " Org-roam"
:keymap (let ((map (make-sparse-keymap))) :keymap (let ((map (make-sparse-keymap)))
(define-key map [remap org-store-link] 'org-roam-store-link)
map) map)
:group 'org-roam :group 'org-roam
:require '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) (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 'rename-file :after #'org-roam--rename-file-advice)
(advice-add 'delete-file :before #'org-roam--delete-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)) (org-roam-db-build-cache))
(t (t
(setq org-execute-file-search-functions (delete 'org-roam--execute-file-row-col org-execute-file-search-functions)) (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) (remove-hook 'org-open-at-point-functions #'org-roam-open-id-at-point)
(advice-remove 'rename-file #'org-roam--rename-file-advice) (advice-remove 'rename-file #'org-roam--rename-file-advice)
(advice-remove 'delete-file #'org-roam--delete-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) (org-roam-db--close-all)
;; Disable local hooks for all org-roam buffers ;; Disable local hooks for all org-roam buffers
(dolist (buf (org-roam--get-roam-buffers)) (dolist (buf (org-roam--get-roam-buffers))
(with-current-buffer buf (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 'post-command-hook #'org-roam-buffer--update-maybe t)
(remove-hook 'after-save-hook #'org-roam-db--update-file t)))))) (remove-hook 'after-save-hook #'org-roam-db--update-file t))))))
@ -1420,42 +1415,50 @@ If DESCRIPTION is provided, use this as the link label. See
`org-roam--get-title-path-completions' for details." `org-roam--get-title-path-completions' for details."
(interactive "P") (interactive "P")
(unless org-roam-mode (org-roam-mode)) (unless org-roam-mode (org-roam-mode))
(let* ((region (and (region-active-p) ;; Deactivate the mark on quit since `atomic-change-group' prevents it
;; following may lose active region, so save it (unwind-protect
(cons (region-beginning) (region-end)))) ;; Group functions together to avoid inconsistent state on quit
(region-text (when region (atomic-change-group
(buffer-substring-no-properties (car region) (cdr region)))) (let* (region-text
(completions (--> (or completions beg end
(org-roam--get-title-path-completions)) (_ (when (region-active-p)
(if filter-fn (setq beg (set-marker (make-marker) (region-beginning)))
(funcall filter-fn it) (setq end (set-marker (make-marker) (region-end)))
it))) (setq region-text (buffer-substring-no-properties beg end))))
(title-with-tags (org-roam-completion--completing-read "File: " completions (completions (--> (or completions
:initial-input region-text)) (org-roam--get-title-path-completions))
(res (cdr (assoc title-with-tags completions))) (if filter-fn
(title (or (plist-get res :title) (funcall filter-fn it)
title-with-tags)) it)))
(target-file-path (plist-get res :path)) (title-with-tags (org-roam-completion--completing-read "File: " completions
(description (or description region-text title)) :initial-input region-text))
(link-description (org-roam--format-link-title (if lowercase (res (cdr (assoc title-with-tags completions)))
(downcase description) (title (or (plist-get res :title)
description)))) title-with-tags))
(if (and target-file-path (target-file-path (plist-get res :path))
(file-exists-p target-file-path)) (description (or description region-text title))
(progn (link-description (org-roam--format-link-title (if lowercase
(when region ;; Remove previously selected text. (downcase description)
(delete-region (car region) (cdr region))) description))))
(insert (org-roam--format-link target-file-path link-description))) (cond ((and target-file-path
(let ((org-roam-capture--info `((title . ,title-with-tags) (file-exists-p target-file-path))
(slug . ,(funcall org-roam-title-to-slug-function title-with-tags)))) (when region-text
(org-roam-capture--context 'title)) (delete-region beg end)
(setq org-roam-capture-additional-template-props (list :region region (set-marker beg nil)
:insert-at (point-marker) (set-marker end nil))
:link-description link-description (insert (org-roam--format-link target-file-path link-description)))
:finalize 'insert-link)) (t
(org-roam--with-template-error 'org-roam-capture-templates (let ((org-roam-capture--info `((title . ,title-with-tags)
(org-roam-capture--capture)))) (slug . ,(funcall org-roam-title-to-slug-function title-with-tags))))
res)) (org-roam-capture--context 'title))
(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)))))
res))
(deactivate-mark)))
;;;###autoload ;;;###autoload
(defun org-roam-insert-immediate (arg &rest args) (defun org-roam-insert-immediate (arg &rest args)