mirror of
https://github.com/org-roam/org-roam
synced 2025-09-16 15:56:48 -05:00
(feature): add jump to point from org-roam buffer (#99)
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
### New Features
|
### New Features
|
||||||
* [#87][gh-87], [#90][gh-90] Support encrypted Org files
|
* [#87][gh-87], [#90][gh-90] Support encrypted Org files
|
||||||
* [#110][gh-110] Add prefix to `org-roam-insert`, for inserting titles down-cased
|
* [#110][gh-110] Add prefix to `org-roam-insert`, for inserting titles down-cased
|
||||||
|
* [#99](https://github.com/jethrokuan/org-roam/pull/99) Add keybinding so that `<return>` or `mouse-1` in the backlinks buffer visits the source file of the backlink at point
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
* [#86][gh-86] Fix `org-roam--parse-content` incorrect `:to` computation for nested files
|
* [#86][gh-86] Fix `org-roam--parse-content` incorrect `:to` computation for nested files
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
### Contributors
|
### Contributors
|
||||||
* [@chip2n](https://github.com/chip2n/)
|
* [@chip2n](https://github.com/chip2n/)
|
||||||
* [@l3kn](https://github.com/l3kn/)
|
* [@l3kn](https://github.com/l3kn/)
|
||||||
|
* [@jdormit](https://github.com/jdormit)
|
||||||
|
|
||||||
## 0.1.1 (2020-02-15)
|
## 0.1.1 (2020-02-15)
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ Like file-name-extension, but does not strip version number."
|
|||||||
(save-match-data
|
(save-match-data
|
||||||
(let ((file (file-name-nondirectory filename)))
|
(let ((file (file-name-nondirectory filename)))
|
||||||
(if (and (string-match "\\.[^.]*\\'" file)
|
(if (and (string-match "\\.[^.]*\\'" file)
|
||||||
(not (eq 0 (match-beginning 0))))
|
(not (eq 0 (match-beginning 0))))
|
||||||
(substring file (+ (match-beginning 0) 1))))))
|
(substring file (+ (match-beginning 0) 1))))))
|
||||||
|
|
||||||
(defun org-roam--org-file-p (path)
|
(defun org-roam--org-file-p (path)
|
||||||
@@ -86,10 +86,11 @@ Like file-name-extension, but does not strip version number."
|
|||||||
(org-roam--org-file-p path))
|
(org-roam--org-file-p path))
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
(let* ((element (org-element-at-point))
|
(let* ((element (org-element-at-point))
|
||||||
|
(begin (or (org-element-property :content-begin element)
|
||||||
|
(org-element-property :begin element)))
|
||||||
(content (or (org-element-property :raw-value element)
|
(content (or (org-element-property :raw-value element)
|
||||||
(buffer-substring
|
(buffer-substring
|
||||||
(or (org-element-property :content-begin element)
|
begin
|
||||||
(org-element-property :begin element))
|
|
||||||
(or (org-element-property :content-end element)
|
(or (org-element-property :content-end element)
|
||||||
(org-element-property :end element)))))
|
(org-element-property :end element)))))
|
||||||
(content (string-trim content))
|
(content (string-trim content))
|
||||||
@@ -97,13 +98,13 @@ Like file-name-extension, but does not strip version number."
|
|||||||
(file-truename (buffer-file-name (current-buffer))))))
|
(file-truename (buffer-file-name (current-buffer))))))
|
||||||
(list :from file-path
|
(list :from file-path
|
||||||
:to (file-truename (expand-file-name path (file-name-directory file-path)))
|
:to (file-truename (expand-file-name path (file-name-directory file-path)))
|
||||||
:content content)))))))
|
:properties (list :content content :point begin))))))))
|
||||||
|
|
||||||
(cl-defun org-roam--insert-item (item &key forward backward)
|
(cl-defun org-roam--insert-item (item &key forward backward)
|
||||||
"Insert ITEM into FORWARD and BACKWARD cache.
|
"Insert ITEM into FORWARD and BACKWARD cache.
|
||||||
|
|
||||||
ITEM is of the form: (:from from-path :to to-path :content preview-content)."
|
ITEM is of the form: (:from from-path :to to-path :properties (:content preview-content :point point))."
|
||||||
(pcase-let ((`(:from ,p-from :to ,p-to :content ,content) item))
|
(pcase-let ((`(:from ,p-from :to ,p-to :properties ,props) item))
|
||||||
;; Build forward-links
|
;; Build forward-links
|
||||||
(let ((links (gethash p-from forward)))
|
(let ((links (gethash p-from forward)))
|
||||||
(if links
|
(if links
|
||||||
@@ -116,14 +117,14 @@ ITEM is of the form: (:from from-path :to to-path :content preview-content)."
|
|||||||
(let ((contents-hash (gethash p-to backward)))
|
(let ((contents-hash (gethash p-to backward)))
|
||||||
(if contents-hash
|
(if contents-hash
|
||||||
(if-let ((contents-list (gethash p-from contents-hash)))
|
(if-let ((contents-list (gethash p-from contents-hash)))
|
||||||
(let ((updated (cons content contents-list)))
|
(let ((updated (cons props contents-list)))
|
||||||
(puthash p-from updated contents-hash)
|
(puthash p-from updated contents-hash)
|
||||||
(puthash p-to contents-hash backward))
|
(puthash p-to contents-hash backward))
|
||||||
(progn
|
(progn
|
||||||
(puthash p-from (list content) contents-hash)
|
(puthash p-from (list props) contents-hash)
|
||||||
(puthash p-to contents-hash backward)))
|
(puthash p-to contents-hash backward)))
|
||||||
(let ((contents-hash (make-hash-table :test #'equal)))
|
(let ((contents-hash (make-hash-table :test #'equal)))
|
||||||
(puthash p-from (list content) contents-hash)
|
(puthash p-from (list props) contents-hash)
|
||||||
(puthash p-to contents-hash backward))))))
|
(puthash p-to contents-hash backward))))))
|
||||||
|
|
||||||
(defun org-roam--extract-title ()
|
(defun org-roam--extract-title ()
|
||||||
|
36
org-roam.el
36
org-roam.el
@@ -397,6 +397,25 @@ This is equivalent to removing the node from the graph."
|
|||||||
(let ((time (org-read-date nil 'to-time nil "Date: ")))
|
(let ((time (org-read-date nil 'to-time nil "Date: ")))
|
||||||
(org-roam--new-file-named (format-time-string "%Y-%m-%d" time))))
|
(org-roam--new-file-named (format-time-string "%Y-%m-%d" time))))
|
||||||
|
|
||||||
|
(defun org-roam-jump-to-backlink ()
|
||||||
|
"Jumps to original file and location of the backlink content snippet at point"
|
||||||
|
(interactive)
|
||||||
|
(let ((file-from (get-text-property (point) 'file-from))
|
||||||
|
(p (get-text-property (point) 'file-from-point)))
|
||||||
|
(when (and file-from p)
|
||||||
|
(find-file file-from)
|
||||||
|
(goto-char p)
|
||||||
|
(org-show-context))))
|
||||||
|
|
||||||
|
(define-derived-mode org-roam-backlinks-mode org-mode "Backlinks"
|
||||||
|
"Major mode for the org-roam backlinks buffer
|
||||||
|
|
||||||
|
Bindings:
|
||||||
|
\\{org-roam-backlinks-mode-map}")
|
||||||
|
|
||||||
|
(define-key org-roam-backlinks-mode-map [mouse-1] 'org-roam-jump-to-backlink)
|
||||||
|
(define-key org-roam-backlinks-mode-map (kbd "RET") 'org-roam-jump-to-backlink)
|
||||||
|
|
||||||
;;; Org-roam buffer updates
|
;;; Org-roam buffer updates
|
||||||
|
|
||||||
(defun org-roam--find-file (file)
|
(defun org-roam--find-file (file)
|
||||||
@@ -419,8 +438,8 @@ This is equivalent to removing the node from the graph."
|
|||||||
(cons '(file . org-roam--find-file) org-link-frame-setup))
|
(cons '(file . org-roam--find-file) org-link-frame-setup))
|
||||||
(let ((inhibit-read-only t))
|
(let ((inhibit-read-only t))
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(when (not (eq major-mode 'org-mode))
|
(when (not (eq major-mode 'org-roam-backlinks-mode))
|
||||||
(org-mode))
|
(org-roam-backlinks-mode))
|
||||||
(make-local-variable 'org-return-follows-link)
|
(make-local-variable 'org-return-follows-link)
|
||||||
(setq org-return-follows-link t)
|
(setq org-return-follows-link t)
|
||||||
(insert
|
(insert
|
||||||
@@ -433,10 +452,15 @@ This is equivalent to removing the node from the graph."
|
|||||||
(insert (format "** [[file:%s][%s]]\n"
|
(insert (format "** [[file:%s][%s]]\n"
|
||||||
file-from
|
file-from
|
||||||
(org-roam--get-title-or-slug file-from)))
|
(org-roam--get-title-or-slug file-from)))
|
||||||
(dolist (content contents)
|
(dolist (properties contents)
|
||||||
(insert (concat (propertize (s-trim (s-replace "\n" " " content))
|
(let ((content (propertize
|
||||||
'font-lock-face 'org-block)
|
(s-trim (s-replace "\n" " "
|
||||||
"\n\n"))))
|
(plist-get properties :content)))
|
||||||
|
'font-lock-face 'org-block
|
||||||
|
'help-echo "mouse-1: visit backlinked note"
|
||||||
|
'file-from file-from
|
||||||
|
'file-from-point (plist-get properties :point))))
|
||||||
|
(insert (format "%s \n\n" content)))))
|
||||||
backlinks))
|
backlinks))
|
||||||
(insert "\n\n* No backlinks!")))
|
(insert "\n\n* No backlinks!")))
|
||||||
(read-only-mode 1)))
|
(read-only-mode 1)))
|
||||||
|
Reference in New Issue
Block a user